shapey
Version:
A simple syntax for remapping objects, inspired by several of Ramda's spec based functions
1,620 lines (1,292 loc) • 99.5 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.shapey = {}));
}(this, (function (exports) { 'use strict';
function getDefaultExportFromCjs (x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
}
function createCommonjsModule(fn, basedir, module) {
return module = {
path: basedir,
exports: {},
require: function (path, base) {
return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
}
}, fn(module, module.exports), module.exports;
}
function commonjsRequire () {
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
}
var curry_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Takes a Function whose params are meant to be supplied all at once and changes it so they can be supplied one at a time.
* As each argument is supplied a new Function is returned that is ready to receive the next argument.
* This continues until all arguments for your origianl function have been supplied and then the actual result is returned.
*
* Note: you cannot set default values for curried function params (again, you _cannot_ set default values for curried function params)
*
* @function
* @param {Function} fn A Function whose signature needs to changed from requiring all at once to providing them one (or more) at a time.
* @returns {Function} A new Function that will wait until all arguments have been supplied before returning a result (otherwise it will continue to return a new Function that is ready to receive the next argument)
*/
function curry(fn) {
var fnlen = fn.length;
switch (fnlen) {
case 2:
return function standardCurry(a, b) {
if (arguments.length === 2) {
return fn(a, b);
}
return function (_b) {
return fn(a, _b);
};
};
case 3:
return function threeArgCurry(a, b, c) {
switch (arguments.length) {
case 3:
return fn(a, b, c);
case 2:
return function (_c) {
return fn(a, b, _c);
};
default:
return curry(function (_b, _c) {
return fn(a, _b, _c);
});
}
};
case 4:
return function fourArgCurry(a, b, c, d) {
switch (arguments.length) {
case 4:
return fn(a, b, c, d);
case 3:
return function (_d) {
return fn(a, b, c, _d);
};
case 2:
return curry(function (_c, _d) {
return fn(a, b, _c, _d);
});
default:
return curry(function (_b, _c, _d) {
return fn(a, _b, _c, _d);
});
}
};
default:
return function manyArgCurry() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var arglen = args.length;
if (arglen === fnlen) {
return fn.apply(void 0, args);
}
return function inner() {
for (var _len2 = arguments.length, innerArgs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
innerArgs[_key2] = arguments[_key2];
}
var innerlen = innerArgs.length;
var limit = fnlen;
var allArgs = [];
var argCount = 0;
while (argCount < arglen) {
allArgs.push(args[argCount]);
argCount++;
limit--;
}
var innerArgCount = 0;
while (innerArgCount < innerlen) {
allArgs.push(innerArgs[innerArgCount]);
innerArgCount++;
limit--;
}
return limit > 0 ? manyArgCurry.apply(void 0, allArgs) : fn.apply(void 0, allArgs);
};
};
}
}
var _default = curry;
exports.default = _default;
module.exports = exports.default;
});
var curry = /*@__PURE__*/getDefaultExportFromCjs(curry_1);
var has_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Checks if a given Object contains a specified prop name
*
* @function
* @param {String} key A prop name to look for in the object
* @param {object} obj An Object to inspect for a given prop
* @returns {Boolean} Whether the object contains the specified prop
*/
function has(key, obj) {
return Object.prototype.hasOwnProperty.call(obj, key);
}
var _default = has;
exports.default = _default;
module.exports = exports.default;
});
var has = /*@__PURE__*/getDefaultExportFromCjs(has_1);
var forIn_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _has = _interopRequireDefault(has_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* A light wrapper around native `for .. in`, but will only iterate over an Object's own properties.
*
* @function
* @param {Function} fn A function to execute iteratively, which will receive the `key`, `value`, and `object` (respectively)
* @param {object} obj An object whose keys will be iterated over
*/
function forIn(fn, obj) {
// eslint-disable-next-line no-restricted-syntax
for (var key in obj) {
if ((0, _has.default)(key, obj)) {
fn(key, obj[key], obj);
}
}
}
var _default = forIn;
exports.default = _default;
module.exports = exports.default;
});
var merge_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _forIn = _interopRequireDefault(forIn_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Merges the values from 2 or more Objects or Arrays together into a new Object/Array.
* Null and Undefined values are handled gracefully, and if the second value is a primitive it will be returned as-is, instead of trying to merge it onto the first.
*
* @function
* @param {object|Array<*>} val The first value to merge onto (will not get mutated though)
* @param {object|Array<*>} val2 A value to merge onto the first
* @returns {object|Array<*>} A new value that contains the combined values from all the values passed in
*/
function merge() {
for (var _len = arguments.length, vals = new Array(_len), _key = 0; _key < _len; _key++) {
vals[_key] = arguments[_key];
}
var numOfVals = vals.length;
if (vals[0] === undefined || vals[1] === undefined) {
return vals[1] !== undefined ? vals[1] : vals[0];
}
if (numOfVals === 2 && (typeof vals[1] !== "object" || !vals[1] || vals[1].constructor.name !== "Object")) {
return vals[1];
}
var newObj = {};
(0, _forIn.default)(function (key, val) {
newObj[key] = val;
}, vals[0]);
for (var i = 1; i < numOfVals; i++) {
(0, _forIn.default)(function (key, val) {
newObj[key] = merge(newObj[key], val);
}, vals[i]);
}
return newObj;
}
var _default = merge;
exports.default = _default;
module.exports = exports.default;
});
var merge = /*@__PURE__*/getDefaultExportFromCjs(merge_1);
var append_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _merge = _interopRequireDefault(merge_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Blends two values together based on their type.
* If both are objects this would result in a new object with the second value's props merged onto the first's.
* If the first value is an array, this would result in a new array with the second value concatenated onto the first value.
* If both values are strings or numbers, a new string will be returned with the second value added onto the first.
*
* @function
* @param {String|Number|Object<string, any>|Array<*>} firstVal A value that will have another appended onto
* @param {String|Number|Object<string, any>|Array<*>} secondVal A value to append to the first value
* @returns {Array<*>|object|String} A new Array, Object, or String that has the characters/values from the second provided value merged _after_ those from the first provided value
*/
function append(firstVal, secondVal) {
if ([firstVal, secondVal].every(function (val) {
return typeof val === "string" || typeof val === "number";
})) {
return "" + firstVal + secondVal;
}
if (Array.isArray(firstVal) && Array.isArray(secondVal)) {
return [].concat(firstVal, secondVal);
}
return (0, _merge.default)(firstVal, secondVal);
}
var _default = append;
exports.default = _default;
module.exports = exports.default;
});
var cond_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Several pieces of conditional logic to apply against a value and the _first_ one which matches will have a corresponding transformation applied to it.
*
* Supply an Array of pairs:
* - the first value is the conditional logic (`Function`) to match against the value
* - the second value is the transformation (`Function`) to apply to the value if the condition was matched
*
* __Note__: if your tranformation is _not_ a function then it will returned as-is in response to a succesfully met condition
*
* @function
* @param {Array<Array<Function>>} conditionalTransforms An array of arrays (which have two values: the condition function and the transformation function)
* @param {*} val A value of any type that will be transformed according to the appropriate condition.
* @returns {*} The provided value transformed by the appropriate matching conditional transformation
*/
function cond(conditionalTransforms, val) {
var result;
conditionalTransforms.some(function (_ref) {
var ifCondition = _ref[0],
_ref$ = _ref[1],
transform = _ref$ === void 0 ? val : _ref$;
if (ifCondition(val)) {
result = typeof transform === "function" ? transform(val) : transform;
return true;
}
return false;
});
return result;
}
var _default = cond;
exports.default = _default;
module.exports = exports.default;
});
var _includes_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports._includes = _includes;
function _includes(val, arr) {
var idx = arr.length;
while (idx--) {
if (arr[idx] === val) {
return true;
}
}
return false;
}
});
var contains_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Checks if a given value is present in a String OR Array
*
* @function
* @param {String|Number} val A value which may be present in the String/Array
* @param {Array<*>|String} arr An Array or String which may contain the provided value
* @returns {Boolean} Whether or not the String|Array contains the provided value
*/
function contains(val, arr) {
return Array.isArray(arr) ? (0, _includes_1._includes)(val, arr) : arr.indexOf(val) !== -1;
}
var _default = contains;
exports.default = _default;
module.exports = exports.default;
});
var difference_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Compares two lists of Strings/Numbers and returns the values that are different between the two lists
*
* @function
* @param {Array<String>|Array<Number>} arr1 An Array of Strings
* @param {Array<String>|Array<Number>} arr2 An Array of Strings
* @returns {Array<String>|Array<Number>} An array of values that are different between the two lists
*/
function difference(arr1, arr2) {
var diff = [];
var len1 = arr1.length;
var len2 = arr2.length;
if (len1 === 0 && len2 === 0) {
return diff;
} else if (len1 === 0) {
return arr2;
} else if (len2 === 0) {
return arr1;
}
for (var i = 0; i < len1; i++) {
var val = arr1[i];
if (!(0, _includes_1._includes)(val, arr2)) {
diff.push(val);
}
}
for (var j = 0; j < len2; j++) {
var _val = arr2[j];
if (!(0, _includes_1._includes)(_val, arr1)) {
diff.push(_val);
}
}
return diff;
}
var _default = difference;
exports.default = _default;
module.exports = exports.default;
});
var difference = /*@__PURE__*/getDefaultExportFromCjs(difference_1);
var each_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* A faster forEach that provides the same API as native.
*
* @function
* @param {Function} fn A Function to execute for each iteration. It will receive the value, index and full array (respectively) as args
* @param {Array<*>} arr An Array to iterate over (any value will be passed into the iterate Function)
*/
function each(fn, arr) {
for (var i = 0, count = arr.length; i < count; i++) {
fn(arr[i], i, arr);
}
}
var _default = each;
exports.default = _default;
module.exports = exports.default;
});
var find_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Find a single value from an array of values, based on criteria defined in a predicate function.
*
* @function
* @param {Function} pred A predicate function to apply to the array of values (It should take a val as input and return a Boolean as output).
* @param {Array<*>} arr An array of values from which to find one particular matching value
* @returns {*} Either a value from the array that matched the predicate function or undefined (if no match)
*/
function find(pred, arr) {
var len = arr.length;
for (var i = 0; i < len; i++) {
if (pred(arr[i])) return arr[i];
}
}
var _default = find;
exports.default = _default;
module.exports = exports.default;
});
var findIndex_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Find the index of a single value from an array of values, based on criteria defined in a predicate function.
*
* @function
* @param {Function} pred A predicate function to apply to the array of values (It should take a val as input and return a Boolean as output).
* @param {Array<*>} arr An array of values from which to find the index of one particular matching value
* @returns {Number} Either the index of the value from the array that matched the predicate function or negative one (-1, if no match).
*/
function findIndex(pred, arr) {
var i = -1;
var len = arr.length;
while (++i < len) {
if (pred(arr[i])) return i;
}
return -1;
}
var _default = findIndex;
exports.default = _default;
module.exports = exports.default;
});
var isNil_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Checks to see if a value is null OR undefined
*
* @function
* @param {*} val A value (of any type)
* @returns {Boolean} Whether or not the value is null or undefined
*/
function isNil(val) {
return val == null;
}
var _default = isNil;
exports.default = _default;
module.exports = exports.default;
});
var getConstructorName_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
function getConstructorName(val) {
try {
return val.constructor.name;
} catch (err) {
return "";
}
}
var _default = getConstructorName;
exports.default = _default;
module.exports = exports.default;
});
var isArrayish_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isNil = _interopRequireDefault(isNil_1);
var _getConstructorName = _interopRequireDefault(getConstructorName_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isArrayLike(name) {
switch (name) {
case "Set":
case "WeakSet":
case "Array":
case "Float64Array":
case "Float32Array":
case "Int32Array":
case "Uint16Array":
case "Int16Array":
case "Uint8ClampedArray":
case "Uint8Array":
case "Int8Array":
return true;
default:
return false;
}
}
/**
* Checks if a given value is "array-like".
*
* This includes:
* - Array
* - Set
* - WeakSet
* - Float64Array
* - Float32Array
* - Int32Array
* - Uint16Array
* - Int16Array
* - Uint8ClampedArray
* - Uint8Array
* - Int8Array
*
* @function
* @param {*} val A value to check as being an array
* @returns {Boolean} Whether the value is an array-like type
*/
function isArrayish(val) {
return Array.isArray(val) || !(0, _isNil.default)(val) && isArrayLike((0, _getConstructorName.default)(val));
}
var _default = isArrayish;
exports.default = _default;
module.exports = exports.default;
});
var isUndefined_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Checks to see if a value is undefined
*
* @function
* @param {*} val A value (of any type)
* @returns {Boolean} Whether or not the value is undefined
*/
function isUndefined(val) {
return val === undefined;
}
var _default = isUndefined;
exports.default = _default;
module.exports = exports.default;
});
var isObject_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isNil = _interopRequireDefault(isNil_1);
var _isUndefined = _interopRequireDefault(isUndefined_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function isAnythingButAnObject(name) {
switch (name) {
case "Function":
case "RegExp":
case "Date":
case "WeakMap":
case "Map":
case "WeakSet":
case "Set":
case "Float64Array":
case "Float32Array":
case "Int32Array":
case "Uint16Array":
case "Int16Array":
case "Uint8ClampedArray":
case "Uint8Array":
case "Int8Array":
case "Array":
case "Symbol":
case "Number":
case "String":
case "Boolean":
case "UriError":
case "TypeError":
case "SyntaxError":
case "ReferenceError":
case "RangeError":
case "InternalError":
case "EvalError":
case "Error":
return true;
default:
return false;
}
}
/**
* A high-speed, mostly adequate check of a value which may be an Object.
* This excludes values that are _technically_ an Object but in practice are not what you _really_ mean when you speak of Objects.
*
* @function
* @param {*} val A value (of any type)
* @returns {Boolean} Whether or not the value is an Object
*/
function isObject(val) {
return !(0, _isNil.default)(val) && (0, _isUndefined.default)(val.length) && (!(0, _isUndefined.default)(val.constructor) && !isAnythingButAnObject(val.constructor.name) || (0, _isUndefined.default)(val.constructor) && (0, _isUndefined.default)(val.prototype));
}
var _default = isObject;
exports.default = _default;
module.exports = exports.default;
});
var isObject = /*@__PURE__*/getDefaultExportFromCjs(isObject_1);
var filterString_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Applies a filtering function you provide over every character in a given string.
*
* @function
* @param {Function} fn A filtering function that is invoked on every char in the provided String value
* @param {String} str A string value to filter over
* @returns {String} A new String value that is the result of the filtering operation over the original string
*/
function filterString(fn, str) {
var len = str.length;
var newStr = "";
for (var i = 0; i < len; i++) {
newStr += fn(str[i], i, str) ? str[i] : "";
}
return newStr;
}
var _default = filterString;
exports.default = _default;
module.exports = exports.default;
});
var filterObject_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _forIn = _interopRequireDefault(forIn_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies a filtering function you provide over every value in a given Object.
*
* @function
* @param {Function} fn A filtering function that is invoked on every value in the provided Object
* @param {object} obj An Object whose values will be filtered
* @returns {object} A new Object that is the result of the filtering operation over all the values in the original Object
*/
function filterObject(fn, obj) {
var newObj = {};
(0, _forIn.default)(function (key, val, ob) {
if (fn(val, key, ob)) {
newObj[key] = val;
}
}, obj);
return newObj;
}
var _default = filterObject;
exports.default = _default;
module.exports = exports.default;
});
var filter_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isArrayish = _interopRequireDefault(isArrayish_1);
var _isObject = _interopRequireDefault(isObject_1);
var _filterString = _interopRequireDefault(filterString_1);
var _filterObject = _interopRequireDefault(filterObject_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies a filtering function you provide over a value you provide, according to its type.
* String values will have the filtering function applied over every character in the String.
* Objects will have the filtering function applied to every value in the Object.
* Arrays (or Array-like values) will have the filtering function applied to every value in the Array.
* If the type of your value is none of the above, the value will be returned as-is.
*
* @function
* @param {Function} fn A filtering function that is invoked on the provided value
* @param {object|Array<*>|String} val An Object/Array/String whose values/chars will be filtered
* @returns {object|Array<*>|String} A new value that is the result of the filtering operation over all the chars or values in the original String/Object/Array
*/
function filter(fn, val) {
if (Array.isArray(val)) return val.filter(fn);
if ((0, _isObject.default)(val)) return (0, _filterObject.default)(fn, val);
if (typeof val === "string") return (0, _filterString.default)(fn, val);
if ((0, _isArrayish.default)(val)) return val.filter(fn);
return val;
}
var _default = filter;
exports.default = _default;
module.exports = exports.default;
});
var filter = /*@__PURE__*/getDefaultExportFromCjs(filter_1);
var fuzzy_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Performs a fuzzy search on a list of strings or objects.
* If a list of objects, provided the prop extraction function so the search can find the correct field(s)
* This is heavily inspired by (most of) the algorithm used by [Matt York's](https://github.com/myork/fuzzy) fuzzy search function,
* however several features were not carried over and his implementation of that alrgorithm has been significantly changed to achieve a 25% speed improvement.
* Please see his original work - called [fuzzy](https://www.npmjs.com/package/fuzzy) MIT - if you need some of his additional options.
*
* @function
* @param {Function} [propFn] A function which will extract all the fields which you wish to fuzzy search on. Omit if the list is a list of strings
* @param {string} needle The search value itself
* @param {boolean} [caseSensitive=false] Whether or not to perform a case-sensitive search
* @param {Array<String>|Array<object>} arr An array of string values or objects which have string values to be searched on
* @returns {Array<String>|Array<object>} The filtered list of search results
*/
function fuzzy(propFn, needle, caseSensitive, arr) {
if (arr == null || !Array.isArray(arr) || arr.length === 0) return [];
if (typeof needle !== "string" || !needle.trim().length) return arr;
var scores = [];
var len = arr.length;
var needleLen = needle.length;
var idx = len;
var noodle = caseSensitive ? needle : needle.toLowerCase();
var extractFn = typeof propFn !== "function" && caseSensitive ? function (v) {
return v;
} : typeof propFn !== "function" ? function (v) {
return v.toLowerCase();
} : caseSensitive ? propFn : function (v) {
return propFn(v).toLowerCase();
};
while (--idx) {
var score = 0;
var val = extractFn(arr[idx]);
var valLen = val.length;
if (noodle === val) {
scores.push([Infinity, idx]);
} else if (valLen !== 0) {
var valIdx = 0;
var matchedInNeedleIdx = 0;
var numOfCharsMatchedAtOnce = 0;
while (valIdx < valLen) {
if (noodle[matchedInNeedleIdx] === val[valIdx]) {
matchedInNeedleIdx++;
numOfCharsMatchedAtOnce++;
} else {
numOfCharsMatchedAtOnce = 0;
}
score += numOfCharsMatchedAtOnce;
valIdx++;
}
if (matchedInNeedleIdx === needleLen) {
scores.push([score, idx]);
}
}
}
return scores.sort(function (a, b) {
return b[0] - a[0] || a[1] - b[1];
}).map(function (_ref) {
_ref[0];
var index = _ref[1];
return arr[index];
});
}
var _default = fuzzy;
exports.default = _default;
module.exports = exports.default;
});
var hasNestedProp_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _has = _interopRequireDefault(has_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Checks if a given Object contains a (potentially) nested property of a specified path
*
* @function
* @param {Array<String>|String} prop A prop name, a dot-separated prop path, or an array of prop path "pieces" to look for in the object
* @param {object} obj An Object to inspect for a given prop at the specified path
* @returns {Boolean} Whether the object contains the specified prop path
*/
function hasNestedProp(prop, obj) {
var paths = typeof prop === "string" ? prop.split(".") : prop;
var len = paths.length;
if (len === 0) return false;
var idx = 0;
var val = obj[paths[idx]];
var hasProp = (0, _has.default)(paths[idx], obj);
while (++idx < len && hasProp === true) {
hasProp = (0, _has.default)(paths[idx], val);
if (hasProp) {
val = val[paths[idx]];
}
}
return hasProp;
}
var _default = hasNestedProp;
exports.default = _default;
module.exports = exports.default;
});
var intersection_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Compares two lists of Strings/Numbers and returns the values that are in common (intersect) between the two lists
*
* @function
* @param {Array<String>|Array<Number>} arr1 An Array of Strings/Numbers
* @param {Array<String>|Array<Number>} arr2 An Array of Strings/Numbers
* @returns {Array<String>|Array<Number>} The values in common between the two lists
*/
function intersection(arr1, arr2) {
var diff = [];
var len1 = arr1.length;
var len2 = arr2.length;
if (len1 === 0 || len2 === 0) return diff;
for (var i = 0; i < len1; i++) {
var val = arr1[i];
if ((0, _includes_1._includes)(val, arr2)) {
diff.push(val);
}
}
for (var j = 0; j < len2; j++) {
var _val = arr2[j];
if ((0, _includes_1._includes)(_val, arr1) && !(0, _includes_1._includes)(_val, diff)) {
diff.push(_val);
}
}
return diff;
}
var _default = intersection;
exports.default = _default;
module.exports = exports.default;
});
var isStrictEqual_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Inspects two values to see if they are strictly equal, meaning no type coercion or deepyly nested equality checks are performed.
* A very simple triple equals is all that is used.
*
* @function
* @param {*} val1 A value (of any type)
* @param {*} val2 A value (of any type)
* @returns {Boolean} Whether or not the two values are strictly equal
*/
function isStrictEqual(firstVal, secondVal) {
return firstVal === secondVal;
}
var _default = isStrictEqual;
exports.default = _default;
module.exports = exports.default;
});
var toTitleCase_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Transforms a string value into one which is title-cased. The first letter of any word is capitalized.
*
* @function
* @param {String} str A string which may contain uppercase characters
* @returns {String} A new string that is an lowercase representation of the original string
*/
function toTitleCase(str) {
return str.split(/\s/).map(function (s) {
return "" + s.charAt(0).toUpperCase() + s.slice(1);
}).join(" ");
}
var _default = toTitleCase;
exports.default = _default;
module.exports = exports.default;
});
var getType_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isNil = _interopRequireDefault(isNil_1);
var _toTitleCase = _interopRequireDefault(toTitleCase_1);
var _getConstructorName = _interopRequireDefault(getConstructorName_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Gets the type for any value. If available will inspect the constructor name, otherwise will use the typeof
*
* @function
* @param {*} val A value of any kind
* @returns {String} The stringified representation of the value's type
*/
function getType(val) {
if ((0, _isNil.default)(val)) {
return "" + val;
}
return (0, _getConstructorName.default)(val) || (0, _toTitleCase.default)(typeof val);
}
var _default = getType;
exports.default = _default;
module.exports = exports.default;
});
var isSameType_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _getType = _interopRequireDefault(getType_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Inspects two values to see if they are the same type.
* The typeof and (if necessary) constructor names are inspected during this check.
*
* @function
* @param {*} val1 A value (of any type)
* @param {*} val2 A value (of any type)
* @returns {Boolean} Whether or not the two values are of the same type
*/
function isSameType(val1, val2) {
return (0, _getType.default)(val1) === (0, _getType.default)(val2);
}
var _default = isSameType;
exports.default = _default;
module.exports = exports.default;
});
var isEqual_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isObject = _interopRequireDefault(isObject_1);
var _isArrayish = _interopRequireDefault(isArrayish_1);
var _isStrictEqual = _interopRequireDefault(isStrictEqual_1);
var _isSameType = _interopRequireDefault(isSameType_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Checks if two provided values are deeply equal.
* If Objects or Arrays (or Array-like values) are provided, they are inspected recursively.
* Primitive values are checked to see if they are stricly equal (ie triple equals; no type coercion).
*
* @function
* @param {*} firstVal A value which may be null, undefined, a JavaScript primitive value, an array of values, an array-like value, or an object
* @param {*} secondVal A value which may be null, undefined, a JavaScript
* @returns {Boolean} Whether or not the two values are deeply equal
*/
function isEqual(firstVal, secondVal) {
if ((0, _isStrictEqual.default)(firstVal, secondVal)) return true;
if (!(0, _isSameType.default)(firstVal, secondVal)) return false;
if (Array.isArray(firstVal) && Array.isArray(secondVal)) {
var valLen = firstVal.length;
if (valLen !== secondVal.length) return false;
for (var i = 0; i < valLen; i++) {
if (!isEqual(firstVal[i], secondVal[i])) return false;
}
return true;
}
if ((0, _isObject.default)(firstVal)) {
var firstKeys = Object.keys(firstVal);
var secondKeys = Object.keys(secondVal);
return firstKeys.length === secondKeys.length && firstKeys.every(function (key) {
return isEqual(firstVal[key], secondVal[key]);
});
}
if ((0, _isArrayish.default)(firstVal)) {
return firstVal.every(function (v, i) {
return isEqual(v, secondVal[i]);
});
}
return false;
}
var _default = isEqual;
exports.default = _default;
module.exports = exports.default;
});
var mapString_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Applies a mapping function you provide over every character in a given string.
*
* @function
* @param {Function} fn A mapping function that is invoked on every char in the provided String value
* @param {String} str A string value to map over
* @returns {String} A new String value that is the result of the mapping operation over the original string
*/
function mapString(fn, str) {
var len = str.length;
var newStr = "";
for (var i = 0; i < len; i++) {
newStr += fn(str[i], i, str);
}
return newStr;
}
var _default = mapString;
exports.default = _default;
module.exports = exports.default;
});
var mapObject_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _forIn = _interopRequireDefault(forIn_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies a mapping function you provide over every value in a given Object.
*
* @function
* @param {Function} fn A mapping function that is invoked on every value in the provided Object
* @param {object} obj An Object whose values will be mapped over
* @returns {object} A new Object that is the result of the mapping operation over all the values in the original Object
*/
function mapObject(fn, obj) {
var newObj = {};
(0, _forIn.default)(function (key, val, ob) {
newObj[key] = fn(val, key, ob);
}, obj);
return newObj;
}
var _default = mapObject;
exports.default = _default;
module.exports = exports.default;
});
var mapObject = /*@__PURE__*/getDefaultExportFromCjs(mapObject_1);
var map_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isArrayish = _interopRequireDefault(isArrayish_1);
var _isObject = _interopRequireDefault(isObject_1);
var _mapString = _interopRequireDefault(mapString_1);
var _mapObject = _interopRequireDefault(mapObject_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies a mapping function you provide over a value you provide, according to its type.
* String values will have the mapping function applied over every character in the String.
* Objects will have the mapping function applied to every value in the Object.
* Arrays (or Array-like values) will have the mapping function applied to every value in the Array.
* If the type of your value is none of the above, the value will be returned as-is.
* Also, this mapping operation does _not_ mutate the original value.
*
* @function
* @param {Function} fn A mapping function that is invoked on the provided value
* @param {object|Array<*>|String} val An Object/Array/String whose values/chars will be mapped over
* @returns {object|Array<*>|String} A new value that is the result of the mapping operation over all the chars or values in the original String/Object/Array
*/
function map(fn, val) {
if (Array.isArray(val)) return val.map(fn);
if ((0, _isObject.default)(val)) return (0, _mapObject.default)(fn, val);
if (typeof val === "string") return (0, _mapString.default)(fn, val);
if ((0, _isArrayish.default)(val)) return val.map(fn);
return val;
}
var _default = map;
exports.default = _default;
module.exports = exports.default;
});
var map = /*@__PURE__*/getDefaultExportFromCjs(map_1);
var mapObjectRecursive_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _forIn = _interopRequireDefault(forIn_1);
var _isObject = _interopRequireDefault(isObject_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies a mapping function you provide over every value in a given Object (recursively).
*
* @function
* @param {Function} fn A mapping function that is invoked on every value in the provided Object
* @param {object} obj An Object whose values will be mapped over (recursively)
* @returns {object} A new Object that is the result of the mapping operation over all the values in the original Object
*/
function mapObjectRecursive(fn, obj) {
var newObj = {};
(0, _forIn.default)(function (key, val, ob) {
/* Looks redundant, but is written this way for speed */
if (typeof val === "object" && val != null && (val.constructor && val.constructor.name === "Object" || (0, _isObject.default)(val))) {
newObj[key] = mapObjectRecursive(fn, val);
} else {
newObj[key] = fn(val, key, ob);
}
}, obj);
return newObj;
}
var _default = mapObjectRecursive;
exports.default = _default;
module.exports = exports.default;
});
var mapSpec_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _has = _interopRequireDefault(has_1);
var _forIn = _interopRequireDefault(forIn_1);
var _isObject = _interopRequireDefault(isObject_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Applies one or more mapping functions to the value in a given Object.
* But rather than applying the same mapping function to every value in an Object, instead you use a "spec" object to link the appropriate mapping function to the key/val in the input Object.
*
* This is similar to Ramda's `evolve()` however you can also set values in your spec that are _not_ functions (which will just override whatever matching key there might be on the input object).
* Addtionally, it supplies the key and the object as the 2nd and third params to your spec's transformation function, so that you can create props based on the entire input Object (with Ramda you'll need to also use `applySpec()` and in a separate operation to derived these kinds of values).
*
* As an example, If you want a mapping function to be applied to a prop called "name", then you would first pass in a spec object with a prop on it called "name" and the value would be the mapping function.
* Then the actual input object (with the desciption field) will have the matching mapping function from your spec applied to it directly.
*
* @function
* @param {object} spec An Object whose keys should correspond to keys in the input Object and whose values are mapping functions that will receive the matching input Object's prop as input
* @param {object} inputObj The actual input to map over and transform
* @returns {object} A new Object with all the mapping functions from the spec Object applied to the corresponding values in the input Object (if they exist)
* @example
* mapSpec({
* age: Number,
* isAlive: Boolean,
* name: str => `${str.charAt(0).toUpperCase()}${str.slice(1)}`
* }, {
* age: '20',
* isAlive: 1,
* name: 'john'
* })
*/
function mapSpec(spec, obj) {
var newObj = {};
(0, _forIn.default)(function (key, val, ob) {
if (typeof spec[key] === "function") {
newObj[key] = spec[key](val, key, ob);
} else if ((0, _isObject.default)(spec[key])) {
newObj[key] = mapSpec(spec[key], val);
} else {
newObj[key] = val;
}
}, obj);
(0, _forIn.default)(function (key, val) {
if (typeof val !== "function") {
newObj[key] = val;
} else if (!(0, _has.default)(key, newObj)) {
newObj[key] = val(undefined, key, newObj);
}
}, spec);
return newObj;
}
var _default = mapSpec;
exports.default = _default;
module.exports = exports.default;
});
var omit_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _forIn = _interopRequireDefault(forIn_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Removes specified keys from an object (after cloning the Object).
*
* @function
* @param {Array<string>} keys An array of keys to search for in the Object and exclude from the output
* @param {object} obj An Object from which to copy and remove keys
* @returns {object} A copy of the original Object, but without the specified keys
*/
function omit(keys, obj) {
var newObj = {};
(0, _forIn.default)(function (key, val) {
if (!(0, _includes_1._includes)(key, keys)) {
newObj[key] = val;
}
}, obj);
return newObj;
}
var _default = omit;
exports.default = _default;
module.exports = exports.default;
});
var omit = /*@__PURE__*/getDefaultExportFromCjs(omit_1);
var pick_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Removes everything _except_ the specified keys from an object (after cloning the Object).
*
* @function
* @param {Array<String>} keys An array of keys to search for in the Object and include from the output
* @param {object} obj An Object from which to copy and remove keys
* @returns {object} A copy of the original Object, but with _only_ the specified keys
*/
function pick(keys, obj) {
var newObj = {};
var numOfKeys = keys.length;
for (var i = 0; i < numOfKeys; i++) {
if (keys[i] in obj) {
newObj[keys[i]] = obj[keys[i]];
}
}
return newObj;
}
var _default = pick;
exports.default = _default;
module.exports = exports.default;
});
var pick = /*@__PURE__*/getDefaultExportFromCjs(pick_1);
var prepend_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _merge = _interopRequireDefault(merge_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Merges two values together, placing the characters (or values) from one before those from the other.
*
* @function
* @param {Array<*>|object|String|Number} firstVal An Array, Object, String or Number that the will have a new value(s) merged before its own characters/values
* @param {Array<*>|object|String|Number} secondVal An Array, Object, String or Number that the will merge _before_ those from the first provided value
* @returns {Array<*>|object|String} A new Array, Object, or String that has the characters/values from the second provided value merged _before_ those from the first provided value
*/
function prepend(firstVal, secondVal) {
if ([firstVal, secondVal].every(function (val) {
return typeof val === "string" || typeof val === "number";
})) {
return "" + secondVal + firstVal;
}
if (Array.isArray(firstVal) && Array.isArray(secondVal)) {
return [].concat(secondVal, firstVal);
}
return (0, _merge.default)(secondVal, firstVal);
}
var _default = prepend;
exports.default = _default;
module.exports = exports.default;
});
var propAt_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
/**
* Looks for a specified key on an Object you provide.
* The is performed safely and will not throw an error if something on the prop path chain you specify doesn't exist.
* Will always return `undefined` if a prop path cannot be resolved (rather than throwing).
*
* @function
* @param {String|Array<String>} prop A top-level key OR a deeply nested prop path (which may be represented as an array or as a single dot-delimited string)
* @param {object} obj An object which may contain a specified prop
* @returns {*|undefined} The value associated with the nested prop path OR undefined if it does not exist
*/
function propAt(prop, obj) {
try {
var paths = typeof prop === "string" ? prop.split(".") : prop;
var len = paths.length;
if (len === 0) return undefined;
var idx = 0;
var val = obj[paths[idx]];
while (++idx < len) {
val = val[paths[idx]];
}
return val;
} catch (err) {// Prop wasn't found; returning undefined
}
}
var _default = propAt;
exports.default = _default;
module.exports = exports.default;
});
var propEquals_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _propAt = _interopRequireDefault(propAt_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Looks for a specified key on an Object you provide and checks to see if its corresponding value equals the value you specifiy.
*
* @function
* @param {String} prop A key to search for on the Object
* @param {Function|String} val A value that the extracted prop will be compared against
* @param {object} obj An object which may contain a specified prop
* @returns {Boolean} Whether or not the requested prop equals the specified value
*/
function propEquals(prop, val, obj) {
return (0, _propAt.default)(prop, obj) === val;
}
var _default = propEquals;
exports.default = _default;
module.exports = exports.default;
});
var is_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _getConstructorName = _interopRequireDefault(getConstructorName_1);
var _getType = _interopRequireDefault(getType_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Checks to see if a value is a certain type.
* You may specify that type as a case-insensitive string
* (ie, 'string', 'boolean', 'object', 'function', 'array', 'regexp', 'date', 'set, 'map'), OR a JavaScript type constructor function (ie, String, Function, Boolean, Array, RegExp, Date, Set, Map).
*
* @function
* @param {Function|String} ofType A JavaScript type constructor function (like `Function`, `String`, `RegExp`, `Boolean`, `Array`, `Object`, etc.) or a string value matching the name of one
* @param {*} val A value (of any type)
* @returns {Boolean} Whether or not the value matches the specified type
* @example
* is('boolean', true)
* is('array', [1, 2, 3])
* is(RegExp, /[a-z0-9]/)
* is(Function, () => null)
*
*/
function is(ofType, val) {
return ofType === val || typeof ofType === "string" && (0, _getType.default)(val).toLowerCase() === ofType.toLowerCase() || ofType && !ofType.name && (0, _getType.default)(ofType) === (0, _getType.default)(val) || ofType && ofType.name && (0, _getConstructorName.default)(ofType) === "Function" && (0, _getType.default)(val) === ofType.name;
}
var _default = is;
exports.default = _default;
module.exports = exports.default;
});
var propIs_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _propAt = _interopRequireDefault(propAt_1);
var _is = _interopRequireDefault(is_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Looks for a specified key on an Object you provide and checks to see if its corresponding value is of the type you specifiy.
*
* @function
* @param {Function|String} type A JavaScript type constructor function (ie `Boolean`, `RegExp`, `Date`, `Array`, `Object`, `Number`, `String`, etc) OR a string represention of the type (ie, "boolean", "regexp", "date", "array", "object", "number", "string", etc)
* @param {String} prop A key to search for on the Object
* @param {object} obj An object which may contain a specified prop
* @returns {Boolean} Whether or not the requested prop is of the type specified
*/
function propIs(type, prop, obj) {
return (0, _is.default)(type, (0, _propAt.default)(prop, obj));
}
var _default = propIs;
exports.default = _default;
module.exports = exports.default;
});
var propOr_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _propAt = _interopRequireDefault(propAt_1);
var _isUndefined = _interopRequireDefault(isUndefined_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Attempts to find a specified key on an Object you provide, and if not found will fall back to an additional value you specify.
*
* @function
* @param {*} fallback A value to fall back on if the requested key does not exist on the provided Object
* @param {String} prop A key to search for on the Object
* @param {object} obj An object which may contain a specified prop
* @returns {*} Either the requested prop (from the Object) or the fallback value
*/
function propOr(fallback, prop, obj) {
var val = (0, _propAt.default)(prop, obj);
return (0, _isUndefined.default)(val) ? fallback : val;
}
var _default = propOr;
exports.default = _default;
module.exports = exports.default;
});
var clone_1 = createCommonjsModule(function (module, exports) {
exports.__esModule = true;
exports.default = void 0;
var _isNil = _interopRequireDefault(isNil_1);
var _isObject = _interopRequireDefault(isObject_1);
var _forIn = _interopRequireDefault(forIn_1);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Recursively copies the content of an Object into a new Object
*
* @function
* @param {object|Array<*>} obj An Object (or Array) from which to create a deep copy
* @returns {object|Array<*>