UNPKG

86.2 kBSource Map (JSON)View Raw
1{"version":3,"file":"functions-b6202a08.js","sources":["../src/functions.js"],"sourcesContent":["/**\n * Created by Andy Likuski on 2017.02.26\n * Copyright (c) 2017 Andy Likuski\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n *\n */\n\n/*\n* Utility functions, which rely heavily on Ramda, data.task, and Ramda Fantasy types\n* These functions should all be pure. Equivalent throwing functions can\n* be found in throwingFunctions. throwingFunctions should only be used for coding errors,\n* such as improper function arguments or an invalid path within object.\n* I/O Errors should be handled using Maybe or Result and calling functions should expect them.\n* An I/O Error should always result in a valid state of an application, even if that valid\n* state is to show an error message, retryTask I/O, etc.\n*/\n\nimport * as R from 'ramda';\nimport * as Rm from 'ramda-maybe';\nimport * as Result from 'folktale/result';\n\n// https://stackoverflow.com/questions/17843691/javascript-regex-to-match-a-regex\nconst regexToMatchARegex = /\\/((?![*+?])(?:[^\\r\\n\\[/\\\\]|\\\\.|\\[(?:[^\\r\\n\\]\\\\]|\\\\.)*\\])+)\\/((?:g(?:im?|mi?)?|i(?:gm?|mg?)?|m(?:gi?|ig?)?)?)/;\n\n\n/**\n * We use this instead of isObject since it's possible to have something that is an object without\n * a prototype to make it an object type\n * @param {*} obj value to test\n * @return {boolean} True if R.is(Object, obj) or is not null and it a typeof 'object'\n */\nexport const isObject = obj => {\n return R.is(Object, obj) || (obj !== null && typeof obj === 'object');\n};\n\n/**\n * Return an empty string if the given entity is falsy\n * @param {Object} entity The entity to check\n * @returns {String|Object} The empty string or the Object\n * @sig orEmpty:: a -> a\n * :: a -> String\n */\nexport const orEmpty = entity => entity || '';\n\n/**\n * Removed null or undefined items from an iterable\n * @param [a] items Items that might have falsy values to remove\n * @returns The compacted items\n * @sig compact:: [a] -> [a]\n * @sig compact:: {k,v} -> {k,v}\n */\nexport const compact = R.reject(R.isNil);\n\n/**\n * Remove empty strings\n * @param [a] items Items that might have empty or null strings to remove\n * @returns The compacted items\n * @sig compactEmpty:: [a] -> [a]\n */\nexport const compactEmpty = R.reject(R.either(R.isNil, R.isEmpty));\n\n/**\n * Convert an empty value to null\n * @param a item Item that might be empty according to isEmpty\n * @returns the\n * @sig emptyToNull:: a -> a\n * :: a -> null\n */\nexport const emptyToNull = R.when(R.isEmpty, () => null);\n\n/**\n * Join elements, first remove null items and empty strings. If the result is empty make it null\n * @param connector Join connector string\n * @param [a] items Items to join that might be removed\n * @sig compactEmpty:: [a] -> String\n * :: [a] -> null\n */\nexport const compactJoin = R.compose(\n (connector, items) => R.pipe(compactEmpty, R.join(connector), emptyToNull)(items)\n);\n\n/**\n * Creates a partial mapping function that expects an iterable and maps each item of the iterable to the given property\n * @param {String} prop The prop of each object to map\n * @param {[Object]} items The objects to map\n * @returns {[Object]} The mapped objects\n * @sig mapProp :: String -> [{k, v}] -> [a]\n */\nexport const mapProp = R.curry((prop, objs) => R.pipe(R.prop, R.map)(prop)(objs));\n\n/**\n * Creates a partial function that maps an array of objects to an object keyed by the given prop of the object's\n * of the array, valued by the item. If the item is not an array, it leaves it alone, assuming it is already indexed\n * @param {String} prop The prop of each object to use as the key\n * @param {[Object]} items The items to map\n * @returns {Object} The returned object\n * @sig mapPropValueAsIndex:: String -> [{k, v}] -> {j, {k, v}}\n * @sig mapPropValueAsIndex:: String -> {k, v} -> {k, v}\n */\nexport const mapPropValueAsIndex = R.curry((prop, obj) =>\n R.when(\n Array.isArray,\n R.pipe(R.prop, R.indexBy)(prop)\n )(obj));\n\n/**\n * Merges a list of objects by the given key and returns the values, meaning all items that are\n * duplicate prop key value are removed from the final list\n * @returns {[Object]} The items without the duplicates\n * @sig removeDuplicateObjectsByProp:: String -> [{k, v}] -> [{k, v}]\n */\nexport const removeDuplicateObjectsByProp = R.curry((prop, list) =>\n R.pipe(\n mapPropValueAsIndex(prop),\n R.values\n )(list)\n);\n\n/**\n * Returns the id of the given value if it is an object or the value itself if it is not.\n * @param {Object|String|Number} objOrId\n * @returns {String|Number} an id\n * @sig idOrIdFromObj:: a -> a\n * :: {k, v} -> a\n */\nexport const idOrIdFromObj = R.when(\n objOrId => (typeof objOrId === 'object') && objOrId !== null,\n R.prop('id')\n);\n\n/**\n * Deep merge values that are objects but not arrays\n * based on https://github.com/ramda/ramda/pull/1088\n * @params {Object} l the 'left' side object to merge\n * @params {Object} r the 'right' side object to merge\n * @type {Immutable.Map<string, V>|__Cursor.Cursor|List<T>|Map<K, V>|*}\n * @returns {Object} The deep-merged object\n * @sig mergeDeep:: (<k, v>, <k, v>) -> <k, v>\n */\nexport const mergeDeep = R.mergeWith((l, r) => {\n // If either (hopefully both) items are arrays or not both objects\n // accept the right value\n return (\n // If either is a function take the last\n (R.is(Function, l) || R.is(Function, r)) ||\n // If either is an array take the last\n (l && l.concat && Array.isArray(l)) ||\n (r && r.concat && Array.isArray(r))) ||\n !(R.is(Object, l) && R.is(Object, r)) ?\n r :\n mergeDeep(l, r); // tail recursive\n});\n\n/**\n * mergeDeep any number of objects\n * @params {[Object]} objs Array of objects to reduce\n * @returns {Object} The deep-merged objects\n */\nexport const mergeDeepAll = R.reduce(mergeDeep, {});\n\n/**\n * Deep merge values with a custom function that are objects\n * based on https://github.com/ramda/ramda/pull/1088\n * @params {Function} fn The merge function left l, right r:: l -> r -> a\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged objeck\n * @sig mergeDeep:: (<k, v>, <k, v>) -> <k, v>\n */\nexport const mergeDeepWith = R.curry((fn, left, right) => R.mergeWith((l, r) => {\n // If either (hopefully both) items are arrays or not both objects\n // accept the right value\n return (\n (l && l.concat && Array.isArray(l)) ||\n (r && r.concat && Array.isArray(r))\n ) ||\n !(R.all(isObject))([l, r]) ||\n R.any(R.is(Function))([l, r]) ?\n fn(l, r) :\n mergeDeepWith(fn, l, r); // tail recursive\n})(left, right));\n\n/**\n * Merge Deep that concats arrays of matching keys\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged object\n * @sig mergeDeep:: (<k, v>, <k, v>) -> <k, v>\n */\nexport const mergeDeepWithConcatArrays = R.curry((left, right) => mergeDeepWith((l, r) => {\n return R.cond(\n [\n [R.all(R.allPass([R.identity, R.prop('concat'), Array.isArray])), R.apply(R.concat)],\n [R.complement(R.all)(isObject), R.last],\n [R.T, R.apply(mergeDeepWithConcatArrays)] // tail recursive\n ]\n )([l, r]);\n})(left, right));\n\n/**\n * Merge Deep and also apply the given function to array items with the same index\n * @params {Function} fn The merge function left l, right r, string k:: l -> r -> k -> a\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged object\n * @sig mergeDeepWithRecurseArrayItems:: (<k, v>, <k, v>, k) -> <k, v>\n */\nexport const mergeDeepWithRecurseArrayItems = R.curry((fn, left, right) => R.cond(\n [\n // Arrays\n [R.all(R.allPass([R.identity, R.prop('concat'), Array.isArray])),\n ([l, r]) => {\n return R.zipWith((a, b) => mergeDeepWithRecurseArrayItems(fn, a, b), l, r);\n }\n ],\n // Primitives\n [R.complement(R.all)(isObject),\n ([l, r]) => {\n return fn(l, r);\n }],\n // Objects\n [R.T, ([l, r]) => {\n return R.mergeWith(mergeDeepWithRecurseArrayItems(fn), l, r);\n }]\n ]\n )([left, right])\n);\n\n/**\n * Like mergeDeepWithRecurseArrayItems but merges array items with a function itemMatchBy that determines\n * if an item from each array of left and right represents the same objects. The right object's array\n * items are returned but any left object item matching by itemMatchBy is deep merged with the matching right item.\n * There is no merge function for primitives, r is always returned\n * @params {Function} fn The item matching function, Arrays deep items in left and right. Called with the\n * item and current key/index\n * are merged. For example\n * item => R.when(isObject, R.propOr(v, 'id'))(item)\n * would match on id if item is an object and has an id\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to merge\n * @params {String} [key] Optional key or index of the parent object/array item\n * @returns {Object} The deep-merged object\n */\nexport const mergeDeepWithRecurseArrayItemsByRight = R.curry((itemMatchBy, left, right) => {\n return _mergeDeepWithRecurseArrayItemsByRight(itemMatchBy, null, left, right, null);\n});\n\n/**\n * Like mergeDeepWithRecurseArrayItemsByRight but takes mergeObject to merge objects, rather than just taking the\n * right value. Primitives still resolve to the right value. the mergeObject function should handle internal array\n * merging by recursing on this function or similar\n * @params {Function} fn The item matching function, Arrays deep items in left and right. Called with the\n * item and current key/index\n * are merged. For example\n * item => R.when(isObject, R.propOr(v, 'id'))(item)\n * would match on id if item is an object and has an id\n * @params {Function} itemMatchBy Expects the left and right object that need to be merged\n * @params {Function} mergeObject Expects left and right when they are objects. mergeObject typically recurses\n * with mergeDeepWithRecurseArrayItemsByAndMergeObjectByRight on each item of left and right after doing something\n * special. This function was designed with the idea of being used in Apollo InMemory Cache Type Policy merge functions\n * to continue calling Apollowing merge function on objects, which in tern delegates back to this function\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to merge\n * @params {String} [key] Optional key or index of the parent object/array item\n * @returns {Object} The deep-merged object\n */\nexport const mergeDeepWithRecurseArrayItemsByAndMergeObjectByRight = R.curry((itemMatchBy, mergeObject, left, right) => {\n return _mergeDeepWithRecurseArrayItemsByRight(itemMatchBy, mergeObject, left, right, null);\n});\n\nexport const _mergeDeepWithRecurseArrayItemsByRight = (itemMatchBy, mergeObject, left, right, key) => {\n return R.cond(\n [\n // Arrays\n [([l, r]) => {\n return R.any(R.allPass([R.identity, R.prop('concat'), Array.isArray]))([l, r]);\n },\n ([l, r]) => {\n // Null case, return the only array\n if (!l || !r) {\n return l || r;\n }\n // Create a lookup of l items\n const lItemsByValue = R.indexBy(li => itemMatchBy(li, key), l || []);\n // Map each item of r\n return R.addIndex(R.map)(\n (rItem, i) => {\n // If the lookup of the r item matches one of l items' itemMatchBy value,\n // recurse with both items. Else just return r\n const rItemValue = itemMatchBy(rItem, key);\n const hasMatchingLItem = R.has(rItemValue, lItemsByValue);\n return R.when(\n () => hasMatchingLItem,\n () => {\n // Pass the index as a key\n return _mergeDeepWithRecurseArrayItemsByRight(\n itemMatchBy,\n mergeObject,\n R.prop(rItemValue, lItemsByValue),\n rItem,\n i\n );\n }\n )(rItem);\n },\n r || []\n );\n }\n ],\n // Primitives. If either is an object skip, it means 1 is null\n [R.none(isObject),\n ([l, r]) => {\n return r;\n }\n ],\n // Objects and nulls\n [R.T,\n ([l, r]) => {\n return mergeObject ? mergeObject(l, r) : R.mergeWithKey(\n (kk, ll, rr) => {\n return _mergeDeepWithRecurseArrayItemsByRight(\n itemMatchBy,\n mergeObject,\n ll,\n rr,\n kk\n );\n },\n l || {},\n r || {}\n );\n }\n ]\n ]\n )([left, right]);\n};\n\n\n/**\n * mergeDeepWithRecurseArrayItems but passes obj as left and right so fn is called on every key\n * @params {Function} fn The merge function left l, right r, string k:: l -> r -> k -> a\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged object\n * @sig mergeDeepWithRecurseArrayItems:: (<k, v>, <k, v>, k) -> <k, v>\n */\nexport const applyDeep = R.curry((fn, obj) => mergeDeepWithRecurseArrayItems(fn, obj, obj));\n\n\n/**\n * Merge Deep and also apply the given function to array items with the same index.\n * This adds another function that maps the object results to something else after the objects are recursed upon\n * @params {Function} fn The merge function left l, right r, string k:: l -> r -> k -> a\n * @params {Function} applyObj Function called with the current key and the result of each recursion that is an object.\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged object\n * @sig mergeDeepWithRecurseArrayItems:: (<k, v>, <k, v>, k) -> <k, v>\n */\nexport const mergeDeepWithRecurseArrayItemsAndMapObjs = R.curry((fn, applyObj, left, right) =>\n _mergeDeepWithRecurseArrayItemsAndMapObjs(fn, applyObj, null, left, right)\n);\n\n/**\n * Same as mergeDeepWithRecurseArrayItemsAndMapObjs but sends the same left and right value so fn is called on every key\n * of ob * @params {Function} fn The merge function left l, right r, string k:: l -> r -> k -> a\n * @params {Function} applyObj Function called with the current key and the result of each recursion that is an object.\n * @params {Object} left the 'left' side object to merge\n * @params {Object} right the 'right' side object to morge\n * @returns {Object} The deep-merged object\n * @sig applyDeepAndMapObjs:: (<k, v>, <k, v>, k) -> <k, v>j\n */\nexport const applyDeepAndMapObjs = R.curry((fn, applyObj, obj) =>\n mergeDeepWithRecurseArrayItemsAndMapObjs(fn, applyObj, obj, obj)\n);\n\nconst _mergeDeepWithRecurseArrayItemsAndMapObjs = R.curry((fn, applyObj, key, left, right) => {\n return R.cond(\n [\n // Arrays\n [R.all(Array.isArray),\n // Recurse on each array item. We pass the key without the index\n lr => {\n return R.apply(\n R.zipWith(\n (l, r) => R.compose(\n // For array items, take key and the result and call the applyObj func, but only if res is an Object\n v => R.when(\n // When it's an object and not an array call applyObj\n // typeof x === 'object' check because sometimes values that are objects are not returning true\n R.both(\n vv => typeof vv === 'object',\n R.complement(R.is)(Array)\n ),\n res => applyObj(key, res)\n )(v),\n ([kk, ll, rr]) => _mergeDeepWithRecurseArrayItemsAndMapObjs(fn, applyObj, kk, ll, rr)\n )([key, l, r])\n )\n )(lr);\n }\n ],\n // Primitives: call the function with left and right as the first two args and key as the last\n [R.complement(R.all)(x => isObject(x)), lr => {\n return fn(...lr, key);\n }],\n // Always leave functions alone.\n [lr => R.all(R.is(Function), lr), ([l, _]) => {\n return l;\n }],\n // Objects\n [R.T,\n lr => {\n return R.apply(\n R.mergeWithKey(\n (k, l, r) => R.compose(\n // Take key and the result and call the applyObj func, but only if res is an Object\n v => R.when(\n // When it's an object and not an array call applyObj\n // typeof x === 'object' check because sometimes values that are objects are not returning true\n R.both(\n x => typeof x === 'object',\n R.complement(R.is)(Array)\n ),\n res => applyObj(k, res)\n )(v),\n // First recurse on l and r\n ([kk, ll, rr]) => R.apply(_mergeDeepWithRecurseArrayItemsAndMapObjs(fn, applyObj), [kk, ll, rr])\n )([k, l, r])\n ),\n lr\n );\n }\n ]\n ]\n )([left, right]);\n }\n);\n\n\n/**\n * http://stackoverflow.com/questions/40011725/point-free-style-capitalize-function-with-ramda\n * Capitalize the first letter\n * @param {String} str The string to capitalize\n * @returns {String} The capitalized string\n * @sig capitalize:: String -> String\n */\nexport const capitalize = str => R.compose(\n R.join(''),\n R.juxt([R.compose(R.toUpper, R.head), R.tail])\n)(str);\n\n/**\n * http://stackoverflow.com/questions/40011725/point-free-style-capitalize-function-with-ramda\n * Lowercase the first letter\n * @param {String} str The string to lowercase\n * @returns {String} The capitalized string\n * @sig capitalize:: String -> String\n */\nexport const lowercase = str => R.compose(\n R.join(''),\n R.juxt([R.compose(R.toLower, R.head), R.tail])\n)(str);\n\n/**\n * From https://github.com/substack/camelize/blob/master/index.js\n * @param {String} str The string to camelCase\n * @returns {String} The camel-cased string\n */\nexport const camelCase = str =>\n R.toLower(str).replace(\n /[_.-](\\w|$)/g,\n (_, x) => x.toUpperCase()\n );\n\n/**\n * Merge a list of objects using the given concat function\n * [{k: v}] → {k: v}\n * @returns {Object} The merged object\n * @sig mergeAllWithKey:: (String → a → a → a) → [{a}] → {a}\n */\nexport const mergeAllWithKey = R.curry((fn, [head, ...rest]) =>\n R.mergeWithKey( // call mergeWithKey on two objects at a time\n fn,\n head || {}, // first object is always the head\n R.ifElse( // second object is the merged object of the recursion\n R.isEmpty, // if no rest\n () => R.empty({}), // end case empty object\n mergeAllWithKey(fn) // else recurse with the rest\n )(rest)\n )\n);\n\n/**\n * Get a required path or return a helpful Error if it fails\n * @param {String} path A lensPath, e.g. ['a', 'b'] or ['a', 2, 'b']\n * @param {Object} obj The object to inspect\n * @returns {Result} Result the resolved value or an Error\n * @sig reqPath:: String -> {k: v} → Result\n */\nexport const reqPath = R.curry((path, obj) => {\n return R.compose(\n R.ifElse(\n // If path doesn't resolve\n maybe => maybe.isNothing,\n // Create a useful Error message\n () => Result.Error({\n resolved: R.reduceWhile(\n // Stop if the accumulated segments can't be resolved\n (segments, segment) => R.not(R.isNil(R.path(R.concat(segments, [segment]), obj))),\n // Accumulate segments\n (segments, segment) => R.concat(segments, [segment]),\n [],\n path\n ),\n path: path\n }),\n // Return the resolved value\n res => Result.Ok(res.value)\n ),\n // Try to resolve the value using the path and obj, returning Maybe\n Rm.path(path)\n )(obj);\n});\n\n/**\n * Expects a prop path and returns a function expecting props,\n * which resolves the prop indicated by the string. Returns Result.Error if there is not match\n * @param {String} str dot-separated prop path\n * @param {Object} props Object to resolve the path in\n * @return {Result} Result.Ok with the resolved value or Result.Error if the path doesn't exist or the\n * value is null\n */\nexport const reqStrPath = R.curry((str, props) => reqPath(R.split('.', str), props));\n\n/**\n * Expects a prop path and returns a function expecting props,\n * which resolves the prop indicated by the string. If not match is found it returns undefined\n * @param {String} str dot-separated prop path\n * @param {Object} props Object to resolve the path in\n * @return {Object} The resolved object or undefined\n */\nexport const strPath = R.curry((str, props) => {\n return R.view(R.lensPath(R.split('.', str)), props);\n});\n\n/**\n * Like strPath but defaults the given value\n * @param {Object} defaultValue. Default value if value is null undefined.\n * @param {String} str dot-separated prop path\n * @param {Object} props Object to resolve the path in\n * @return {function(*=)}\n */\nexport const strPathOr = R.curry((defaultValue, str, props) => {\n const result = R.view(R.lensPath(R.split('.', str)), props);\n return R.when(\n R.isNil,\n R.always(defaultValue)\n )(result);\n});\n\nexport const strPathOrNullOk = R.curry((defaultValue, str, props) => {\n const segments = R.split('.', str);\n const result = R.view(R.lensPath(R.init(segments)), props);\n return R.ifElse(\n R.isNil,\n R.always(defaultValue),\n r => {\n try {\n return R.when(v => typeof v === 'undefined', () => defaultValue)(R.prop(R.last(segments), r));\n } catch {\n return defaultValue;\n }\n }\n )(result);\n});\n\n/**\n * Returns true if the given string path is non-null\n * @param {String} str dot-separated prop path\n * @param {Object} props Object to resolve the path in\n * @returns {Boolean} true\n */\nexport const hasStrPath = R.curry((str, props) =>\n R.complement(R.isNil)(\n R.view(R.lensPath(R.split('.', str)), props)\n )\n);\n\n/**\n * Uses reqPath to resolve the path of an object and compares it to val\n * @param {String} path A lensPath, e.g. ['a', 'b'] or ['a', 2, 'b']\n * @param {*} val The val to do an equality check on\n * @param {Object} obj The object to inspect\n * @returns {Result} Result the resolved value or an Error\n * @sig reqPath:: String -> {k: v} → Result\n */\nexport const reqPathPropEq = R.curry((path, val, obj) =>\n // If the reqPath is valid map it to a comparison with val\n reqPath(path, obj).map(R.equals(val))\n);\n\n/**\n * From the cookbook: https://github.com/ramda/ramda/wiki/Cookbook#map-keys-of-an-object\n * Maps keys according to the given function\n * @returns {Object} The mapped keys of the object\n * @sig mapKeys :: (String -> String) -> Object -> Object\n */\nexport const mapKeys = R.curry(\n (fn, obj) => R.compose(\n R.fromPairs,\n pairs => R.map(\n // Apply fn to index 0 of pair\n pair => R.adjust(0, fn, pair),\n pairs\n ),\n R.toPairs\n )(obj)\n);\n\n\n/**\n * Uses a lens to map keys that are embedded in a data structure\n * The lens must indicate an object whose keys shall be mapped\n * @returns {Object} Object with the keys indicated by the given lens mapped\n * @sig mapKeysForLens :: Lens -> ((String -> String) -> Object -> Object\n */\nexport const mapKeysForLens = R.curry((lens, fn, obj) =>\n // Sets the lens-focused objects to a new object with keys mapped according to the function\n R.set(lens, mapKeys(fn, R.view(lens, obj)), obj)\n);\n\n/**\n * Converts default to desired name. Used for requiring defaults\n * @param {String} keyName The desired rename of 'default'\n * @param {Object} module A required module with a default key\n * @returns {Object} The import module with key default changed to keyName\n * @sig mapDefault :: String -> <k,v> -> <k,v>\n */\nexport const mapDefault = (keyName, module) => mapKeys(key => key === 'default' ? keyName : key, module);\n/**\n * Converts default to desired name and prefixes others.\n * Used for requiring defaults and renaming others\n * @param {String} defaultName The desired rename of 'default'\n * @param {String} prefix The desired prefix for others. Camel Case maintained\n * @param {Object} module A required module with a default key\n * @returns {Object} The import module with key default changed to keyName\n * @sig mapDefault :: String -> <k,v> -> <k,v>\n */\nexport const mapDefaultAndPrefixOthers = (defaultName, prefix, module) =>\n mapKeys(\n key => (key === 'default') ? defaultName : `${prefix}${capitalize(key)}`,\n module\n );\n\n/**\n * Maps an object with a function that returns pairs and create and object therefrom\n * Like R.mapObjIndexed, the function's first argument is the value of each item, and the seconds is the key if\n * iterating over objects\n * @params {Functor} f The mapping function\n * @params {Container} container Anything that can be mapped\n * @returns {Object} The mapped pairs made into key values\n * @sig mapKeysAndValues :: Functor F = (a -> [b,c]) -> F -> <k,v>\n */\nexport const mapKeysAndValues = R.curry((f, container) => R.fromPairs(mapObjToValues(f, container)));\n\n/**\n * https://github.com/ramda/ramda/wiki/Cookbook\n * Filter objects with values and keys. Null objs return as null\n * @param {Function} pred (value, key) => True|False\n * @param {Object} obj The object to filter\n * @returns {Object} The filtered object\n * @sig filterWithKeys:: (v -> k -> True|False) -> <k,v> -> <k,v>\n */\nexport const filterWithKeys = R.curry((pred, obj) => {\n if (!obj) {\n return obj;\n }\n return R.compose(\n R.fromPairs,\n R.filter(pair => R.apply(pred, R.reverse(pair))),\n R.toPairs\n )(obj);\n});\n\n/**\n * Transforms the keys of the given object with the given func\n * @param {Function} func The mapping function that expects the key\n * @param {Object} The object to map\n * @returns {Object} The object with transformed keys and the original values\n */\nexport const transformKeys = R.curry((func, obj) =>\n R.compose(\n R.fromPairs,\n R.map(([key, value]) =>\n [func(key), value]),\n R.toPairs\n )(obj)\n);\n\n/**\n * Renames the key of the object specified by the lens\n * @param {Function} lens A ramda lens that points to the object containing the key, not the key itself.\n * Use R.lensPath([]) to operate directly on obj\n * @param {String} from Key to rename\n * @param {String} to New name for the key\n * @param {Object} obj Object to traverse with the lens\n */\nexport const renameKey = R.curry((lens, from, to, obj) => R.over(\n lens,\n target => mapKeys(\n R.when(R.equals(from), R.always(to)),\n target),\n obj));\n\n/**\n * Duplicates the key of the object specified by the lens and key, to the given list of keys or single key.\n * A duplicate of the value at key will be added at each of the toKeys using R.clone\n * @param {Function} lens A ramda lens that points to the object containing the key, not the key itself\n * @param {String} key Key to duplicate the value of\n * @param {String|[String]} toKeys Array of new keys to make. New keys overwrite existing keys\n * @param {Object} obj Object to traverse with the lens\n */\nexport const duplicateKey = R.curry((lens, key, toKeys, obj) => R.over(\n lens,\n // convert the target of the lens to a merge of the target with copies of target[key]\n target => R.merge(\n target,\n R.fromPairs(\n R.map(\n toKey => [toKey, R.clone(target[key])],\n toArrayIfNot(toKeys)\n )\n )\n ),\n // take the lens of this obj\n obj)\n);\n\n/**\n * Converts a scalar value (!Array.isArray) to array an array\n * @param {*|[*]} arrayOrScalar An array or scalar\n * @returns {[*]} The scalar as an array or the untouched array\n */\nexport const toArrayIfNot = arrayOrScalar => {\n return R.unless(Array.isArray, Array.of)(arrayOrScalar);\n};\n\n/**\n * Like duplicateKey but removes the original key\n * @param {Function} lens A ramda lens that points to the object containing the key, not the key itself\n * @param {String} key Key to duplicate the value of\n * @param [{String}] toKeys Array of new keys to make. New keys overwrite existing keys\n * @param {Object} obj Object to traverse with the lens\n */\nexport const moveToKeys = R.curry((lens, key, toKeys, obj) => R.over(\n lens,\n // convert the target of the lens to a merge of the target with copies of target[key]\n // and with target[key] itself removed\n target => R.merge(\n R.omit([key], target),\n R.fromPairs(\n R.map(\n toKey => [toKey, R.clone(target[key])],\n toKeys\n )\n )\n ),\n // take the lens of this obj\n obj)\n);\n\n/**\n * Like R.find but expects only one match and works on both arrays and objects\n * Note this still iterates through the whole list or object, so this should be rewritten to quit when one is found\n * @param {Function} predicate\n * @param {Array|Object} obj Container that should only match once with predicate\n * @returns {Result} Result.Error if no matches or more than one, otherwise Result.Ok with the single matching item in an array/object\n */\nexport const findOne = R.curry((predicate, obj) =>\n R.ifElse(\n // If path doesn't resolve\n items => R.equals(R.length(R.keys(items)), 1),\n // Return the resolved single key/value object\n items => Result.Ok(items),\n // Create a useful Error message\n items => Result.Error({\n all: obj,\n matching: items\n })\n )(R.filter(predicate, obj))\n);\n\n/**\n * Version of find one that accepts all items of the given Container\n * @param {Array|Object} obj Container\n * @returns {Result} Result.Error if no items or more than one, otherwise Result.Ok with the single item in an array/object\n */\nexport const onlyOne = findOne(R.T);\n\n/**\n * Like onlyOne but extracts the value\n * @param {Array|Object|Result} obj Container that should have one value to extract. This currently expects\n * and array or object or Result, but it could be expanded to take Result, Maybe, or any other container where\n * the value can be extracted. Types like Tasks and Streams can't extract, I suppose\n * @returns {Result} Result.Error if no items or more than one, otherwise Result.Ok with the single value\n */\nexport const onlyOneValue = R.compose(\n // Use R.map to operate on the value of Result without extracting it\n R.map(R.head),\n R.map(R.values),\n findOne(R.T)\n);\n\n/**\n * Curryable Maps container values to the key and values of an object, applying f to each to make the value\n * @param {Function} f Transforms each item to a value\n * @param {Array} list Container to map to an object.\n * @sig mapToObjValue:: Functor a => (b -> c) -> <b, c>\n */\nexport const mapToObjValue = R.curry((f, obj) => R.compose(R.fromPairs, R.map(v => [v, f(v)]))(obj));\n\n\n/**\n * Finds an item that matches all the given props in params\n * @param {Object} params object key values to match\n * @param {Object|Array} items Object or Array that can produce values to search\n * @returns {Result} An Result.Ok containing the value or an Result.Error if no value is found\n */\nexport const findOneValueByParams = (params, items) => {\n return findOne(\n // Compare all the eqProps against each item\n R.allPass(\n // Create a eqProps for each prop of params\n R.map(prop => R.eqProps(prop, params),\n R.keys(params)\n )\n ),\n R.values(items)\n ).map(R.head);\n};\n\n/**\n * Returns the items matching all param key values\n * @param {Object} params Key values to match to items\n * @param {Object|Array} items Object with values of objects or array of objects that can produce values to search\n * @returns {[Object]} items that pass\n */\nexport const findByParams = (params, items) => {\n return R.filter(\n // Compare all the eqProps against each item\n R.allPass(\n // Create a eqProps for each prop of params\n R.map(prop => R.eqProps(prop, params),\n R.keys(params)\n )\n ),\n items\n );\n};\n\n/**\n * Returns the first mapped item that is not null\n * @param {Function} f The mapping function\n * @param {[*]} items The items\n * @returns {*} The first mapped item value that is not nil\n */\nexport const findMapped = (f, items) => {\n return R.reduceWhile(\n R.isNil,\n (_, i) => f(i),\n null,\n items\n );\n};\n\n/**\n * Converts the given value to an always function (that ignores all arguments) unless already a function\n * @param {Function} maybeFunc A function or something else\n * @return {Function} a function that always returns the non funcion value of maybeFunc, or maybeFunc\n * itself if maybeFunc is a functon\n */\nexport const alwaysFunc = maybeFunc => R.unless(R.is(Function), R.always)(maybeFunc);\n\n/**\n * Map the object with a function accepting a key, value, and the obj but return just the mapped values,\n * not the object\n * @param {Function} f Expects value, key, and obj\n * @param {Object} obj The object to map\n * @return {[Object]} Mapped values\n */\nexport const mapObjToValues = R.curry((f, obj) => {\n return R.values(R.mapObjIndexed(f, obj));\n});\n\n/**\n * Filter the given object and return the values, discarding the keys\n * @param {Function} f Receives each value and key\n * @param {Object} obj The object to filter\n * @return {Object} The filtered object values\n */\nexport const filterObjToValues = R.curry((f, obj) => {\n return R.values(filterWithKeys(f, obj));\n});\n/**\n * Like mapObjToValues but chains the values when an array is returned for each mapping\n * @param {Function} f Expects key, value, and obj\n * @param {Object} obj The object to chain\n * @return {[Object]} Mapped flattened values\n */\nexport const chainObjToValues = R.curry((f, obj) => {\n return R.chain(R.identity, mapObjToValues(f, obj));\n});\n\n\n/**\n *\n * This is a deep fromPairs. If it encounters a two element array it assumes it's a pair if the first\n * element is a string. If an array is not a pair it is iterated over and each element is recursed upon.\n * The 2nd element of each pair is also recursed upon. The end case for recursion is that an element is not an array.\n *\n * This method doesn't currently expect objects but could be easily modified to handle them\n * @param {[*]} deepPairs An array of deep pairs, with possibly other arrays at the top or lower levels\n * that aren't pairs but might contain them\n * @returns {Array|Object} All arrays of pairs are converted to objects. Arrays of non pairs are left as arrays\n */\nexport const fromPairsDeep = deepPairs => R.cond(\n [\n // It's array of pairs or some other array\n [Array.isArray, list =>\n R.ifElse(\n // Is the first item a two element array whose first item is a string?\n ([first]) => R.allPass(\n [\n Array.isArray,\n x => R.compose(R.equals(2), R.length)(x),\n x => R.compose(R.is(String), R.head)(x)\n ])(first),\n // Yes, return an object whose keys are the first element and values are the result of recursing on the second\n l => R.compose(R.fromPairs, R.map(([k, v]) => [k, fromPairsDeep(v)]))(l),\n // No, recurse on each array item\n l => R.map(v => fromPairsDeep(v), l)\n )(list)\n ],\n // End case, return the given value unadulterated\n [R.T, R.identity]\n ])(deepPairs);\n\n\n/**\n * At the given depth, object and array values are converted to the replacementString.\n * @param {Number} n Depth to replace at.\n * Depth 3 converts {a: {b: {c: 1}}} to {a: {b: {c: '...'}}}\n * Depth 2 converts {a: {b: {c: 1}}} to {a: {b: '...'}}\n * Depth 1 converts {a: {b: {c: 1}}} to {a: '...'}\n * Depth 0 converts {a: {b: {c: 1}}} to '...'\n * @param {String|Function} replaceStringOrFunc String such as '...' or a unary function that replaces the value\n * e.g. R.when(isObject, R.length(R.keys)) will count objects and arrays but leave primitives alone\n * @param {Object} obj Object to process\n * @returns {Object} with the above transformation. Use replaceValuesAtDepthAndStringify to get a string\n */\nexport function replaceValuesAtDepth(n, replaceStringOrFunc, obj) {\n return R.ifElse(\n // If we are above level 0 and we have an object\n R.both(R.always(R.lt(0, n)), isObject),\n // Then recurse on each object or array value\n o => R.map(oo => replaceValuesAtDepth(n - 1, replaceStringOrFunc, oo), o),\n // If at level 0 replace the value. If not an object or not at level 0, leave it alone\n o => R.when(R.always(R.equals(0, n)), alwaysFunc(replaceStringOrFunc))(o)\n )(obj);\n}\n\n/** *\n * replaceValuesAtDepth but stringifies result\n * @param {Number} n Depth to replace at.\n * Depth 3 converts {a: {b: {c: 1}}} to {a: {b: {c: '...'}}}\n * Depth 2 converts {a: {b: {c: 1}}} to {a: {b: '...'}}\n * Depth 1 converts {a: {b: {c: 1}}} to {a: '...'}\n * Depth 0 converts {a: {b: {c: 1}}} to '...'\n * @param {String|Function} replaceString String such as '...' or a unary function that replaces the value\n * e.g. R.when(isObject, R.length(R.keys)) will count objects and arrays but leave primitives alone\n * @param {Object} obj Object to process\n * @returns {String} after the above replacement\n */\nexport const replaceValuesAtDepthAndStringify = (n, replaceString, obj) => {\n return JSON.stringify(replaceValuesAtDepth(n, replaceString, obj));\n};\n\n/**\n * Convenient method to count objects and lists at the given depth but leave primitives alone\n * @param {Number} n Depth to replace at.\n * @param {Object} obj Object to process\n * @returns {Object} after the above replacement\n */\nexport const replaceValuesWithCountAtDepth = (n, obj) => {\n return replaceValuesAtDepth(\n n,\n R.when(\n isObject,\n o => R.compose(\n // Show arrays and objs different\n R.ifElse(R.always(Array.isArray(o)), c => `[...${c}]`, c => `{...${c}}`),\n R.length,\n R.keys)(o)\n ),\n obj);\n};\n\n/**\n * Convenient method to count objects and lists at the given depth but leave primitives alone and stringify result\n * @param {Number} n Depth to replace at.\n * @param {Object} obj Object to process\n * @returns {String} after the above replacement\n */\nexport const replaceValuesWithCountAtDepthAndStringify = (n, obj) => {\n return JSON.stringify(replaceValuesWithCountAtDepth(n, obj));\n};\n\n/**\n * Flattens an objects so deep keys and array indices become concatinated strings\n * E.g. {a: {b: [1, 3]}} => {'a.b.0': 1, 'a.b.1': 2}\n * @param {Object} obj The object to flattened\n * @returns {Object} The 1-D version of the object\n */\nexport const flattenObj = obj => {\n return R.fromPairs(_flattenObj({}, obj));\n};\n\n/**\n * Flatten objs until the predicate returns false. This is called recursively on each object and array\n * @param {Function} predicate Expects object, returns true when we should stop flatting on the current object\n * @param {Object} obj The object to flatten\n * @return {Object} The flattened object\n */\nexport const flattenObjUntil = (predicate, obj) => {\n return R.fromPairs(_flattenObj({predicate}, obj));\n};\n\nconst _flattenObj = (config, obj, keys = []) => {\n const predicate = R.propOr(null, 'predicate', config);\n return R.ifElse(\n // If we have an object\n o => R.both(\n isObject,\n oo => R.when(\n () => predicate,\n ooo => R.complement(predicate)(ooo)\n )(oo)\n )(o),\n // Then recurse on each object or array value\n o => chainObjToValues((oo, k) => _flattenObj(config, oo, R.concat(keys, [k])), o),\n // If not an object return flat pair\n o => [[R.join('.', keys), o]]\n )(obj);\n};\n\n/**\n * Converts a key string like 'foo.bar.0.wopper' to ['foo', 'bar', 0, 'wopper']\n * @param {String} keyString The dot-separated key string\n * @returns {[String]} The lens array containing string or integers\n */\nexport const keyStringToLensPath = keyString => R.map(\n R.when(R.compose(R.complement(R.equals)(NaN), parseInt), parseInt),\n R.split('.', keyString)\n);\n\n/**\n * Undoes the work of flattenObj. Does not allow number keys to become array indices\n * @param {Object} obj 1-D object in the form returned by flattenObj\n * @returns {Object} The original\n */\nexport const unflattenObjNoArrays = obj => {\n return _unflattenObj({allowArrays: false}, obj);\n};\n\n/**\n * Undoes the work of flattenObj\n * @param {Object} obj 1-D object in the form returned by flattenObj\n * @returns {Object} The original\n */\nexport const unflattenObj = obj => {\n return _unflattenObj({allowArrays: true}, obj);\n};\n\nexport const _unflattenObj = (config, obj) => {\n return R.compose(\n R.reduce(\n (accum, [keyString, value]) => {\n // Don't allow indices if allowArrays is false\n const itemKeyPath = R.map(\n key => {\n return R.when(\n () => R.not(R.prop('allowArrays', config)),\n k => k.toString()\n )(key);\n },\n keyStringToLensPath(keyString)\n );\n // Current item lens\n const itemLensPath = R.lensPath(itemKeyPath);\n // All but the last segment gives us the item container len\n const constainerKeyPath = R.init(itemKeyPath);\n const container = R.unless(\n // If the path has any length (not []) and the value is set, don't do anything\n R.both(R.always(R.length(constainerKeyPath)), R.view(R.lensPath(constainerKeyPath))),\n // Else we are at the top level, so use the existing accum or create a [] or {}\n // depending on if our item key is a number or not\n x => R.defaultTo(\n R.ifElse(\n v => R.both(() => R.prop('allowArrays', config), R.is(Number))(v),\n R.always([]),\n R.always({})\n )(R.head(itemKeyPath))\n )(x)\n )(accum);\n // Finally set the container at the itemLensPath\n return R.set(\n itemLensPath,\n value,\n container\n );\n },\n // null initial value\n null\n ),\n R.toPairs\n )(obj);\n};\n\n/**\n * Does something to every object\n * @param {Function} func Called on each object that is the child of another object. Called with the key that\n * points at it from the parent object and the object itself\n * @param {Object} obj The object to process\n */\nexport const overDeep = R.curry((func, obj) => mergeDeepWithRecurseArrayItemsAndMapObjs(\n // We are using a mergeDeepWithRecurseArrayItemsAndMapObjs but we only need the second function\n (l, r, k) => l,\n func,\n // Use obj twice so that all keys match and get called with the merge function\n obj,\n obj\n )\n);\n\n/**\n * Omit the given keys anywhere in a data structure. Objects and arrays are recursed and omit_deep is called\n * on each dictionary that hasn't been removed by omit_deep at a higher level\n */\nexport const omitDeep = R.curry(\n (omit_keys, obj) => omitDeepBy(\n (k, v) => R.includes(k, omit_keys),\n obj\n )\n);\n\n/**\n * Omit by the given function that is called with key and value. You can ignore the value if you only want to test the key\n * Objects and arrays are recursed and omit_deep is called\n * on each dictionary that hasn't been removed by omit_deep at a higher level\n * @param {Function} f Binary function accepting each key, value. Return non-nil to omit and false or nil to keep\n */\nexport const omitDeepBy = R.curry(\n (f, obj) => R.compose(\n o => applyDeepAndMapObjs(\n // If k is in omit_keys return {} to force the applyObj function to call. Otherwise take l since l and r are always the same\n // l and r are always the same value\n (l, r, kk) => R.ifElse(\n // Reject any function return value that isn't null or false\n k => R.anyPass([R.isNil, R.equals(false)])(f(k, l)),\n R.always(l),\n () => ({})\n )(kk),\n // Called as the result of each recursion. Removes the keys at any level except the topmost level\n (key, result) => filterWithKeys(\n (v, k) => R.anyPass([R.isNil, R.equals(false)])(f(k, v)),\n result\n ),\n o\n ),\n // Omit at the top level. We have to do this because applyObj of applyDeepAndMapObjs only gets called starting\n // on the object of each key\n // Reject any function return value that isn't null or false\n o => filterWithKeys(\n (v, k) => R.anyPass([R.isNil, R.equals(false)])(f(k, v)),\n o\n )\n )(obj)\n);\n\n/**\n * Given a predicate for eliminating an item based on paths, return the paths of item that don't pass the predicate.\n * keyOrIndex is the object key or array index that the item came from. We use it for the eliminateItemPredicate\n * test. If each paths current first segment matches keyOrIndex or equals '*', we consider that path.\n * With the considered paths\n * @param {Function} eliminateItemPredicate Accepts the remaining paths and optional item as a second argument.\n * Returns true if the item shall be eliminated\n * @param {[String]} paths Paths to caculate if they match the item\n * @param {*} item Item to test\n * @param {String|Number} keyOrIndex The key or index that the item belonged to of an object or array\n * @return {Object} {item: the item, paths: remaining paths with first segment removed}. Or null if eliminateItemPredicate\n * returns true\n * @private\n */\nconst _calculateRemainingPaths = (eliminateItemPredicate, paths, item, keyOrIndex) => {\n // Keep paths that match keyOrIndex as the first item. Remove other paths\n // since they can't match item or its descendants\n const tailPathsStillMatchingItemPath = compact(R.map(\n R.compose(\n R.ifElse(\n R.compose(\n aKeyOrIndex => {\n return R.ifElse(\n // if keyOrIndex is a string and matches the shape of a regex: /.../[gim]\n possibleRegex => R.both(R.is(String), str => R.test(regexToMatchARegex, str))(possibleRegex),\n // Construct the regex with one or two, the expression and options (gim)\n provenRegex => {\n const args = compactEmpty(R.split('/', provenRegex));\n return new RegExp(...args).test(keyOrIndex);\n },\n // If aKeyOrIndex is '*' or equals keyOrIndex always return true\n str => R.includes(str, ['*', keyOrIndex])\n )(aKeyOrIndex);\n },\n R.head\n ),\n // Matches the keyOrIndex at the head. Return the tail\n R.tail,\n // Mark null to remove from list\n R.always(null)),\n // Convert path to array with string keys and number indexes\n keyStringToLensPath\n ),\n paths\n ));\n // For omit:\n // If any path matches the path to the item return null so we can throw away the item\n // If no path is down to zero length return the item and the paths\n // For pick:\n // If no path matches the path to the item return null so we can throw away the item\n // If any path is not down to zero return the item and the paths, unless item is a primitive meaning it can't match\n // a path\n return R.ifElse(\n tailPaths => eliminateItemPredicate(tailPaths, item),\n R.always(null),\n p => ({item: item, paths: R.map(R.join('.'), p)})\n )(tailPathsStillMatchingItemPath);\n};\n\n// This predicate looks for any path that's zero length, meaning it matches the path to an item and we should\n// omit that item\nconst _omitDeepPathsEliminateItemPredicate = paths => R.any(R.compose(R.equals(0), R.length), paths);\n\n/**\n * Omit matching paths in a a structure. For instance omitDeepPaths(['a.b.c', 'a.0.1']) will omit keys\n * c in {a: {b: c: ...}}} and 'y' in {a: [['x', 'y']]}\n */\nexport const omitDeepPaths = R.curry((pathSet, obj) => R.cond([\n\n // Arrays\n [o => Array.isArray(o),\n list => {\n // Recurse on each array item that doesn't match the paths.\n // We pass the key without the index\n // If any path matches the path to the value we return the item and the matching paths\n const survivingItems = compact(R.addIndex(R.map)(\n (item, index) => _calculateRemainingPaths(_omitDeepPathsEliminateItemPredicate, pathSet, item, index),\n list\n ));\n return R.map(({paths, item}) => omitDeepPaths(paths, item), survivingItems);\n }\n ],\n // Primitives always pass.\n [R.complement(isObject), primitive => primitive],\n // Objects\n [R.T,\n o => {\n // Recurse on each object value that doesn't match the paths.\n const survivingItems = compact(R.mapObjIndexed(\n // If any path matches the path to the value we return the value and the matching paths\n // If no path matches it we know the value shouldn't be omitted so we don't recurse on it below\n (value, key) => _calculateRemainingPaths(_omitDeepPathsEliminateItemPredicate, pathSet, value, key),\n o\n ));\n // Only recurse on items from the object that are still eligible for omitting\n return R.map(({paths, item}) => omitDeepPaths(paths, item), survivingItems);\n }\n ]\n ]\n )(obj)\n);\n\n// This eliminate predicate returns true if no path is left matching the item's path so the item should not\n// be picked. It also returns true if the there are paths with length greater than 0\n// but item is a primitive, meaning it can't match a path\nconst _pickDeepPathsEliminateItemPredicate = (paths, item) => {\n return R.either(\n R.compose(R.equals(0), R.length),\n pths => {\n return R.both(\n // Item is not an object\n () => R.complement(R.is)(Object, item),\n ps => R.any(R.compose(R.lt(0), R.length), ps)\n )(pths);\n }\n )(paths);\n};\n/**\n * Pick matching paths in a a structure. For instance pickDeepPaths(['a.b.c', 'a.0.1']) will pick only keys\n * c in {a: {b: c: ...}}} and 'y' in {a: [['x', 'y']]}.\n * Use * in the path to capture all array items or keys, e.g. ['a.*.c./1|3/']\n * to get all items 0 or 3 of c that is in all items of a, whether a is an object or array\n */\nexport const pickDeepPaths = R.curry((pathSet, obj) => R.cond([\n // Arrays\n [o => Array.isArray(o),\n list => {\n // Recurse on each array item that doesn't match the paths. We pass the key without the index\n // We pass the key without the index\n // If any path matches the path to the value we return the item and the matching paths\n const survivingItemsEachWithRemainingPaths = compact(R.addIndex(R.map)(\n (item, index) => {\n return _calculateRemainingPaths(_pickDeepPathsEliminateItemPredicate, pathSet, item, index);\n },\n list\n ));\n return R.map(\n R.ifElse(\n // If the only paths are now empty we have a match with the items path and keep the item.\n // Otherwise we pick recursively\n ({paths}) => R.all(R.compose(R.equals(0), R.length), paths),\n ({item}) => item,\n ({item, paths}) => pickDeepPaths(paths, item)\n ),\n survivingItemsEachWithRemainingPaths\n );\n }\n ],\n // Primitives never match because we'd only get here if we have pathSets remaining and no path can match a primitive\n [R.complement(isObject),\n () => {\n throw new Error('pickDeepPaths encountered a value that is not an object or array at the top level. This should never happens and suggests a bug in this function');\n }\n ],\n // Objects\n [R.T,\n o => {\n // Recurse on each array item that doesn't match the paths. We pass the key without the index\n // If any path matches the path to the value we return the value and the matching paths\n // If no path matches it we know the value shouldn't be picked so we don't recurse on it below\n const survivingItems = compact(R.mapObjIndexed(\n (item, key) => _calculateRemainingPaths(_pickDeepPathsEliminateItemPredicate, pathSet, item, key),\n o\n ));\n return R.map(\n R.ifElse(\n // If the only path is now empty we have a match with the items path and keep the item.\n // Otherwise we pick recursively\n ({item, paths}) => R.all(R.compose(R.equals(0), R.length), paths),\n R.prop('item'),\n ({item, paths}) => pickDeepPaths(paths, item)\n ),\n survivingItems\n );\n }\n ]\n ]\n )(obj)\n);\n\n/**\n * splitAt that gives the split point item to both sides of the split\n * @param {Number} index The index\n * @param {String|[Object]} list A string or list\n * @returns {[Object]} A pair of results\n */\nexport const splitAtInclusive = (index, list) => {\n const pair = R.splitAt(index, list);\n return [\n R.concat(R.head(pair), R.slice(0, 1, R.last(pair))),\n R.last(pair)\n ];\n};\n\n/**\n * Whether the objects are equal at the given propStr. Null objects are never equal\n * @param {String} stringPath Path of props separated by dots\n * @param {Object|Array} obj1 The object to compare to obj2 at the propStr\n * @param {Object|Array} obj2 The object to compare to obj1 at the propStr\n * @returns {Boolean} True or false\n */\nexport const eqStrPath = R.curry((stringPath, obj1, obj2) => {\n return R.apply(R.equals, R.map(strPathOr(null, stringPath), [obj1, obj2]));\n});\n\n/**\n * Whether the objects are equal at the given strPaths. Null objects are never equal\n * @param [{String}] strPaths Paths of props separated by dots\n * @param {Object|Array} obj1 The object to compare to obj2 at the propStr\n * @param {Object|Array} obj2 The object to compare to obj1 at the propStr\n * @returns {Boolean} True or false\n */\nexport const eqStrPathsAll = R.curry(\n (strPaths, obj1, obj2) => R.all(prop => eqStrPath(prop, obj1, obj2), strPaths)\n);\n"],"names":["regexToMatchARegex","isObject","obj","R","Object","orEmpty","entity","compact","compactEmpty","emptyToNull","compactJoin","connector","items","mapProp","prop","objs","mapPropValueAsIndex","Array","isArray","removeDuplicateObjectsByProp","list","idOrIdFromObj","objOrId","mergeDeep","l","r","Function","concat","mergeDeepAll","mergeDeepWith","fn","left","right","mergeDeepWithConcatArrays","mergeDeepWithRecurseArrayItems","a","b","mergeDeepWithRecurseArrayItemsByRight","itemMatchBy","_mergeDeepWithRecurseArrayItemsByRight","mergeDeepWithRecurseArrayItemsByAndMergeObjectByRight","mergeObject","key","lItemsByValue","li","rItem","i","rItemValue","hasMatchingLItem","kk","ll","rr","applyDeep","mergeDeepWithRecurseArrayItemsAndMapObjs","applyObj","_mergeDeepWithRecurseArrayItemsAndMapObjs","applyDeepAndMapObjs","lr","v","vv","res","x","_","k","capitalize","str","lowercase","camelCase","replace","toUpperCase","mergeAllWithKey","head","rest","reqPath","path","maybe","isNothing","Result","resolved","segments","segment","value","Rm","reqStrPath","props","strPath","strPathOr","defaultValue","result","strPathOrNullOk","hasStrPath","reqPathPropEq","val","map","mapKeys","pairs","pair","mapKeysForLens","lens","mapDefault","keyName","module","mapDefaultAndPrefixOthers","defaultName","prefix","mapKeysAndValues","f","container","mapObjToValues","filterWithKeys","pred","transformKeys","func","renameKey","from","to","target","duplicateKey","toKeys","toKey","toArrayIfNot","arrayOrScalar","of","moveToKeys","findOne","predicate","all","matching","onlyOne","onlyOneValue","mapToObjValue","findOneValueByParams","params","findByParams","findMapped","alwaysFunc","maybeFunc","filterObjToValues","chainObjToValues","fromPairsDeep","deepPairs","first","String","replaceValuesAtDepth","n","replaceStringOrFunc","o","oo","replaceValuesAtDepthAndStringify","replaceString","JSON","stringify","replaceValuesWithCountAtDepth","c","replaceValuesWithCountAtDepthAndStringify","flattenObj","_flattenObj","flattenObjUntil","config","keys","ooo","keyStringToLensPath","keyString","NaN","parseInt","unflattenObjNoArrays","_unflattenObj","allowArrays","unflattenObj","accum","itemKeyPath","toString","itemLensPath","constainerKeyPath","Number","overDeep","omitDeep","omit_keys","omitDeepBy","_calculateRemainingPaths","eliminateItemPredicate","paths","item","keyOrIndex","tailPathsStillMatchingItemPath","aKeyOrIndex","possibleRegex","provenRegex","args","RegExp","test","tailPaths","p","_omitDeepPathsEliminateItemPredicate","omitDeepPaths","pathSet","survivingItems","index","primitive","_pickDeepPathsEliminateItemPredicate","pths","ps","pickDeepPaths","survivingItemsEachWithRemainingPaths","Error","splitAtInclusive","eqStrPath","stringPath","obj1","obj2","eqStrPathsAll","strPaths"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAMA,kBAAkB,GAAG,+GAA3B;AAGA;;;;;;;IAMaC,QAAQ,GAAG,SAAXA,QAAW,CAAAC,GAAG,EAAI;AAC7B,SAAOC,IAAA,CAAKC,MAAL,EAAaF,GAAb,KAAsBA,GAAG,KAAK,IAAR,IAAgB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