Repository URL to install this package:
|
Version:
1.2.13 ▾
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.juxt = juxt;
exports.toPrice = toPrice;
exports.spread = exports.arrayPropGetter = exports.upgradeSpecification = exports.withoutPath = exports.withoutProp = exports.indexByProp = exports.forOwn = exports.getTag = exports.keys = exports.cast = void 0;
const filter = require('lodash/filter');
const _require = require('ramda'),
indexBy = _require.indexBy,
prop = _require.prop,
clone = _require.clone;
const _require2 = require('chain-able-boost'),
argumentsToArray = _require2.argumentsToArray,
cast = _require2.cast,
keys = _require2.keys,
getTag = _require2.getTag,
forOwn = _require2.forOwn,
filterWhere = _require2.filterWhere,
equals = _require2.equals,
isPrimitive = _require2.isPrimitive,
isObj = _require2.isObj,
isArray = _require2.isArray,
curry = _require2.curry;
exports.forOwn = forOwn;
exports.getTag = getTag;
exports.keys = keys;
exports.cast = cast;
function juxt(fns) {
return function () {
const args = argumentsToArray.apply(null, arguments);
forOwn(fns, function (fn) {
fn.apply(this, args);
});
};
}
function toPrice(price) {
try {
let newPrice = Number(price);
return newPrice.toFixed(2);
} catch (error) {
return 'N/A';
}
} // const indexByProp = pipeTwo(R.prop, R.indexBy)
const indexByProp = x => indexBy(prop(x));
/**
* @NOTE this is `filterObj`
* @desc dereferences obj, deletes property
* @param {string} path
* @param {Object} obj
* @return {Object}
*/
exports.indexByProp = indexByProp;
const withoutProp = (path, obj) => {
const predicate = (value, key) => key !== path;
return filterWhere(obj, predicate);
};
exports.withoutProp = withoutProp;
const withoutPath = (path, obj) => {
const predicate = (value, key) => key !== path;
return filter(obj, predicate);
};
exports.withoutPath = withoutPath;
const upgradeSpecification = specification => {
// turn primitive values into eq functions
forOwn(specification, (value, key) => {
if (isPrimitive(value)) {
specification[key] = equals(value);
}
});
};
exports.upgradeSpecification = upgradeSpecification;
const spread = x => {
if (isArray(x)) return x.slice();else if (isObj(x)) return Object.assign({}, x);else return clone(x);
};
exports.spread = spread;
const arrayPropGetter = curry(3, function (thisArg, name, prop) {
Object.defineProperty(thisArg, name, {
get() {
return this[prop][this[prop].length - 1];
}
});
}); // --- export default exports
exports.arrayPropGetter = arrayPropGetter;