From 8af364677b7484a6f8c8a0059170c0125d59d706 Mon Sep 17 00:00:00 2001 From: "kai.t" Date: Thu, 16 Nov 2023 11:19:41 +0700 Subject: [PATCH] first commit --- .gitignore | 1 + background.js | 12 + background/image_editor.js | 35 +++ background/remove_bg.js | 41 +++ background_api.js | 71 ++++++ background_utils.js | 35 +++ contents/image_editor.js | 85 ++++++ contents/remove_bg.js | 70 +++++ icon/128.png | Bin 0 -> 2072 bytes icon/32.png | Bin 0 -> 527 bytes icon/48.png | Bin 0 -> 690 bytes libs/lodash/.internal/Hash.js | 88 +++++++ libs/lodash/.internal/ListCache.js | 103 ++++++++ libs/lodash/.internal/MapCache.js | 120 +++++++++ libs/lodash/.internal/SetCache.js | 52 ++++ libs/lodash/.internal/Stack.js | 93 +++++++ libs/lodash/.internal/addMapEntry.js | 15 ++ libs/lodash/.internal/addSetEntry.js | 15 ++ libs/lodash/.internal/arrayEach.js | 21 ++ libs/lodash/.internal/arrayEachRight.js | 20 ++ libs/lodash/.internal/arrayIncludes.js | 17 ++ libs/lodash/.internal/arrayIncludesWith.js | 23 ++ libs/lodash/.internal/arrayLikeKeys.js | 43 ++++ libs/lodash/.internal/arrayReduce.js | 25 ++ libs/lodash/.internal/arrayReduceRight.js | 23 ++ libs/lodash/.internal/asciiSize.js | 12 + libs/lodash/.internal/asciiToArray.js | 12 + libs/lodash/.internal/assignMergeValue.js | 20 ++ libs/lodash/.internal/assignValue.js | 27 ++ libs/lodash/.internal/assocIndexOf.js | 21 ++ libs/lodash/.internal/baseAssignValue.js | 23 ++ libs/lodash/.internal/baseAt.js | 23 ++ libs/lodash/.internal/baseClone.js | 241 ++++++++++++++++++ libs/lodash/.internal/baseConforms.js | 16 ++ libs/lodash/.internal/baseConformsTo.js | 27 ++ libs/lodash/.internal/baseDifference.js | 63 +++++ libs/lodash/.internal/baseEach.js | 31 +++ libs/lodash/.internal/baseEachRight.js | 30 +++ libs/lodash/.internal/baseFindIndex.js | 23 ++ libs/lodash/.internal/baseFindKey.js | 22 ++ libs/lodash/.internal/baseFlatten.js | 37 +++ libs/lodash/.internal/baseFor.js | 27 ++ libs/lodash/.internal/baseForOwn.js | 16 ++ libs/lodash/.internal/baseForOwnRight.js | 16 ++ libs/lodash/.internal/baseForRight.js | 25 ++ libs/lodash/.internal/baseGet.js | 24 ++ libs/lodash/.internal/baseInRange.js | 14 + libs/lodash/.internal/baseIndexOf.js | 20 ++ libs/lodash/.internal/baseIndexOfWith.js | 23 ++ libs/lodash/.internal/baseIntersection.js | 72 ++++++ libs/lodash/.internal/baseIsEqual.js | 28 ++ libs/lodash/.internal/baseIsEqualDeep.js | 79 ++++++ libs/lodash/.internal/baseIsMatch.js | 64 +++++ libs/lodash/.internal/baseIsNaN.js | 12 + libs/lodash/.internal/baseMatches.js | 20 ++ libs/lodash/.internal/baseMatchesProperty.js | 33 +++ libs/lodash/.internal/baseMerge.js | 41 +++ libs/lodash/.internal/baseMergeDeep.js | 91 +++++++ libs/lodash/.internal/baseOrderBy.js | 49 ++++ libs/lodash/.internal/basePick.js | 17 ++ libs/lodash/.internal/basePickBy.js | 29 +++ libs/lodash/.internal/baseProperty.js | 12 + libs/lodash/.internal/basePropertyDeep.js | 14 + libs/lodash/.internal/basePropertyOf.js | 12 + libs/lodash/.internal/basePullAll.js | 44 ++++ libs/lodash/.internal/basePullAt.js | 32 +++ libs/lodash/.internal/baseRange.js | 24 ++ libs/lodash/.internal/baseReduce.js | 23 ++ libs/lodash/.internal/baseSet.js | 48 ++++ libs/lodash/.internal/baseSortBy.js | 21 ++ libs/lodash/.internal/baseSortedIndex.js | 40 +++ libs/lodash/.internal/baseSortedIndexBy.js | 65 +++++ libs/lodash/.internal/baseSortedUniq.js | 29 +++ libs/lodash/.internal/baseSum.js | 21 ++ libs/lodash/.internal/baseToNumber.js | 24 ++ libs/lodash/.internal/baseToString.js | 33 +++ libs/lodash/.internal/baseUniq.js | 73 ++++++ libs/lodash/.internal/baseUnset.js | 20 ++ libs/lodash/.internal/baseUpdate.js | 18 ++ libs/lodash/.internal/baseValues.js | 15 ++ libs/lodash/.internal/baseWhile.js | 25 ++ libs/lodash/.internal/baseXor.js | 36 +++ libs/lodash/.internal/baseZipObject.js | 23 ++ libs/lodash/.internal/cacheHas.js | 13 + libs/lodash/.internal/castArrayLikeObject.js | 14 + libs/lodash/.internal/castPath.js | 19 ++ libs/lodash/.internal/castSlice.js | 18 ++ libs/lodash/.internal/charsEndIndex.js | 19 ++ libs/lodash/.internal/charsStartIndex.js | 20 ++ libs/lodash/.internal/cloneArrayBuffer.js | 14 + libs/lodash/.internal/cloneBuffer.js | 34 +++ libs/lodash/.internal/cloneDataView.js | 16 ++ libs/lodash/.internal/cloneRegExp.js | 17 ++ libs/lodash/.internal/cloneSymbol.js | 15 ++ libs/lodash/.internal/cloneTypedArray.js | 16 ++ libs/lodash/.internal/compareAscending.js | 45 ++++ libs/lodash/.internal/compareMultiple.js | 45 ++++ libs/lodash/.internal/composeArgs.js | 38 +++ libs/lodash/.internal/composeArgsRight.js | 39 +++ libs/lodash/.internal/copyArray.js | 20 ++ libs/lodash/.internal/copyObject.js | 35 +++ libs/lodash/.internal/copySymbols.js | 16 ++ libs/lodash/.internal/copySymbolsIn.js | 16 ++ libs/lodash/.internal/createAssigner.js | 36 +++ libs/lodash/.internal/createCaseFirst.js | 34 +++ libs/lodash/.internal/createMathOperation.js | 35 +++ libs/lodash/.internal/createPadding.js | 30 +++ libs/lodash/.internal/createRange.js | 26 ++ libs/lodash/.internal/createRound.js | 25 ++ libs/lodash/.internal/createSet.js | 17 ++ libs/lodash/.internal/customDefaultsMerge.js | 28 ++ libs/lodash/.internal/deburrLetter.js | 71 ++++++ libs/lodash/.internal/equalArrays.js | 84 ++++++ libs/lodash/.internal/equalByTag.js | 109 ++++++++ libs/lodash/.internal/equalObjects.js | 88 +++++++ libs/lodash/.internal/freeGlobal.js | 4 + libs/lodash/.internal/getAllKeys.js | 19 ++ libs/lodash/.internal/getAllKeysIn.js | 21 ++ libs/lodash/.internal/getHolder.js | 13 + libs/lodash/.internal/getMatchData.js | 23 ++ libs/lodash/.internal/getSymbols.js | 22 ++ libs/lodash/.internal/getSymbolsIn.js | 19 ++ libs/lodash/.internal/getTag.js | 17 ++ libs/lodash/.internal/hasUnicode.js | 28 ++ libs/lodash/.internal/initCloneObject.js | 16 ++ libs/lodash/.internal/isFlattenable.js | 18 ++ libs/lodash/.internal/isIndex.js | 25 ++ libs/lodash/.internal/isIterateeCall.js | 31 +++ libs/lodash/.internal/isKey.js | 27 ++ libs/lodash/.internal/isPrototype.js | 18 ++ libs/lodash/.internal/isStrictComparable.js | 15 ++ libs/lodash/.internal/iteratorToArray.js | 18 ++ libs/lodash/.internal/mapToArray.js | 18 ++ .../.internal/matchesStrictComparable.js | 20 ++ libs/lodash/.internal/memoizeCapped.js | 26 ++ libs/lodash/.internal/metaMap.js | 1 + libs/lodash/.internal/nodeTypes.js | 28 ++ libs/lodash/.internal/parent.js | 16 ++ libs/lodash/.internal/reEscape.js | 4 + libs/lodash/.internal/reEvaluate.js | 4 + libs/lodash/.internal/reInterpolate.js | 4 + libs/lodash/.internal/root.js | 13 + libs/lodash/.internal/setToArray.js | 18 ++ libs/lodash/.internal/setToPairs.js | 18 ++ libs/lodash/.internal/setToString.js | 18 ++ libs/lodash/.internal/strictIndexOf.js | 23 ++ libs/lodash/.internal/strictLastIndexOf.js | 21 ++ libs/lodash/.internal/stringSize.js | 16 ++ libs/lodash/.internal/stringToArray.js | 18 ++ libs/lodash/.internal/stringToPath.js | 44 ++++ libs/lodash/.internal/toKey.js | 21 ++ libs/lodash/.internal/unicodeSize.js | 47 ++++ libs/lodash/.internal/unicodeToArray.js | 43 ++++ libs/lodash/.internal/unicodeWords.js | 70 +++++ libs/lodash/LICENSE | 49 ++++ libs/lodash/README.md | 80 ++++++ libs/lodash/SECURITY.md | 34 +++ libs/lodash/add.js | 18 ++ libs/lodash/after.js | 30 +++ libs/lodash/at.js | 21 ++ libs/lodash/attempt.js | 30 +++ libs/lodash/before.js | 32 +++ libs/lodash/camelCase.js | 31 +++ libs/lodash/capitalize.js | 20 ++ libs/lodash/castArray.js | 41 +++ libs/lodash/ceil.js | 24 ++ libs/lodash/chunk.js | 38 +++ libs/lodash/clamp.js | 31 +++ libs/lodash/clone.js | 35 +++ libs/lodash/cloneDeep.js | 28 ++ libs/lodash/cloneDeepWith.js | 40 +++ libs/lodash/cloneWith.js | 40 +++ libs/lodash/compact.js | 30 +++ libs/lodash/cond.js | 49 ++++ libs/lodash/conforms.js | 33 +++ libs/lodash/conformsTo.js | 30 +++ libs/lodash/countBy.js | 41 +++ libs/lodash/create.js | 39 +++ libs/lodash/debounce.js | 213 ++++++++++++++++ libs/lodash/deburr.js | 43 ++++ libs/lodash/defaultTo.js | 23 ++ libs/lodash/defaultToAny.js | 32 +++ libs/lodash/defaults.js | 45 ++++ libs/lodash/defaultsDeep.js | 26 ++ libs/lodash/defer.js | 22 ++ libs/lodash/delay.js | 23 ++ libs/lodash/difference.js | 30 +++ libs/lodash/differenceBy.js | 36 +++ libs/lodash/differenceWith.js | 37 +++ libs/lodash/divide.js | 18 ++ libs/lodash/drop.js | 33 +++ libs/lodash/dropRight.js | 32 +++ libs/lodash/dropRightWhile.js | 30 +++ libs/lodash/dropWhile.js | 30 +++ libs/lodash/each.js | 1 + libs/lodash/eachRight.js | 1 + libs/lodash/endsWith.js | 37 +++ libs/lodash/eq.js | 35 +++ libs/lodash/eqDeep.js | 33 +++ libs/lodash/escape.js | 47 ++++ libs/lodash/escapeRegExp.js | 28 ++ libs/lodash/every.js | 34 +++ libs/lodash/everyValue.js | 34 +++ libs/lodash/filter.js | 39 +++ libs/lodash/filterObject.js | 34 +++ libs/lodash/findKey.js | 38 +++ libs/lodash/findLast.js | 32 +++ libs/lodash/findLastIndex.js | 41 +++ libs/lodash/findLastKey.js | 30 +++ libs/lodash/first.js | 1 + libs/lodash/flatMap.js | 28 ++ libs/lodash/flatMapDeep.js | 30 +++ libs/lodash/flatMapDepth.js | 29 +++ libs/lodash/flatten.js | 21 ++ libs/lodash/flattenDeep.js | 24 ++ libs/lodash/flattenDepth.js | 31 +++ libs/lodash/flip.js | 25 ++ libs/lodash/floor.js | 24 ++ libs/lodash/flow.js | 41 +++ libs/lodash/flowRight.js | 28 ++ libs/lodash/forEach.js | 33 +++ libs/lodash/forEachRight.js | 25 ++ libs/lodash/forOwn.js | 31 +++ libs/lodash/forOwnRight.js | 36 +++ libs/lodash/fromEntries.js | 25 ++ libs/lodash/functions.js | 29 +++ libs/lodash/get.js | 32 +++ libs/lodash/groupBy.js | 36 +++ libs/lodash/gt.js | 30 +++ libs/lodash/gte.js | 30 +++ libs/lodash/has.js | 28 ++ libs/lodash/hasIn.js | 24 ++ libs/lodash/hasPath.js | 53 ++++ libs/lodash/hasPathIn.js | 50 ++++ libs/lodash/head.js | 24 ++ libs/lodash/inRange.js | 47 ++++ libs/lodash/indexOf.js | 37 +++ libs/lodash/initial.js | 20 ++ libs/lodash/intersection.js | 27 ++ libs/lodash/intersectionBy.js | 37 +++ libs/lodash/intersectionWith.js | 38 +++ libs/lodash/invert.js | 31 +++ libs/lodash/invertBy.js | 36 +++ libs/lodash/invoke.js | 29 +++ libs/lodash/invokeMap.js | 37 +++ libs/lodash/isArguments.js | 23 ++ libs/lodash/isArrayBuffer.js | 27 ++ libs/lodash/isArrayLike.js | 30 +++ libs/lodash/isArrayLikeObject.js | 31 +++ libs/lodash/isBoolean.js | 24 ++ libs/lodash/isBuffer.js | 35 +++ libs/lodash/isDate.js | 27 ++ libs/lodash/isElement.js | 23 ++ libs/lodash/isEmpty.js | 69 +++++ libs/lodash/isEqualWith.js | 39 +++ libs/lodash/isError.js | 30 +++ libs/lodash/isFunction.js | 32 +++ libs/lodash/isLength.js | 33 +++ libs/lodash/isMap.js | 27 ++ libs/lodash/isMatch.js | 34 +++ libs/lodash/isMatchWith.js | 39 +++ libs/lodash/isNative.js | 36 +++ libs/lodash/isNil.js | 23 ++ libs/lodash/isNull.js | 20 ++ libs/lodash/isNumber.js | 34 +++ libs/lodash/isObject.js | 29 +++ libs/lodash/isObjectLike.js | 27 ++ libs/lodash/isPlainObject.js | 44 ++++ libs/lodash/isRegExp.js | 27 ++ libs/lodash/isSet.js | 27 ++ libs/lodash/isString.js | 23 ++ libs/lodash/isSymbol.js | 23 ++ libs/lodash/isTypedArray.js | 30 +++ libs/lodash/isUndefined.js | 20 ++ libs/lodash/isWeakMap.js | 23 ++ libs/lodash/isWeakSet.js | 23 ++ libs/lodash/kebabCase.js | 30 +++ libs/lodash/keyBy.js | 32 +++ libs/lodash/keys.js | 37 +++ libs/lodash/keysIn.js | 32 +++ libs/lodash/last.js | 18 ++ libs/lodash/lastIndexOf.js | 40 +++ libs/lodash/lowerCase.js | 31 +++ libs/lodash/lowerFirst.js | 20 ++ libs/lodash/lt.js | 30 +++ libs/lodash/lte.js | 30 +++ libs/lodash/map.js | 30 +++ libs/lodash/mapKey.js | 31 +++ libs/lodash/mapObject.js | 29 +++ libs/lodash/mapValue.js | 33 +++ libs/lodash/matches.js | 37 +++ libs/lodash/matchesProperty.js | 35 +++ libs/lodash/maxBy.js | 40 +++ libs/lodash/mean.js | 19 ++ libs/lodash/meanBy.js | 28 ++ libs/lodash/memoize.js | 64 +++++ libs/lodash/merge.js | 37 +++ libs/lodash/mergeWith.js | 37 +++ libs/lodash/method.js | 29 +++ libs/lodash/methodOf.js | 28 ++ libs/lodash/minBy.js | 40 +++ libs/lodash/multiply.js | 18 ++ libs/lodash/negate.js | 28 ++ libs/lodash/nth.js | 31 +++ libs/lodash/nthArg.js | 25 ++ libs/lodash/once.js | 23 ++ libs/lodash/orderBy.js | 51 ++++ libs/lodash/over.js | 25 ++ libs/lodash/overArgs.js | 41 +++ libs/lodash/overEvery.js | 31 +++ libs/lodash/overSome.js | 31 +++ libs/lodash/pad.js | 38 +++ libs/lodash/padEnd.js | 32 +++ libs/lodash/padStart.js | 32 +++ libs/lodash/parseInt.js | 36 +++ libs/lodash/partition.js | 32 +++ libs/lodash/pick.js | 22 ++ libs/lodash/pickBy.js | 29 +++ libs/lodash/property.js | 30 +++ libs/lodash/propertyOf.js | 26 ++ libs/lodash/pull.js | 29 +++ libs/lodash/pullAll.js | 28 ++ libs/lodash/pullAllBy.js | 31 +++ libs/lodash/pullAllWith.js | 31 +++ libs/lodash/pullAt.js | 38 +++ libs/lodash/random.js | 73 ++++++ libs/lodash/range.js | 44 ++++ libs/lodash/rangeRight.js | 39 +++ libs/lodash/reduce.js | 44 ++++ libs/lodash/reduceRight.js | 29 +++ libs/lodash/reject.js | 30 +++ libs/lodash/remove.js | 48 ++++ libs/lodash/repeat.js | 40 +++ libs/lodash/replace.js | 24 ++ libs/lodash/result.js | 53 ++++ libs/lodash/round.js | 24 ++ libs/lodash/sample.js | 18 ++ libs/lodash/sampleSize.js | 40 +++ libs/lodash/set.js | 34 +++ libs/lodash/setWith.js | 30 +++ libs/lodash/shuffle.js | 33 +++ libs/lodash/size.js | 43 ++++ libs/lodash/slice.js | 47 ++++ libs/lodash/snakeCase.js | 33 +++ libs/lodash/some.js | 29 +++ libs/lodash/someValue.js | 29 +++ libs/lodash/sortedIndex.js | 22 ++ libs/lodash/sortedIndexBy.js | 26 ++ libs/lodash/sortedIndexOf.js | 29 +++ libs/lodash/sortedLastIndex.js | 23 ++ libs/lodash/sortedLastIndexBy.js | 26 ++ libs/lodash/sortedLastIndexOf.js | 29 +++ libs/lodash/sortedUniq.js | 24 ++ libs/lodash/sortedUniqBy.js | 23 ++ libs/lodash/split.js | 42 +++ libs/lodash/startCase.js | 30 +++ libs/lodash/startsWith.js | 36 +++ libs/lodash/subtract.js | 18 ++ libs/lodash/sum.js | 21 ++ libs/lodash/sumBy.js | 26 ++ libs/lodash/tail.js | 22 ++ libs/lodash/take.js | 32 +++ libs/lodash/takeRight.js | 34 +++ libs/lodash/takeRightWhile.js | 30 +++ libs/lodash/takeWhile.js | 30 +++ libs/lodash/throttle.js | 70 +++++ libs/lodash/times.js | 42 +++ libs/lodash/toArray.js | 55 ++++ libs/lodash/toFinite.js | 40 +++ libs/lodash/toInteger.js | 35 +++ libs/lodash/toLength.js | 45 ++++ libs/lodash/toNumber.js | 65 +++++ libs/lodash/toPath.js | 29 +++ libs/lodash/toPlainObject.js | 32 +++ libs/lodash/toSafeInteger.js | 42 +++ libs/lodash/toString.js | 44 ++++ libs/lodash/transform.js | 59 +++++ libs/lodash/trim.js | 38 +++ libs/lodash/trimEnd.js | 36 +++ libs/lodash/trimStart.js | 36 +++ libs/lodash/truncate.js | 113 ++++++++ libs/lodash/unescape.js | 38 +++ libs/lodash/union.js | 24 ++ libs/lodash/unionBy.js | 32 +++ libs/lodash/unionWith.js | 32 +++ libs/lodash/uniq.js | 26 ++ libs/lodash/uniqBy.js | 27 ++ libs/lodash/uniqWith.js | 29 +++ libs/lodash/uniqueId.js | 33 +++ libs/lodash/unset.js | 33 +++ libs/lodash/unzip.js | 43 ++++ libs/lodash/unzipWith.js | 31 +++ libs/lodash/update.js | 32 +++ libs/lodash/updateWith.js | 30 +++ libs/lodash/upperCase.js | 29 +++ libs/lodash/upperFirst.js | 21 ++ libs/lodash/values.js | 33 +++ libs/lodash/without.js | 26 ++ libs/lodash/words.js | 38 +++ libs/lodash/xor.js | 24 ++ libs/lodash/xorBy.js | 31 +++ libs/lodash/xorWith.js | 31 +++ libs/lodash/zip.js | 22 ++ libs/lodash/zipObject.js | 23 ++ libs/lodash/zipObjectDeep.js | 22 ++ libs/lodash/zipWith.js | 27 ++ manifest.json | 61 +++++ popup.css | 130 ++++++++++ popup.html | 1 + popup.js | 0 410 files changed, 13457 insertions(+) create mode 100644 .gitignore create mode 100644 background.js create mode 100644 background/image_editor.js create mode 100644 background/remove_bg.js create mode 100644 background_api.js create mode 100644 background_utils.js create mode 100644 contents/image_editor.js create mode 100644 contents/remove_bg.js create mode 100644 icon/128.png create mode 100644 icon/32.png create mode 100644 icon/48.png create mode 100644 libs/lodash/.internal/Hash.js create mode 100644 libs/lodash/.internal/ListCache.js create mode 100644 libs/lodash/.internal/MapCache.js create mode 100644 libs/lodash/.internal/SetCache.js create mode 100644 libs/lodash/.internal/Stack.js create mode 100644 libs/lodash/.internal/addMapEntry.js create mode 100644 libs/lodash/.internal/addSetEntry.js create mode 100644 libs/lodash/.internal/arrayEach.js create mode 100644 libs/lodash/.internal/arrayEachRight.js create mode 100644 libs/lodash/.internal/arrayIncludes.js create mode 100644 libs/lodash/.internal/arrayIncludesWith.js create mode 100644 libs/lodash/.internal/arrayLikeKeys.js create mode 100644 libs/lodash/.internal/arrayReduce.js create mode 100644 libs/lodash/.internal/arrayReduceRight.js create mode 100644 libs/lodash/.internal/asciiSize.js create mode 100644 libs/lodash/.internal/asciiToArray.js create mode 100644 libs/lodash/.internal/assignMergeValue.js create mode 100644 libs/lodash/.internal/assignValue.js create mode 100644 libs/lodash/.internal/assocIndexOf.js create mode 100644 libs/lodash/.internal/baseAssignValue.js create mode 100644 libs/lodash/.internal/baseAt.js create mode 100644 libs/lodash/.internal/baseClone.js create mode 100644 libs/lodash/.internal/baseConforms.js create mode 100644 libs/lodash/.internal/baseConformsTo.js create mode 100644 libs/lodash/.internal/baseDifference.js create mode 100644 libs/lodash/.internal/baseEach.js create mode 100644 libs/lodash/.internal/baseEachRight.js create mode 100644 libs/lodash/.internal/baseFindIndex.js create mode 100644 libs/lodash/.internal/baseFindKey.js create mode 100644 libs/lodash/.internal/baseFlatten.js create mode 100644 libs/lodash/.internal/baseFor.js create mode 100644 libs/lodash/.internal/baseForOwn.js create mode 100644 libs/lodash/.internal/baseForOwnRight.js create mode 100644 libs/lodash/.internal/baseForRight.js create mode 100644 libs/lodash/.internal/baseGet.js create mode 100644 libs/lodash/.internal/baseInRange.js create mode 100644 libs/lodash/.internal/baseIndexOf.js create mode 100644 libs/lodash/.internal/baseIndexOfWith.js create mode 100644 libs/lodash/.internal/baseIntersection.js create mode 100644 libs/lodash/.internal/baseIsEqual.js create mode 100644 libs/lodash/.internal/baseIsEqualDeep.js create mode 100644 libs/lodash/.internal/baseIsMatch.js create mode 100644 libs/lodash/.internal/baseIsNaN.js create mode 100644 libs/lodash/.internal/baseMatches.js create mode 100644 libs/lodash/.internal/baseMatchesProperty.js create mode 100644 libs/lodash/.internal/baseMerge.js create mode 100644 libs/lodash/.internal/baseMergeDeep.js create mode 100644 libs/lodash/.internal/baseOrderBy.js create mode 100644 libs/lodash/.internal/basePick.js create mode 100644 libs/lodash/.internal/basePickBy.js create mode 100644 libs/lodash/.internal/baseProperty.js create mode 100644 libs/lodash/.internal/basePropertyDeep.js create mode 100644 libs/lodash/.internal/basePropertyOf.js create mode 100644 libs/lodash/.internal/basePullAll.js create mode 100644 libs/lodash/.internal/basePullAt.js create mode 100644 libs/lodash/.internal/baseRange.js create mode 100644 libs/lodash/.internal/baseReduce.js create mode 100644 libs/lodash/.internal/baseSet.js create mode 100644 libs/lodash/.internal/baseSortBy.js create mode 100644 libs/lodash/.internal/baseSortedIndex.js create mode 100644 libs/lodash/.internal/baseSortedIndexBy.js create mode 100644 libs/lodash/.internal/baseSortedUniq.js create mode 100644 libs/lodash/.internal/baseSum.js create mode 100644 libs/lodash/.internal/baseToNumber.js create mode 100644 libs/lodash/.internal/baseToString.js create mode 100644 libs/lodash/.internal/baseUniq.js create mode 100644 libs/lodash/.internal/baseUnset.js create mode 100644 libs/lodash/.internal/baseUpdate.js create mode 100644 libs/lodash/.internal/baseValues.js create mode 100644 libs/lodash/.internal/baseWhile.js create mode 100644 libs/lodash/.internal/baseXor.js create mode 100644 libs/lodash/.internal/baseZipObject.js create mode 100644 libs/lodash/.internal/cacheHas.js create mode 100644 libs/lodash/.internal/castArrayLikeObject.js create mode 100644 libs/lodash/.internal/castPath.js create mode 100644 libs/lodash/.internal/castSlice.js create mode 100644 libs/lodash/.internal/charsEndIndex.js create mode 100644 libs/lodash/.internal/charsStartIndex.js create mode 100644 libs/lodash/.internal/cloneArrayBuffer.js create mode 100644 libs/lodash/.internal/cloneBuffer.js create mode 100644 libs/lodash/.internal/cloneDataView.js create mode 100644 libs/lodash/.internal/cloneRegExp.js create mode 100644 libs/lodash/.internal/cloneSymbol.js create mode 100644 libs/lodash/.internal/cloneTypedArray.js create mode 100644 libs/lodash/.internal/compareAscending.js create mode 100644 libs/lodash/.internal/compareMultiple.js create mode 100644 libs/lodash/.internal/composeArgs.js create mode 100644 libs/lodash/.internal/composeArgsRight.js create mode 100644 libs/lodash/.internal/copyArray.js create mode 100644 libs/lodash/.internal/copyObject.js create mode 100644 libs/lodash/.internal/copySymbols.js create mode 100644 libs/lodash/.internal/copySymbolsIn.js create mode 100644 libs/lodash/.internal/createAssigner.js create mode 100644 libs/lodash/.internal/createCaseFirst.js create mode 100644 libs/lodash/.internal/createMathOperation.js create mode 100644 libs/lodash/.internal/createPadding.js create mode 100644 libs/lodash/.internal/createRange.js create mode 100644 libs/lodash/.internal/createRound.js create mode 100644 libs/lodash/.internal/createSet.js create mode 100644 libs/lodash/.internal/customDefaultsMerge.js create mode 100644 libs/lodash/.internal/deburrLetter.js create mode 100644 libs/lodash/.internal/equalArrays.js create mode 100644 libs/lodash/.internal/equalByTag.js create mode 100644 libs/lodash/.internal/equalObjects.js create mode 100644 libs/lodash/.internal/freeGlobal.js create mode 100644 libs/lodash/.internal/getAllKeys.js create mode 100644 libs/lodash/.internal/getAllKeysIn.js create mode 100644 libs/lodash/.internal/getHolder.js create mode 100644 libs/lodash/.internal/getMatchData.js create mode 100644 libs/lodash/.internal/getSymbols.js create mode 100644 libs/lodash/.internal/getSymbolsIn.js create mode 100644 libs/lodash/.internal/getTag.js create mode 100644 libs/lodash/.internal/hasUnicode.js create mode 100644 libs/lodash/.internal/initCloneObject.js create mode 100644 libs/lodash/.internal/isFlattenable.js create mode 100644 libs/lodash/.internal/isIndex.js create mode 100644 libs/lodash/.internal/isIterateeCall.js create mode 100644 libs/lodash/.internal/isKey.js create mode 100644 libs/lodash/.internal/isPrototype.js create mode 100644 libs/lodash/.internal/isStrictComparable.js create mode 100644 libs/lodash/.internal/iteratorToArray.js create mode 100644 libs/lodash/.internal/mapToArray.js create mode 100644 libs/lodash/.internal/matchesStrictComparable.js create mode 100644 libs/lodash/.internal/memoizeCapped.js create mode 100644 libs/lodash/.internal/metaMap.js create mode 100644 libs/lodash/.internal/nodeTypes.js create mode 100644 libs/lodash/.internal/parent.js create mode 100644 libs/lodash/.internal/reEscape.js create mode 100644 libs/lodash/.internal/reEvaluate.js create mode 100644 libs/lodash/.internal/reInterpolate.js create mode 100644 libs/lodash/.internal/root.js create mode 100644 libs/lodash/.internal/setToArray.js create mode 100644 libs/lodash/.internal/setToPairs.js create mode 100644 libs/lodash/.internal/setToString.js create mode 100644 libs/lodash/.internal/strictIndexOf.js create mode 100644 libs/lodash/.internal/strictLastIndexOf.js create mode 100644 libs/lodash/.internal/stringSize.js create mode 100644 libs/lodash/.internal/stringToArray.js create mode 100644 libs/lodash/.internal/stringToPath.js create mode 100644 libs/lodash/.internal/toKey.js create mode 100644 libs/lodash/.internal/unicodeSize.js create mode 100644 libs/lodash/.internal/unicodeToArray.js create mode 100644 libs/lodash/.internal/unicodeWords.js create mode 100644 libs/lodash/LICENSE create mode 100644 libs/lodash/README.md create mode 100644 libs/lodash/SECURITY.md create mode 100644 libs/lodash/add.js create mode 100644 libs/lodash/after.js create mode 100644 libs/lodash/at.js create mode 100644 libs/lodash/attempt.js create mode 100644 libs/lodash/before.js create mode 100644 libs/lodash/camelCase.js create mode 100644 libs/lodash/capitalize.js create mode 100644 libs/lodash/castArray.js create mode 100644 libs/lodash/ceil.js create mode 100644 libs/lodash/chunk.js create mode 100644 libs/lodash/clamp.js create mode 100644 libs/lodash/clone.js create mode 100644 libs/lodash/cloneDeep.js create mode 100644 libs/lodash/cloneDeepWith.js create mode 100644 libs/lodash/cloneWith.js create mode 100644 libs/lodash/compact.js create mode 100644 libs/lodash/cond.js create mode 100644 libs/lodash/conforms.js create mode 100644 libs/lodash/conformsTo.js create mode 100644 libs/lodash/countBy.js create mode 100644 libs/lodash/create.js create mode 100644 libs/lodash/debounce.js create mode 100644 libs/lodash/deburr.js create mode 100644 libs/lodash/defaultTo.js create mode 100644 libs/lodash/defaultToAny.js create mode 100644 libs/lodash/defaults.js create mode 100644 libs/lodash/defaultsDeep.js create mode 100644 libs/lodash/defer.js create mode 100644 libs/lodash/delay.js create mode 100644 libs/lodash/difference.js create mode 100644 libs/lodash/differenceBy.js create mode 100644 libs/lodash/differenceWith.js create mode 100644 libs/lodash/divide.js create mode 100644 libs/lodash/drop.js create mode 100644 libs/lodash/dropRight.js create mode 100644 libs/lodash/dropRightWhile.js create mode 100644 libs/lodash/dropWhile.js create mode 100644 libs/lodash/each.js create mode 100644 libs/lodash/eachRight.js create mode 100644 libs/lodash/endsWith.js create mode 100644 libs/lodash/eq.js create mode 100644 libs/lodash/eqDeep.js create mode 100644 libs/lodash/escape.js create mode 100644 libs/lodash/escapeRegExp.js create mode 100644 libs/lodash/every.js create mode 100644 libs/lodash/everyValue.js create mode 100644 libs/lodash/filter.js create mode 100644 libs/lodash/filterObject.js create mode 100644 libs/lodash/findKey.js create mode 100644 libs/lodash/findLast.js create mode 100644 libs/lodash/findLastIndex.js create mode 100644 libs/lodash/findLastKey.js create mode 100644 libs/lodash/first.js create mode 100644 libs/lodash/flatMap.js create mode 100644 libs/lodash/flatMapDeep.js create mode 100644 libs/lodash/flatMapDepth.js create mode 100644 libs/lodash/flatten.js create mode 100644 libs/lodash/flattenDeep.js create mode 100644 libs/lodash/flattenDepth.js create mode 100644 libs/lodash/flip.js create mode 100644 libs/lodash/floor.js create mode 100644 libs/lodash/flow.js create mode 100644 libs/lodash/flowRight.js create mode 100644 libs/lodash/forEach.js create mode 100644 libs/lodash/forEachRight.js create mode 100644 libs/lodash/forOwn.js create mode 100644 libs/lodash/forOwnRight.js create mode 100644 libs/lodash/fromEntries.js create mode 100644 libs/lodash/functions.js create mode 100644 libs/lodash/get.js create mode 100644 libs/lodash/groupBy.js create mode 100644 libs/lodash/gt.js create mode 100644 libs/lodash/gte.js create mode 100644 libs/lodash/has.js create mode 100644 libs/lodash/hasIn.js create mode 100644 libs/lodash/hasPath.js create mode 100644 libs/lodash/hasPathIn.js create mode 100644 libs/lodash/head.js create mode 100644 libs/lodash/inRange.js create mode 100644 libs/lodash/indexOf.js create mode 100644 libs/lodash/initial.js create mode 100644 libs/lodash/intersection.js create mode 100644 libs/lodash/intersectionBy.js create mode 100644 libs/lodash/intersectionWith.js create mode 100644 libs/lodash/invert.js create mode 100644 libs/lodash/invertBy.js create mode 100644 libs/lodash/invoke.js create mode 100644 libs/lodash/invokeMap.js create mode 100644 libs/lodash/isArguments.js create mode 100644 libs/lodash/isArrayBuffer.js create mode 100644 libs/lodash/isArrayLike.js create mode 100644 libs/lodash/isArrayLikeObject.js create mode 100644 libs/lodash/isBoolean.js create mode 100644 libs/lodash/isBuffer.js create mode 100644 libs/lodash/isDate.js create mode 100644 libs/lodash/isElement.js create mode 100644 libs/lodash/isEmpty.js create mode 100644 libs/lodash/isEqualWith.js create mode 100644 libs/lodash/isError.js create mode 100644 libs/lodash/isFunction.js create mode 100644 libs/lodash/isLength.js create mode 100644 libs/lodash/isMap.js create mode 100644 libs/lodash/isMatch.js create mode 100644 libs/lodash/isMatchWith.js create mode 100644 libs/lodash/isNative.js create mode 100644 libs/lodash/isNil.js create mode 100644 libs/lodash/isNull.js create mode 100644 libs/lodash/isNumber.js create mode 100644 libs/lodash/isObject.js create mode 100644 libs/lodash/isObjectLike.js create mode 100644 libs/lodash/isPlainObject.js create mode 100644 libs/lodash/isRegExp.js create mode 100644 libs/lodash/isSet.js create mode 100644 libs/lodash/isString.js create mode 100644 libs/lodash/isSymbol.js create mode 100644 libs/lodash/isTypedArray.js create mode 100644 libs/lodash/isUndefined.js create mode 100644 libs/lodash/isWeakMap.js create mode 100644 libs/lodash/isWeakSet.js create mode 100644 libs/lodash/kebabCase.js create mode 100644 libs/lodash/keyBy.js create mode 100644 libs/lodash/keys.js create mode 100644 libs/lodash/keysIn.js create mode 100644 libs/lodash/last.js create mode 100644 libs/lodash/lastIndexOf.js create mode 100644 libs/lodash/lowerCase.js create mode 100644 libs/lodash/lowerFirst.js create mode 100644 libs/lodash/lt.js create mode 100644 libs/lodash/lte.js create mode 100644 libs/lodash/map.js create mode 100644 libs/lodash/mapKey.js create mode 100644 libs/lodash/mapObject.js create mode 100644 libs/lodash/mapValue.js create mode 100644 libs/lodash/matches.js create mode 100644 libs/lodash/matchesProperty.js create mode 100644 libs/lodash/maxBy.js create mode 100644 libs/lodash/mean.js create mode 100644 libs/lodash/meanBy.js create mode 100644 libs/lodash/memoize.js create mode 100644 libs/lodash/merge.js create mode 100644 libs/lodash/mergeWith.js create mode 100644 libs/lodash/method.js create mode 100644 libs/lodash/methodOf.js create mode 100644 libs/lodash/minBy.js create mode 100644 libs/lodash/multiply.js create mode 100644 libs/lodash/negate.js create mode 100644 libs/lodash/nth.js create mode 100644 libs/lodash/nthArg.js create mode 100644 libs/lodash/once.js create mode 100644 libs/lodash/orderBy.js create mode 100644 libs/lodash/over.js create mode 100644 libs/lodash/overArgs.js create mode 100644 libs/lodash/overEvery.js create mode 100644 libs/lodash/overSome.js create mode 100644 libs/lodash/pad.js create mode 100644 libs/lodash/padEnd.js create mode 100644 libs/lodash/padStart.js create mode 100644 libs/lodash/parseInt.js create mode 100644 libs/lodash/partition.js create mode 100644 libs/lodash/pick.js create mode 100644 libs/lodash/pickBy.js create mode 100644 libs/lodash/property.js create mode 100644 libs/lodash/propertyOf.js create mode 100644 libs/lodash/pull.js create mode 100644 libs/lodash/pullAll.js create mode 100644 libs/lodash/pullAllBy.js create mode 100644 libs/lodash/pullAllWith.js create mode 100644 libs/lodash/pullAt.js create mode 100644 libs/lodash/random.js create mode 100644 libs/lodash/range.js create mode 100644 libs/lodash/rangeRight.js create mode 100644 libs/lodash/reduce.js create mode 100644 libs/lodash/reduceRight.js create mode 100644 libs/lodash/reject.js create mode 100644 libs/lodash/remove.js create mode 100644 libs/lodash/repeat.js create mode 100644 libs/lodash/replace.js create mode 100644 libs/lodash/result.js create mode 100644 libs/lodash/round.js create mode 100644 libs/lodash/sample.js create mode 100644 libs/lodash/sampleSize.js create mode 100644 libs/lodash/set.js create mode 100644 libs/lodash/setWith.js create mode 100644 libs/lodash/shuffle.js create mode 100644 libs/lodash/size.js create mode 100644 libs/lodash/slice.js create mode 100644 libs/lodash/snakeCase.js create mode 100644 libs/lodash/some.js create mode 100644 libs/lodash/someValue.js create mode 100644 libs/lodash/sortedIndex.js create mode 100644 libs/lodash/sortedIndexBy.js create mode 100644 libs/lodash/sortedIndexOf.js create mode 100644 libs/lodash/sortedLastIndex.js create mode 100644 libs/lodash/sortedLastIndexBy.js create mode 100644 libs/lodash/sortedLastIndexOf.js create mode 100644 libs/lodash/sortedUniq.js create mode 100644 libs/lodash/sortedUniqBy.js create mode 100644 libs/lodash/split.js create mode 100644 libs/lodash/startCase.js create mode 100644 libs/lodash/startsWith.js create mode 100644 libs/lodash/subtract.js create mode 100644 libs/lodash/sum.js create mode 100644 libs/lodash/sumBy.js create mode 100644 libs/lodash/tail.js create mode 100644 libs/lodash/take.js create mode 100644 libs/lodash/takeRight.js create mode 100644 libs/lodash/takeRightWhile.js create mode 100644 libs/lodash/takeWhile.js create mode 100644 libs/lodash/throttle.js create mode 100644 libs/lodash/times.js create mode 100644 libs/lodash/toArray.js create mode 100644 libs/lodash/toFinite.js create mode 100644 libs/lodash/toInteger.js create mode 100644 libs/lodash/toLength.js create mode 100644 libs/lodash/toNumber.js create mode 100644 libs/lodash/toPath.js create mode 100644 libs/lodash/toPlainObject.js create mode 100644 libs/lodash/toSafeInteger.js create mode 100644 libs/lodash/toString.js create mode 100644 libs/lodash/transform.js create mode 100644 libs/lodash/trim.js create mode 100644 libs/lodash/trimEnd.js create mode 100644 libs/lodash/trimStart.js create mode 100644 libs/lodash/truncate.js create mode 100644 libs/lodash/unescape.js create mode 100644 libs/lodash/union.js create mode 100644 libs/lodash/unionBy.js create mode 100644 libs/lodash/unionWith.js create mode 100644 libs/lodash/uniq.js create mode 100644 libs/lodash/uniqBy.js create mode 100644 libs/lodash/uniqWith.js create mode 100644 libs/lodash/uniqueId.js create mode 100644 libs/lodash/unset.js create mode 100644 libs/lodash/unzip.js create mode 100644 libs/lodash/unzipWith.js create mode 100644 libs/lodash/update.js create mode 100644 libs/lodash/updateWith.js create mode 100644 libs/lodash/upperCase.js create mode 100644 libs/lodash/upperFirst.js create mode 100644 libs/lodash/values.js create mode 100644 libs/lodash/without.js create mode 100644 libs/lodash/words.js create mode 100644 libs/lodash/xor.js create mode 100644 libs/lodash/xorBy.js create mode 100644 libs/lodash/xorWith.js create mode 100644 libs/lodash/zip.js create mode 100644 libs/lodash/zipObject.js create mode 100644 libs/lodash/zipObjectDeep.js create mode 100644 libs/lodash/zipWith.js create mode 100644 manifest.json create mode 100644 popup.css create mode 100644 popup.html create mode 100644 popup.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c4c4ffc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.zip diff --git a/background.js b/background.js new file mode 100644 index 0000000..0682aa4 --- /dev/null +++ b/background.js @@ -0,0 +1,12 @@ +import IMAGE_EDITOR from "./background/image_editor.js"; +import REMOVE_BG from "./background/remove_bg.js"; + +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { + if (request.action && request.action.includes("image_editor")) { + return IMAGE_EDITOR._init(request); + } + + if (request.action && request.action.includes("remove_bg")) { + return REMOVE_BG._init(request); + } +}) diff --git a/background/image_editor.js b/background/image_editor.js new file mode 100644 index 0000000..8e44ebc --- /dev/null +++ b/background/image_editor.js @@ -0,0 +1,35 @@ +import UTILS from "../background_utils.js"; +import camelCase from "../libs/lodash/camelCase.js"; + +let ROOT_KEY = "image_editor"; + +const IMAGE_EDITOR = { + _init: function (request) { + if (request.action === ROOT_KEY) { + // contructor + } + if (request.action === ROOT_KEY + "__has_capcha") { + chrome.action.setBadgeBackgroundColor({ color: "red" }); + chrome.action.setBadgeTextColor({ color: "white" }); + chrome.action.setBadgeText({ + text: "capcha", + }); + return this.sendMessageContent(request); + } + if (request.action === ROOT_KEY + "__save_image") { + return this.sendMessageContent(request) + } + if (request.action === ROOT_KEY + "__loading") { + return this.sendMessageContent(request) + } + }, + + sendMessageContent(request) { + UTILS.sendMessageToTabByURL("localhost", request); + UTILS.sendMessageToTabByURL("127.0.0.1", request); + UTILS.sendMessageToTabByURL("stage-editor.danielvu.com", request); + return true; + }, +}; + +export default IMAGE_EDITOR; diff --git a/background/remove_bg.js b/background/remove_bg.js new file mode 100644 index 0000000..f5363c8 --- /dev/null +++ b/background/remove_bg.js @@ -0,0 +1,41 @@ +import UTILS from "../background_utils.js"; +import camelCase from "../libs/lodash/camelCase.js"; +import IMAGE_EDITOR from "./image_editor.js"; + +let ROOT_KEY = "remove_bg"; + +export default { + _init: function (request) { + if (request.action === ROOT_KEY) { + // contructor + } + + if (request.action === ROOT_KEY + "__execute") { + this.sendMessageContent(request); + } + + if (request.action === ROOT_KEY + "__loading") { + + // to image editor to disable button + IMAGE_EDITOR.sendMessageContent({ + action: "image_editor__loading", + status: request.status, + }); + + // handle more on icon extension chrome + if (request.status) { + chrome.action.setBadgeText({ + text: "run", + }); + } else { + chrome.action.setBadgeText({ + text: null, + }); + } + } + }, + + sendMessageContent(request) { + return UTILS.sendMessageToTabByURL("remove.bg", request); + } +}; diff --git a/background_api.js b/background_api.js new file mode 100644 index 0000000..3c8b4f2 --- /dev/null +++ b/background_api.js @@ -0,0 +1,71 @@ +import CONFIG from "./config.js"; +import UTILS from "./background_utils.js"; + +const API = { + _get: async function (url, payload, token = null) { + try { + const headers = { + "Content-Type": "application/json", + } + + if (token) { + headers['Authorization'] = `Bearer ${token}` + } + + if (payload) { + url += '?' + new URLSearchParams(payload).toString(); + } + + const response = await fetch(url, { + headers + }); + + if (!response.ok) { + return false; + } else { + return await response.json(); + } + } catch (error) { + console.error("background_api: _get", error); + return false; + } + }, + + _post: async function (url, payload, token = null) { + try { + const headers = { + "Content-Type": "application/json", + } + + if (token) { + headers['Authorization'] = `Bearer ${token}` + } + + const response = await fetch(url, { + method: "POST", + body: JSON.stringify(payload), + headers + }); + + if (!response.ok) { + return false; + } else { + return await response.json(); + } + } catch (error) { + console.error("background_api: _post", error); + return false; + } + }, + + // TODO examle + example: async function(buyer_id) { + const env = await UTILS.getStorage('env') ?? 'dev' + const url = CONFIG._ENV[env][url] + return await this._get(url, null, { + request + }); + } +}; + +export default API; diff --git a/background_utils.js b/background_utils.js new file mode 100644 index 0000000..6fff359 --- /dev/null +++ b/background_utils.js @@ -0,0 +1,35 @@ +const UTILS = { + getStorage: async function (key) { + const storage = await chrome.storage.local.get(); + return storage[key] ?? null; + }, + + setStorage: async function (key, value) { + chrome.storage.local.set({ + [key]: value, + }); + return await this.getStorage(key); + }, + + sendMessageToFirstTab: function (data = {}) { + chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { + if (tabs.length) { + console.log({ + tabs, + }); + chrome.tabs.sendMessage(tabs[0].id, data); + } + }); + }, + sendMessageToTabByURL: function (url, data = {}) { + chrome.tabs.query({}, function (tabs) { + tabs + .filter((tab) => tab.url.includes(url)) + .forEach((tab) => { + chrome.tabs.sendMessage(tab.id, data); + }); + }); + }, +}; + +export default UTILS; diff --git a/contents/image_editor.js b/contents/image_editor.js new file mode 100644 index 0000000..d021048 --- /dev/null +++ b/contents/image_editor.js @@ -0,0 +1,85 @@ +if ( + ["127.0.0.1", "localhost", "stage-editor.danielvu.com"].includes( + location.hostname + ) +) { + let ROOT_KEY = "image_editor"; + let _SELECTOR_BUTTON_ID = "btn_trigger_remove_bg_"; + + // INIT + window.addEventListener("load", async () => { + cloneButton(); + }); + + // LISTEN event 🎧🎧🎧 + chrome.runtime.onMessage.addListener(function (res, sendResponse) { + if (res.action === ROOT_KEY + "__has_capcha") { + alert("Has capcha! Please select it on remove.bg and go home remove.bg, Thanks!"); + } + if (res.action === ROOT_KEY + "__save_image") { + const imageUrl = res.payload.url; + const filename = imageUrl.substring(imageUrl.lastIndexOf('/') + 1); + + fetch(imageUrl) + .then(responseImage => responseImage.blob()) + .then(blob => { + const file = new File([blob], filename, { type: blob.type }); + const fileList = new DataTransfer(); + const fileInput = document.querySelector(`#file_${res.payload.id}`) + fileList.items.add(file); + fileInput.files = fileList.files; + fileInput.dispatchEvent(new Event('change')); + + }) + .catch(error => { + console.error('Error fetching the image:', error); + }); + } + if (res.action === ROOT_KEY + "__loading") { + if (res.status) { + document + .querySelectorAll(`[id^=clone__${_SELECTOR_BUTTON_ID}]`) + ?.forEach((btn) => (btn.disabled = true)); + } else { + document + .querySelectorAll(`[id^=clone__${_SELECTOR_BUTTON_ID}]`) + ?.forEach((btn) => (btn.disabled = false)); + } + } + }); + + function cloneButton() { + window.$intervalCloneButton = setInterval(() => { + const selector = `[id^="${_SELECTOR_BUTTON_ID}"]:not([data-has_clone="true"])`; + document.querySelectorAll(selector)?.forEach((btn) => { + const cloneEl = btn.cloneNode(true); + cloneEl.id = "clone__" + cloneEl.id; + cloneEl.classList.value = cloneEl.classList.value.replace( + "purple", + "blue" + ); + cloneEl.querySelector(".q-btn__content ").textContent = + "remove.bg extension"; + cloneEl.addEventListener("click", function () { + handleClick(this); + }); + btn.after(cloneEl); + btn.setAttribute("data-has_clone", true); + }); + }, 1000); + } + + function handleClick(btn) { + const id = btn.getAttribute("data-id"); + const urlImg = btn.getAttribute("data-image"); + + btn.disabled = true; + chrome.runtime.sendMessage({ + action: "remove_bg__execute", + payload: { + id: parseInt(id), + url: urlImg, + }, + }); + } +} diff --git a/contents/remove_bg.js b/contents/remove_bg.js new file mode 100644 index 0000000..a58c6e4 --- /dev/null +++ b/contents/remove_bg.js @@ -0,0 +1,70 @@ +if (location.hostname === "www.remove.bg") { + let ROOT_KEY = "remove_bg"; + + window.addEventListener("load", async () => { + // do something after ready page + }); + + // LISTEN event 🎧🎧🎧 + chrome.runtime.onMessage.addListener(function (res, sendResponse) { + if (res.action === ROOT_KEY + "__execute") { + const idEl = "btn_" + new Date().getTime(); + document.body.innerHTML += ` + + `; + + // Wait to handle trigger "upload" button + setTimeout(() => { + document.querySelector(`#${idEl}`).click(); + document.querySelector(`#${idEl}`).remove(); + chrome.runtime.sendMessage({ + action: "remove_bg__loading", + status: true, + }); + }, 100); + + window.$getImageRm = setInterval(() => { + const imgEl = document.querySelector( + 'img[src*="removebg-preview.png"]' + ); + if (imgEl) { + clearInterval(window.$getImageRm); + chrome.runtime.sendMessage({ + action: "remove_bg__loading", + status: false, + }); + chrome.runtime.sendMessage({ + action: "image_editor__save_image", + payload: { + id: res.payload.id, + url: imgEl.src, + }, + }); + // Clear old data + document + .querySelectorAll(".image-result--delete-btn") + ?.forEach((btn) => btn.click()); + setTimeout(() => (location.href = "/"), 500); + } + }, 500); + + window.$checkCapcha = setInterval(() => { + const hasCapcha = document.querySelector(".checkbox-captcha"); + if (hasCapcha) { + clearInterval(window.$checkCapcha); + // stop loading + chrome.runtime.sendMessage({ + action: "image_editor__loading", + status: false, + }); + chrome.runtime.sendMessage({ + action: "image_editor__has_capcha", + payload: { + msg: "Has capcha!", + }, + }); + } + }, 500); + } + }); +} diff --git a/icon/128.png b/icon/128.png new file mode 100644 index 0000000000000000000000000000000000000000..5b418b9c3337731a01ae262e55390b8c64dc6cb6 GIT binary patch literal 2072 zcmZuydo(*Wa;fu1pvvev#2x95qa}tm$2tA0g}S7@HJY` zC;AD`UD#o*(l()dzxu@wM;{=iqNJibj-A1G6-?Re641^)a%E`L2HwMif?AfG^M;+S zsCp6XL4 z%SW2Y;|0fByMLuV15SiLefQWGuocw^u78 zIc*^+j6DawxKH)^GM{Ho-Qx;0DFHx7Z|`a1EbNu<`Cq(nzHni`oP>U^{aTrnvk5MW z^~K*rWdX7mnerTd%mb0#oncu4lSxcVOOsc(e26;SsfEMSl?=_z--OL@7si`8Q9y#D z4(vFgvA&?dnlb3=>N+zub)>rR!v}n&%gFe+ReF^yWVY-ho4Ty^$LUA)6}7qbL`#<^ z>sbDY#bTY?8ab|!AQBh*ytJ6X@KK%y?~RX-@AS*dK4$OM)V{9gAflITZ?eN!? z?dL_GOe}58&dp&kn497gL`aTWJpMe*@1So8Kr}Y z@B902t_vrZ9U2hrMd=zW0&VBNYrAblA|@(n{r+s~*YOBvAVE0M65pL|z)}0AZWN<# zc;bZj>mffsznx9(oO6CADwMl%{!?99=%U4Mof$cyTk#kf1BViwm$kKuD@M1|IT zZF<){PJHV(STZW;WNzP#jmis`a(Oj#Hoh34KLOH1R8*8orDDhZ4kZwY#B!HPpJT9R ziC)$Sg@EhVZK$1i9T?}4TK8jhdC$)v-#m{GQY}c1nE8=9Mpf10v{R+bIzp37texxb>-ehcGV0vwng6^F9@$@OY(Q3Mb@=wuT zUS6d|auTgcP}R>J#+XrE0JvQ1;S_?)>Yl>kaLR+dU!5Vrb0?ojVxPGXto2gw$SYEPeVh=<}Yh%ZgoFBrqA9Wd+No~`FgIe3Yw(Z zKGj1(?KLS!2Ej6;*M*0YTMI$jjWJ2DDcUFYz(F~`u*=rc)~2AP6W@VmxNLB|_m^Zr zEY5zH?&|6apC4{R=Zn?5gQl-!KtQpkoDd5CF*Vi18TF}~$^tCcH-_@Q70&!kj7$*^lg@oNk@Xq03k8p);^qamUrsped zhy0%H#qp*XyPwG6&y$V>!ogXb{n4zW4ac+~tqh$)Zc^Wppc277$#JR9>qATb+s|Pn z`bG7&R2;sHO^q8A^QeTABnbOJ@0{em4NWuWRB>_f`X!;Ay*>ATob(o2YFWdW0Az}9gHu|FMuIt&8(fDeauTkI&x3G* zq970m`Ejy&x8mLO2Lfy1sckb$ZGxomR4#-JVGYq&;e3^4m me`aPT3=TgEOR-9i+yPX$UhO|}gQ1|u180A?N4-K`zV|mHP0+gl literal 0 HcmV?d00001 diff --git a/icon/32.png b/icon/32.png new file mode 100644 index 0000000000000000000000000000000000000000..a460580345d64a6804c7fe4f6de655f51f0d4a6a GIT binary patch literal 527 zcmV+q0`UEbP)Kl`p8mKpe+!=W~iMLG0p!rXdEwII)Nr6bzc|cB_JE zCWA?kDMr(RNuybjVX`Sh&>}_^clW}<;gjb%_9htKH~sE+zx#dee)kX5YBlgS34#Cw zL3khFUmqck)yMtbi!pWv(Cv0hrP6~FA#^+*SF4q#X`|8Tdc9hQJ!&`{Vy1Lm4~N6- zB+xz|fLJUx9*=pRcL1QOsw~U0EN3#AUav>}k|gDFImW;*i-7HRJDbgjJ)KS?kw_|) zBF$tnscG7?fi_DtpUDXts>)7cwL~1pK?os)^m^ZJw@#;1tyXPLAH2F~%jFWn*YmTw zf_A$tiee&>IG@kN6OYFWg@R*%)9JL?Y!-_}zu%|MX0z#Xxtsw|wOTE@2uYI4<+8&7 z!!QPe0c|!K4Y%9vBme-QD9Yt>A$BwxtyC%w0}R8s--&v??(uk@1+zY!P$(1#1c<%g z?+=Fq?ehEm_pilzy`~%Uug??vNBz5CHk*B8b_jv4>*;j*<&$DV!C+8PlyBY5;i7va RZXW;u002ovPDHLkV1kUt@x1^5 literal 0 HcmV?d00001 diff --git a/icon/48.png b/icon/48.png new file mode 100644 index 0000000000000000000000000000000000000000..f6d5c2da5d3b9a40893b6a896030406071cefa15 GIT binary patch literal 690 zcmV;j0!{siP)_Lxd0;c$Wns zTr3udK)cxusGm@2cJNWPtYARdp0S(eKs`F8e!OePa%X*3$-+gS#3I2?Yz zA2X)YY4Ql9y$nJ)pU<&wkW3~AgTdjM&*$rOI+Mx7;c&kDbh}->UcXwc$eBoiZa5gX z+pWXlU>W6Rpy_n#cDwIFa|2L1omMCmHzZ>JD?3OglZ{5BI|T>eLWR6uFHO@lO*0I$ z-|w+ihG8BJ^wrBCgxPEsTdmjY|CuoF3j_eLTCG2e^z%%591w&sm&;)e?RNXBMg~}X zsS!faXcV2!_G-2IUPU6AhaiOcd>-@Z^?G8lm^=}ipFKh-5{Y0&g+dVw23gE<6yd~p zwn*dgnEXn_^1*m0680v2etw2RA;Jh(++1xo8<%@>DJT|;^Z6W)2%*Jd!N#=NY*s3j z$aB5*)?0r`S2dak=)>i5J)7ZFtyW7emp_~0D1*TOYPDJ>ld;?F&;1KSQIyByDHIC- Y0N^6)Rg;8qfdBvi07*qoM6N<$g7O75^#A|> literal 0 HcmV?d00001 diff --git a/libs/lodash/.internal/Hash.js b/libs/lodash/.internal/Hash.js new file mode 100644 index 0000000..2e277e3 --- /dev/null +++ b/libs/lodash/.internal/Hash.js @@ -0,0 +1,88 @@ +/** Used to stand-in for `undefined` hash values. */ +const HASH_UNDEFINED = '__lodash_hash_undefined__' + +class Hash { + + /** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + constructor(entries) { + let index = -1 + const length = entries == null ? 0 : entries.length + + this.clear() + while (++index < length) { + const entry = entries[index] + this.set(entry[0], entry[1]) + } + } + + /** + * Removes all key-value entries from the hash. + * + * @memberOf Hash + */ + clear() { + this.__data__ = Object.create(null) + this.size = 0 + } + + /** + * Removes `key` and its value from the hash. + * + * @memberOf Hash + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + delete(key) { + const result = this.has(key) && delete this.__data__[key] + this.size -= result ? 1 : 0 + return result + } + + /** + * Gets the hash value for `key`. + * + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + get(key) { + const data = this.__data__ + const result = data[key] + return result === HASH_UNDEFINED ? undefined : result + } + + /** + * Checks if a hash value for `key` exists. + * + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + has(key) { + const data = this.__data__ + return data[key] !== undefined + } + + /** + * Sets the hash `key` to `value`. + * + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */ + set(key, value) { + const data = this.__data__ + this.size += this.has(key) ? 0 : 1 + data[key] = value === undefined ? HASH_UNDEFINED : value + return this + } +} + +export default Hash diff --git a/libs/lodash/.internal/ListCache.js b/libs/lodash/.internal/ListCache.js new file mode 100644 index 0000000..f3015dd --- /dev/null +++ b/libs/lodash/.internal/ListCache.js @@ -0,0 +1,103 @@ +import assocIndexOf from './assocIndexOf.js' + +class ListCache { + + /** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + constructor(entries) { + let index = -1 + const length = entries == null ? 0 : entries.length + + this.clear() + while (++index < length) { + const entry = entries[index] + this.set(entry[0], entry[1]) + } + } + + /** + * Removes all key-value entries from the list cache. + * + * @memberOf ListCache + */ + clear() { + this.__data__ = [] + this.size = 0 + } + + /** + * Removes `key` and its value from the list cache. + * + * @memberOf ListCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + delete(key) { + const data = this.__data__ + const index = assocIndexOf(data, key) + + if (index < 0) { + return false + } + const lastIndex = data.length - 1 + if (index == lastIndex) { + data.pop() + } else { + data.splice(index, 1) + } + --this.size + return true + } + + /** + * Gets the list cache value for `key`. + * + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + get(key) { + const data = this.__data__ + const index = assocIndexOf(data, key) + return index < 0 ? undefined : data[index][1] + } + + /** + * Checks if a list cache value for `key` exists. + * + * @memberOf ListCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + has(key) { + return assocIndexOf(this.__data__, key) > -1 + } + + /** + * Sets the list cache `key` to `value`. + * + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */ + set(key, value) { + const data = this.__data__ + const index = assocIndexOf(data, key) + + if (index < 0) { + ++this.size + data.push([key, value]) + } else { + data[index][1] = value + } + return this + } +} + +export default ListCache diff --git a/libs/lodash/.internal/MapCache.js b/libs/lodash/.internal/MapCache.js new file mode 100644 index 0000000..706e17e --- /dev/null +++ b/libs/lodash/.internal/MapCache.js @@ -0,0 +1,120 @@ + +import Hash from './Hash.js' + +/** + * Gets the data for `map`. + * + * @private + * @param {Object} map The map to query. + * @param {string} key The reference key. + * @returns {*} Returns the map data. + */ +function getMapData({ __data__ }, key) { + const data = __data__ + return isKeyable(key) + ? data[typeof key === 'string' ? 'string' : 'hash'] + : data.map +} + +/** + * Checks if `value` is suitable for use as unique object key. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is suitable, else `false`. + */ +function isKeyable(value) { + const type = typeof value + return (type === 'string' || type === 'number' || type === 'symbol' || type === 'boolean') + ? (value !== '__proto__') + : (value === null) +} + +class MapCache { + + /** + * Creates a map cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + constructor(entries) { + let index = -1 + const length = entries == null ? 0 : entries.length + + this.clear() + while (++index < length) { + const entry = entries[index] + this.set(entry[0], entry[1]) + } + } + + /** + * Removes all key-value entries from the map. + * + * @memberOf MapCache + */ + clear() { + this.size = 0 + this.__data__ = { + 'hash': new Hash, + 'map': new Map, + 'string': new Hash + } + } + + /** + * Removes `key` and its value from the map. + * + * @memberOf MapCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + delete(key) { + const result = getMapData(this, key)['delete'](key) + this.size -= result ? 1 : 0 + return result + } + + /** + * Gets the map value for `key`. + * + * @memberOf MapCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + get(key) { + return getMapData(this, key).get(key) + } + + /** + * Checks if a map value for `key` exists. + * + * @memberOf MapCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + has(key) { + return getMapData(this, key).has(key) + } + + /** + * Sets the map `key` to `value`. + * + * @memberOf MapCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the map cache instance. + */ + set(key, value) { + const data = getMapData(this, key) + const size = data.size + + data.set(key, value) + this.size += data.size == size ? 0 : 1 + return this + } +} + +export default MapCache diff --git a/libs/lodash/.internal/SetCache.js b/libs/lodash/.internal/SetCache.js new file mode 100644 index 0000000..20b1cbf --- /dev/null +++ b/libs/lodash/.internal/SetCache.js @@ -0,0 +1,52 @@ +import MapCache from './MapCache.js' + +/** Used to stand-in for `undefined` hash values. */ +const HASH_UNDEFINED = '__lodash_hash_undefined__' + +class SetCache { + + /** + * Creates an array cache object to store unique values. + * + * @private + * @constructor + * @param {Array} [values] The values to cache. + */ + constructor(values) { + let index = -1 + const length = values == null ? 0 : values.length + + this.__data__ = new MapCache + while (++index < length) { + this.add(values[index]) + } + } + + /** + * Adds `value` to the array cache. + * + * @memberOf SetCache + * @alias push + * @param {*} value The value to cache. + * @returns {Object} Returns the cache instance. + */ + add(value) { + this.__data__.set(value, HASH_UNDEFINED) + return this + } + + /** + * Checks if `value` is in the array cache. + * + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {boolean} Returns `true` if `value` is found, else `false`. + */ + has(value) { + return this.__data__.has(value) + } +} + +SetCache.prototype.push = SetCache.prototype.add + +export default SetCache diff --git a/libs/lodash/.internal/Stack.js b/libs/lodash/.internal/Stack.js new file mode 100644 index 0000000..ee3afdd --- /dev/null +++ b/libs/lodash/.internal/Stack.js @@ -0,0 +1,93 @@ +import ListCache from './ListCache.js' +import MapCache from './MapCache.js' + +/** Used as the size to enable large array optimizations. */ +const LARGE_ARRAY_SIZE = 200 + +class Stack { + + /** + * Creates a stack cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + constructor(entries) { + const data = this.__data__ = new ListCache(entries) + this.size = data.size + } + + /** + * Removes all key-value entries from the stack. + * + * @memberOf Stack + */ + clear() { + this.__data__ = new ListCache + this.size = 0 + } + + /** + * Removes `key` and its value from the stack. + * + * @memberOf Stack + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + delete(key) { + const data = this.__data__ + const result = data['delete'](key) + + this.size = data.size + return result + } + + /** + * Gets the stack value for `key`. + * + * @memberOf Stack + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + get(key) { + return this.__data__.get(key) + } + + /** + * Checks if a stack value for `key` exists. + * + * @memberOf Stack + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + has(key) { + return this.__data__.has(key) + } + + /** + * Sets the stack `key` to `value`. + * + * @memberOf Stack + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the stack cache instance. + */ + set(key, value) { + let data = this.__data__ + if (data instanceof ListCache) { + const pairs = data.__data__ + if (pairs.length < LARGE_ARRAY_SIZE - 1) { + pairs.push([key, value]) + this.size = ++data.size + return this + } + data = this.__data__ = new MapCache(pairs) + } + data.set(key, value) + this.size = data.size + return this + } +} + +export default Stack diff --git a/libs/lodash/.internal/addMapEntry.js b/libs/lodash/.internal/addMapEntry.js new file mode 100644 index 0000000..34f504d --- /dev/null +++ b/libs/lodash/.internal/addMapEntry.js @@ -0,0 +1,15 @@ +/** + * Adds the key-value `pair` to `map`. + * + * @private + * @param {Object} map The map to modify. + * @param {Array} pair The key-value pair to add. + * @returns {Object} Returns `map`. + */ +function addMapEntry(map, pair) { + // Don't return `map.set` because it's not chainable in IE 11. + map.set(pair[0], pair[1]) + return map +} + +export default addMapEntry diff --git a/libs/lodash/.internal/addSetEntry.js b/libs/lodash/.internal/addSetEntry.js new file mode 100644 index 0000000..cfe3474 --- /dev/null +++ b/libs/lodash/.internal/addSetEntry.js @@ -0,0 +1,15 @@ +/** + * Adds `value` to `set`. + * + * @private + * @param {Object} set The set to modify. + * @param {*} value The value to add. + * @returns {Object} Returns `set`. + */ +function addSetEntry(set, value) { + // Don't return `set.add` because it's not chainable in IE 11. + set.add(value) + return set +} + +export default addSetEntry diff --git a/libs/lodash/.internal/arrayEach.js b/libs/lodash/.internal/arrayEach.js new file mode 100644 index 0000000..1af406d --- /dev/null +++ b/libs/lodash/.internal/arrayEach.js @@ -0,0 +1,21 @@ +/** + * A specialized version of `forEach` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ +function arrayEach(array, iteratee) { + let index = -1 + const length = array.length + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break + } + } + return array +} + +export default arrayEach diff --git a/libs/lodash/.internal/arrayEachRight.js b/libs/lodash/.internal/arrayEachRight.js new file mode 100644 index 0000000..1adf853 --- /dev/null +++ b/libs/lodash/.internal/arrayEachRight.js @@ -0,0 +1,20 @@ +/** + * A specialized version of `forEachRight` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ +function arrayEachRight(array, iteratee) { + let length = array == null ? 0 : array.length + + while (length--) { + if (iteratee(array[length], length, array) === false) { + break + } + } + return array +} + +export default arrayEachRight diff --git a/libs/lodash/.internal/arrayIncludes.js b/libs/lodash/.internal/arrayIncludes.js new file mode 100644 index 0000000..caec698 --- /dev/null +++ b/libs/lodash/.internal/arrayIncludes.js @@ -0,0 +1,17 @@ +import baseIndexOf from './baseIndexOf.js' + +/** + * A specialized version of `includes` for arrays without support for + * specifying an index to search from. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ +function arrayIncludes(array, value) { + const length = array == null ? 0 : array.length + return !!length && baseIndexOf(array, value, 0) > -1 +} + +export default arrayIncludes diff --git a/libs/lodash/.internal/arrayIncludesWith.js b/libs/lodash/.internal/arrayIncludesWith.js new file mode 100644 index 0000000..09e35df --- /dev/null +++ b/libs/lodash/.internal/arrayIncludesWith.js @@ -0,0 +1,23 @@ +/** + * This function is like `arrayIncludes` except that it accepts a comparator. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @param {Function} comparator The comparator invoked per element. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ +function arrayIncludesWith(array, target, comparator) { + if (array == null) { + return false + } + + for (const value of array) { + if (comparator(target, value)) { + return true + } + } + return false +} + +export default arrayIncludesWith diff --git a/libs/lodash/.internal/arrayLikeKeys.js b/libs/lodash/.internal/arrayLikeKeys.js new file mode 100644 index 0000000..fea4bcd --- /dev/null +++ b/libs/lodash/.internal/arrayLikeKeys.js @@ -0,0 +1,43 @@ +import isArguments from '../isArguments.js' +import isBuffer from '../isBuffer.js' +import isIndex from './isIndex.js' +import isTypedArray from '../isTypedArray.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Creates an array of the enumerable property names of the array-like `value`. + * + * @private + * @param {*} value The value to query. + * @param {boolean} inherited Specify returning inherited property names. + * @returns {Array} Returns the array of property names. + */ +function arrayLikeKeys(value, inherited) { + const isArr = Array.isArray(value) + const isArg = !isArr && isArguments(value) + const isBuff = !isArr && !isArg && isBuffer(value) + const isType = !isArr && !isArg && !isBuff && isTypedArray(value) + const skipIndexes = isArr || isArg || isBuff || isType + const length = value.length + const result = new Array(skipIndexes ? length : 0) + let index = skipIndexes ? -1 : length + while (++index < length) { + result[index] = `${index}` + } + for (const key in value) { + if ((inherited || hasOwnProperty.call(value, key)) && + !(skipIndexes && ( + // Safari 9 has enumerable `arguments.length` in strict mode. + (key === 'length' || + // Skip index properties. + isIndex(key, length)) + ))) { + result.push(key) + } + } + return result +} + +export default arrayLikeKeys diff --git a/libs/lodash/.internal/arrayReduce.js b/libs/lodash/.internal/arrayReduce.js new file mode 100644 index 0000000..4078f3c --- /dev/null +++ b/libs/lodash/.internal/arrayReduce.js @@ -0,0 +1,25 @@ +/** + * A specialized version of `reduce` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ +function arrayReduce(array, iteratee, accumulator, initAccum) { + let index = -1 + const length = array == null ? 0 : array.length + + if (initAccum && length) { + accumulator = array[++index] + } + while (++index < length) { + accumulator = iteratee(accumulator, array[index], index, array) + } + return accumulator +} + +export default arrayReduce diff --git a/libs/lodash/.internal/arrayReduceRight.js b/libs/lodash/.internal/arrayReduceRight.js new file mode 100644 index 0000000..34406af --- /dev/null +++ b/libs/lodash/.internal/arrayReduceRight.js @@ -0,0 +1,23 @@ +/** + * A specialized version of `reduceRight` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ +function arrayReduceRight(array, iteratee, accumulator, initAccum) { + let length = array == null ? 0 : array.length + if (initAccum && length) { + accumulator = array[--length] + } + while (length--) { + accumulator = iteratee(accumulator, array[length], length, array) + } + return accumulator +} + +export default arrayReduceRight diff --git a/libs/lodash/.internal/asciiSize.js b/libs/lodash/.internal/asciiSize.js new file mode 100644 index 0000000..4d12e8c --- /dev/null +++ b/libs/lodash/.internal/asciiSize.js @@ -0,0 +1,12 @@ +/** + * Gets the size of an ASCII `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ +function asciiSize({ length }) { + return length +} + +export default asciiSize diff --git a/libs/lodash/.internal/asciiToArray.js b/libs/lodash/.internal/asciiToArray.js new file mode 100644 index 0000000..2fc3fd5 --- /dev/null +++ b/libs/lodash/.internal/asciiToArray.js @@ -0,0 +1,12 @@ +/** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function asciiToArray(string) { + return string.split('') +} + +export default asciiToArray diff --git a/libs/lodash/.internal/assignMergeValue.js b/libs/lodash/.internal/assignMergeValue.js new file mode 100644 index 0000000..8ce656b --- /dev/null +++ b/libs/lodash/.internal/assignMergeValue.js @@ -0,0 +1,20 @@ +import baseAssignValue from './baseAssignValue.js' +import eq from '../eq.js' + +/** + * This function is like `assignValue` except that it doesn't assign + * `undefined` values. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ +function assignMergeValue(object, key, value) { + if ((value !== undefined && !eq(object[key], value)) || + (value === undefined && !(key in object))) { + baseAssignValue(object, key, value) + } +} + +export default assignMergeValue diff --git a/libs/lodash/.internal/assignValue.js b/libs/lodash/.internal/assignValue.js new file mode 100644 index 0000000..f9a113d --- /dev/null +++ b/libs/lodash/.internal/assignValue.js @@ -0,0 +1,27 @@ +import baseAssignValue from './baseAssignValue.js' +import eq from '../eq.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Assigns `value` to `key` of `object` if the existing value is not equivalent. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ +function assignValue(object, key, value) { + const objValue = object[key] + + if (!(hasOwnProperty.call(object, key) && eq(objValue, value))) { + if (value !== 0 || (1 / value) === (1 / objValue)) { + baseAssignValue(object, key, value) + } + } else if (value === undefined && !(key in object)) { + baseAssignValue(object, key, value) + } +} + +export default assignValue diff --git a/libs/lodash/.internal/assocIndexOf.js b/libs/lodash/.internal/assocIndexOf.js new file mode 100644 index 0000000..93cf863 --- /dev/null +++ b/libs/lodash/.internal/assocIndexOf.js @@ -0,0 +1,21 @@ +import eq from '../eq.js' + +/** + * Gets the index at which the `key` is found in `array` of key-value pairs. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} key The key to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function assocIndexOf(array, key) { + let { length } = array + while (length--) { + if (eq(array[length][0], key)) { + return length + } + } + return -1 +} + +export default assocIndexOf diff --git a/libs/lodash/.internal/baseAssignValue.js b/libs/lodash/.internal/baseAssignValue.js new file mode 100644 index 0000000..7b630c3 --- /dev/null +++ b/libs/lodash/.internal/baseAssignValue.js @@ -0,0 +1,23 @@ +/** + * The base implementation of `assignValue` and `assignMergeValue` without + * value checks. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ +function baseAssignValue(object, key, value) { + if (key == '__proto__') { + Object.defineProperty(object, key, { + 'configurable': true, + 'enumerable': true, + 'value': value, + 'writable': true + }) + } else { + object[key] = value + } +} + +export default baseAssignValue diff --git a/libs/lodash/.internal/baseAt.js b/libs/lodash/.internal/baseAt.js new file mode 100644 index 0000000..1668e9a --- /dev/null +++ b/libs/lodash/.internal/baseAt.js @@ -0,0 +1,23 @@ +import get from '../get.js' + +/** + * The base implementation of `at` without support for individual paths. + * + * @private + * @param {Object} object The object to iterate over. + * @param {string[]} paths The property paths to pick. + * @returns {Array} Returns the picked elements. + */ +function baseAt(object, paths) { + let index = -1 + const length = paths.length + const result = new Array(length) + const skip = object == null + + while (++index < length) { + result[index] = skip ? undefined : get(object, paths[index]) + } + return result +} + +export default baseAt diff --git a/libs/lodash/.internal/baseClone.js b/libs/lodash/.internal/baseClone.js new file mode 100644 index 0000000..a7157e1 --- /dev/null +++ b/libs/lodash/.internal/baseClone.js @@ -0,0 +1,241 @@ +import Stack from './Stack.js' +import arrayEach from './arrayEach.js' +import assignValue from './assignValue.js' +import cloneBuffer from './cloneBuffer.js' +import copyArray from './copyArray.js' +import copyObject from './copyObject.js' +import cloneArrayBuffer from './cloneArrayBuffer.js' +import cloneDataView from './cloneDataView.js' +import cloneRegExp from './cloneRegExp.js' +import cloneSymbol from './cloneSymbol.js' +import cloneTypedArray from './cloneTypedArray.js' +import copySymbols from './copySymbols.js' +import copySymbolsIn from './copySymbolsIn.js' +import getAllKeys from './getAllKeys.js' +import getAllKeysIn from './getAllKeysIn.js' +import getTag from './getTag.js' +import initCloneObject from './initCloneObject.js' +import isBuffer from '../isBuffer.js' +import isObject from '../isObject.js' +import isTypedArray from '../isTypedArray.js' +import keys from '../keys.js' +import keysIn from '../keysIn.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 +const CLONE_FLAT_FLAG = 2 +const CLONE_SYMBOLS_FLAG = 4 + +/** `Object#toString` result references. */ +const argsTag = '[object Arguments]' +const arrayTag = '[object Array]' +const boolTag = '[object Boolean]' +const dateTag = '[object Date]' +const errorTag = '[object Error]' +const mapTag = '[object Map]' +const numberTag = '[object Number]' +const objectTag = '[object Object]' +const regexpTag = '[object RegExp]' +const setTag = '[object Set]' +const stringTag = '[object String]' +const symbolTag = '[object Symbol]' +const weakMapTag = '[object WeakMap]' + +const arrayBufferTag = '[object ArrayBuffer]' +const dataViewTag = '[object DataView]' +const float32Tag = '[object Float32Array]' +const float64Tag = '[object Float64Array]' +const int8Tag = '[object Int8Array]' +const int16Tag = '[object Int16Array]' +const int32Tag = '[object Int32Array]' +const uint8Tag = '[object Uint8Array]' +const uint8ClampedTag = '[object Uint8ClampedArray]' +const uint16Tag = '[object Uint16Array]' +const uint32Tag = '[object Uint32Array]' + +/** Used to identify `toStringTag` values supported by `clone`. */ +const cloneableTags = {} +cloneableTags[argsTag] = cloneableTags[arrayTag] = +cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = +cloneableTags[boolTag] = cloneableTags[dateTag] = +cloneableTags[float32Tag] = cloneableTags[float64Tag] = +cloneableTags[int8Tag] = cloneableTags[int16Tag] = +cloneableTags[int32Tag] = cloneableTags[mapTag] = +cloneableTags[numberTag] = cloneableTags[objectTag] = +cloneableTags[regexpTag] = cloneableTags[setTag] = +cloneableTags[stringTag] = cloneableTags[symbolTag] = +cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = +cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true +cloneableTags[errorTag] = cloneableTags[weakMapTag] = false + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Initializes an object clone based on its `toStringTag`. + * + * **Note:** This function only supports cloning values with tags of + * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. + * + * @private + * @param {Object} object The object to clone. + * @param {string} tag The `toStringTag` of the object to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the initialized clone. + */ +function initCloneByTag(object, tag, isDeep) { + const Ctor = object.constructor + switch (tag) { + case arrayBufferTag: + return cloneArrayBuffer(object) + + case boolTag: + case dateTag: + return new Ctor(+object) + + case dataViewTag: + return cloneDataView(object, isDeep) + + case float32Tag: case float64Tag: + case int8Tag: case int16Tag: case int32Tag: + case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: + return cloneTypedArray(object, isDeep) + + case mapTag: + return new Ctor + + case numberTag: + case stringTag: + return new Ctor(object) + + case regexpTag: + return cloneRegExp(object) + + case setTag: + return new Ctor + + case symbolTag: + return cloneSymbol(object) + } +} + +/** + * Initializes an array clone. + * + * @private + * @param {Array} array The array to clone. + * @returns {Array} Returns the initialized clone. + */ +function initCloneArray(array) { + const { length } = array + const result = new array.constructor(length) + + // Add properties assigned by `RegExp#exec`. + if (length && typeof array[0] === 'string' && hasOwnProperty.call(array, 'index')) { + result.index = array.index + result.input = array.input + } + return result +} + +/** + * The base implementation of `clone` and `cloneDeep` which tracks + * traversed objects. + * + * @private + * @param {*} value The value to clone. + * @param {number} bitmask The bitmask flags. + * 1 - Deep clone + * 2 - Flatten inherited properties + * 4 - Clone symbols + * @param {Function} [customizer] The function to customize cloning. + * @param {string} [key] The key of `value`. + * @param {Object} [object] The parent object of `value`. + * @param {Object} [stack] Tracks traversed objects and their clone counterparts. + * @returns {*} Returns the cloned value. + */ +function baseClone(value, bitmask, customizer, key, object, stack) { + let result + const isDeep = bitmask & CLONE_DEEP_FLAG + const isFlat = bitmask & CLONE_FLAT_FLAG + const isFull = bitmask & CLONE_SYMBOLS_FLAG + + if (customizer) { + result = object ? customizer(value, key, object, stack) : customizer(value) + } + if (result !== undefined) { + return result + } + if (!isObject(value)) { + return value + } + const isArr = Array.isArray(value) + const tag = getTag(value) + if (isArr) { + result = initCloneArray(value) + if (!isDeep) { + return copyArray(value, result) + } + } else { + const isFunc = typeof value === 'function' + + if (isBuffer(value)) { + return cloneBuffer(value, isDeep) + } + if (tag == objectTag || tag == argsTag || (isFunc && !object)) { + result = (isFlat || isFunc) ? {} : initCloneObject(value) + if (!isDeep) { + return isFlat + ? copySymbolsIn(value, copyObject(value, keysIn(value), result)) + : copySymbols(value, Object.assign(result, value)) + } + } else { + if (isFunc || !cloneableTags[tag]) { + return object ? value : {} + } + result = initCloneByTag(value, tag, isDeep) + } + } + // Check for circular references and return its corresponding clone. + stack || (stack = new Stack) + const stacked = stack.get(value) + if (stacked) { + return stacked + } + stack.set(value, result) + + if (tag == mapTag) { + value.forEach((subValue, key) => { + result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)) + }) + return result + } + + if (tag == setTag) { + value.forEach((subValue) => { + result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)) + }) + return result + } + + if (isTypedArray(value)) { + return result + } + + const keysFunc = isFull + ? (isFlat ? getAllKeysIn : getAllKeys) + : (isFlat ? keysIn : keys) + + const props = isArr ? undefined : keysFunc(value) + arrayEach(props || value, (subValue, key) => { + if (props) { + key = subValue + subValue = value[key] + } + // Recursively populate clone (susceptible to call stack limits). + assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)) + }) + return result +} + +export default baseClone diff --git a/libs/lodash/.internal/baseConforms.js b/libs/lodash/.internal/baseConforms.js new file mode 100644 index 0000000..1df2aed --- /dev/null +++ b/libs/lodash/.internal/baseConforms.js @@ -0,0 +1,16 @@ +import baseConformsTo from './baseConformsTo.js' +import keys from '../keys.js' + +/** + * The base implementation of `conforms` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property predicates to conform to. + * @returns {Function} Returns the new spec function. + */ +function baseConforms(source) { + const props = keys(source) + return (object) => baseConformsTo(object, source, props) +} + +export default baseConforms diff --git a/libs/lodash/.internal/baseConformsTo.js b/libs/lodash/.internal/baseConformsTo.js new file mode 100644 index 0000000..8569bbd --- /dev/null +++ b/libs/lodash/.internal/baseConformsTo.js @@ -0,0 +1,27 @@ +/** + * The base implementation of `conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ +function baseConformsTo(object, source, props) { + let length = props.length + if (object == null) { + return !length + } + object = Object(object) + while (length--) { + const key = props[length] + const predicate = source[key] + const value = object[key] + + if ((value === undefined && !(key in object)) || !predicate(value)) { + return false + } + } + return true +} + +export default baseConformsTo diff --git a/libs/lodash/.internal/baseDifference.js b/libs/lodash/.internal/baseDifference.js new file mode 100644 index 0000000..1bf76d7 --- /dev/null +++ b/libs/lodash/.internal/baseDifference.js @@ -0,0 +1,63 @@ +import SetCache from './SetCache.js' +import arrayIncludes from './arrayIncludes.js' +import arrayIncludesWith from './arrayIncludesWith.js' +import map from '../map.js' +import cacheHas from './cacheHas.js' + +/** Used as the size to enable large array optimizations. */ +const LARGE_ARRAY_SIZE = 200 + +/** + * The base implementation of methods like `difference` without support + * for excluding multiple arrays. + * + * @private + * @param {Array} array The array to inspect. + * @param {Array} values The values to exclude. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + */ +function baseDifference(array, values, iteratee, comparator) { + let includes = arrayIncludes + let isCommon = true + const result = [] + const valuesLength = values.length + + if (!array.length) { + return result + } + if (iteratee) { + values = map(values, (value) => iteratee(value)) + } + if (comparator) { + includes = arrayIncludesWith + isCommon = false + } + else if (values.length >= LARGE_ARRAY_SIZE) { + includes = cacheHas + isCommon = false + values = new SetCache(values) + } + outer: + for (let value of array) { + const computed = iteratee == null ? value : iteratee(value) + + value = (comparator || value !== 0) ? value : 0 + if (isCommon && computed === computed) { + let valuesIndex = valuesLength + while (valuesIndex--) { + if (values[valuesIndex] === computed) { + continue outer + } + } + result.push(value) + } + else if (!includes(values, computed, comparator)) { + result.push(value) + } + } + return result +} + +export default baseDifference diff --git a/libs/lodash/.internal/baseEach.js b/libs/lodash/.internal/baseEach.js new file mode 100644 index 0000000..1cf581d --- /dev/null +++ b/libs/lodash/.internal/baseEach.js @@ -0,0 +1,31 @@ +import baseForOwn from './baseForOwn.js' +import isArrayLike from '../isArrayLike.js' + +/** + * The base implementation of `forEach`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ +function baseEach(collection, iteratee) { + if (collection == null) { + return collection + } + if (!isArrayLike(collection)) { + return baseForOwn(collection, iteratee) + } + const length = collection.length + const iterable = Object(collection) + let index = -1 + + while (++index < length) { + if (iteratee(iterable[index], index, iterable) === false) { + break + } + } + return collection +} + +export default baseEach diff --git a/libs/lodash/.internal/baseEachRight.js b/libs/lodash/.internal/baseEachRight.js new file mode 100644 index 0000000..263fd21 --- /dev/null +++ b/libs/lodash/.internal/baseEachRight.js @@ -0,0 +1,30 @@ +import baseForOwnRight from './baseForOwnRight.js' +import isArrayLike from '../isArrayLike.js' + +/** + * The base implementation of `forEachRight`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ +function baseEachRight(collection, iteratee) { + if (collection == null) { + return collection + } + if (!isArrayLike(collection)) { + return baseForOwnRight(collection, iteratee) + } + const iterable = Object(collection) + let length = collection.length + + while (length--) { + if (iteratee(iterable[length], length, iterable) === false) { + break + } + } + return collection +} + +export default baseEachRight diff --git a/libs/lodash/.internal/baseFindIndex.js b/libs/lodash/.internal/baseFindIndex.js new file mode 100644 index 0000000..f7ea131 --- /dev/null +++ b/libs/lodash/.internal/baseFindIndex.js @@ -0,0 +1,23 @@ +/** + * The base implementation of `findIndex` and `findLastIndex`. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseFindIndex(array, predicate, fromIndex, fromRight) { + const { length } = array + let index = fromIndex + (fromRight ? 1 : -1) + + while ((fromRight ? index-- : ++index < length)) { + if (predicate(array[index], index, array)) { + return index + } + } + return -1 +} + +export default baseFindIndex diff --git a/libs/lodash/.internal/baseFindKey.js b/libs/lodash/.internal/baseFindKey.js new file mode 100644 index 0000000..4374ce8 --- /dev/null +++ b/libs/lodash/.internal/baseFindKey.js @@ -0,0 +1,22 @@ +/** + * The base implementation of methods like `findKey` and `findLastKey` + * which iterates over `collection` using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the found element or its key, else `undefined`. + */ +function baseFindKey(collection, predicate, eachFunc) { + let result + eachFunc(collection, (value, key, collection) => { + if (predicate(value, key, collection)) { + result = key + return false + } + }) + return result +} + +export default baseFindKey diff --git a/libs/lodash/.internal/baseFlatten.js b/libs/lodash/.internal/baseFlatten.js new file mode 100644 index 0000000..dc1d9df --- /dev/null +++ b/libs/lodash/.internal/baseFlatten.js @@ -0,0 +1,37 @@ +import isFlattenable from './isFlattenable.js' + +/** + * The base implementation of `flatten` with support for restricting flattening. + * + * @private + * @param {Array} array The array to flatten. + * @param {number} depth The maximum recursion depth. + * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. + * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. + * @param {Array} [result=[]] The initial result value. + * @returns {Array} Returns the new flattened array. + */ +function baseFlatten(array, depth, predicate, isStrict, result) { + predicate || (predicate = isFlattenable) + result || (result = []) + + if (array == null) { + return result + } + + for (const value of array) { + if (depth > 0 && predicate(value)) { + if (depth > 1) { + // Recursively flatten arrays (susceptible to call stack limits). + baseFlatten(value, depth - 1, predicate, isStrict, result) + } else { + result.push(...value) + } + } else if (!isStrict) { + result[result.length] = value + } + } + return result +} + +export default baseFlatten diff --git a/libs/lodash/.internal/baseFor.js b/libs/lodash/.internal/baseFor.js new file mode 100644 index 0000000..a0eb403 --- /dev/null +++ b/libs/lodash/.internal/baseFor.js @@ -0,0 +1,27 @@ +/** + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` and invokes `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ +function baseFor(object, iteratee, keysFunc) { + const iterable = Object(object) + const props = keysFunc(object) + let { length } = props + let index = -1 + + while (length--) { + const key = props[++index] + if (iteratee(iterable[key], key, iterable) === false) { + break + } + } + return object +} + +export default baseFor diff --git a/libs/lodash/.internal/baseForOwn.js b/libs/lodash/.internal/baseForOwn.js new file mode 100644 index 0000000..8476037 --- /dev/null +++ b/libs/lodash/.internal/baseForOwn.js @@ -0,0 +1,16 @@ +import baseFor from './baseFor.js' +import keys from '../keys.js' + +/** + * The base implementation of `forOwn`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys) +} + +export default baseForOwn diff --git a/libs/lodash/.internal/baseForOwnRight.js b/libs/lodash/.internal/baseForOwnRight.js new file mode 100644 index 0000000..b94a053 --- /dev/null +++ b/libs/lodash/.internal/baseForOwnRight.js @@ -0,0 +1,16 @@ +import baseForRight from './baseForRight.js' +import keys from '../keys.js' + +/** + * The base implementation of `forOwnRight`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForOwnRight(object, iteratee) { + return object && baseForRight(object, iteratee, keys) +} + +export default baseForOwnRight diff --git a/libs/lodash/.internal/baseForRight.js b/libs/lodash/.internal/baseForRight.js new file mode 100644 index 0000000..d10c6a1 --- /dev/null +++ b/libs/lodash/.internal/baseForRight.js @@ -0,0 +1,25 @@ +/** + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ +function baseForRight(object, iteratee, keysFunc) { + const iterable = Object(object) + const props = keysFunc(object) + let { length } = props + + while (length--) { + const key = props[length] + if (iteratee(iterable[key], key, iterable) === false) { + break + } + } + return object +} + +export default baseForRight diff --git a/libs/lodash/.internal/baseGet.js b/libs/lodash/.internal/baseGet.js new file mode 100644 index 0000000..d0bc3d4 --- /dev/null +++ b/libs/lodash/.internal/baseGet.js @@ -0,0 +1,24 @@ +import castPath from './castPath.js' +import toKey from './toKey.js' + +/** + * The base implementation of `get` without support for default values. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @returns {*} Returns the resolved value. + */ +function baseGet(object, path) { + path = castPath(path, object) + + let index = 0 + const length = path.length + + while (object != null && index < length) { + object = object[toKey(path[index++])] + } + return (index && index == length) ? object : undefined +} + +export default baseGet diff --git a/libs/lodash/.internal/baseInRange.js b/libs/lodash/.internal/baseInRange.js new file mode 100644 index 0000000..607bc66 --- /dev/null +++ b/libs/lodash/.internal/baseInRange.js @@ -0,0 +1,14 @@ +/** + * The base implementation of `inRange` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to check. + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + */ +function baseInRange(number, start, end) { + return number >= Math.min(start, end) && number < Math.max(start, end) +} + +export default baseInRange diff --git a/libs/lodash/.internal/baseIndexOf.js b/libs/lodash/.internal/baseIndexOf.js new file mode 100644 index 0000000..0566354 --- /dev/null +++ b/libs/lodash/.internal/baseIndexOf.js @@ -0,0 +1,20 @@ +import baseFindIndex from './baseFindIndex.js' +import baseIsNaN from './baseIsNaN.js' +import strictIndexOf from './strictIndexOf.js' + +/** + * The base implementation of `indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseIndexOf(array, value, fromIndex) { + return value === value + ? strictIndexOf(array, value, fromIndex) + : baseFindIndex(array, baseIsNaN, fromIndex) +} + +export default baseIndexOf diff --git a/libs/lodash/.internal/baseIndexOfWith.js b/libs/lodash/.internal/baseIndexOfWith.js new file mode 100644 index 0000000..8a98ff3 --- /dev/null +++ b/libs/lodash/.internal/baseIndexOfWith.js @@ -0,0 +1,23 @@ +/** + * This function is like `baseIndexOf` except that it accepts a comparator. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @param {Function} comparator The comparator invoked per element. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseIndexOfWith(array, value, fromIndex, comparator) { + let index = fromIndex - 1 + const { length } = array + + while (++index < length) { + if (comparator(array[index], value)) { + return index + } + } + return -1 +} + +export default baseIndexOfWith diff --git a/libs/lodash/.internal/baseIntersection.js b/libs/lodash/.internal/baseIntersection.js new file mode 100644 index 0000000..b723872 --- /dev/null +++ b/libs/lodash/.internal/baseIntersection.js @@ -0,0 +1,72 @@ +import SetCache from './SetCache.js' +import arrayIncludes from './arrayIncludes.js' +import arrayIncludesWith from './arrayIncludesWith.js' +import map from '../map.js' +import cacheHas from './cacheHas.js' + +/** + * The base implementation of methods like `intersection` that accepts an + * array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ +function baseIntersection(arrays, iteratee, comparator) { + const includes = comparator ? arrayIncludesWith : arrayIncludes + const length = arrays[0].length + const othLength = arrays.length + const caches = new Array(othLength) + const result = [] + + let array + let maxLength = Infinity + let othIndex = othLength + + while (othIndex--) { + array = arrays[othIndex] + if (othIndex && iteratee) { + array = map(array, (value) => iteratee(value)) + } + maxLength = Math.min(array.length, maxLength) + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined + } + array = arrays[0] + + let index = -1 + const seen = caches[0] + + outer: + while (++index < length && result.length < maxLength) { + let value = array[index] + const computed = iteratee ? iteratee(value) : value + + value = (comparator || value !== 0) ? value : 0 + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength + while (--othIndex) { + const cache = caches[othIndex] + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer + } + } + if (seen) { + seen.push(computed) + } + result.push(value) + } + } + return result +} + +export default baseIntersection diff --git a/libs/lodash/.internal/baseIsEqual.js b/libs/lodash/.internal/baseIsEqual.js new file mode 100644 index 0000000..58b2a45 --- /dev/null +++ b/libs/lodash/.internal/baseIsEqual.js @@ -0,0 +1,28 @@ +import baseIsEqualDeep from './baseIsEqualDeep.js' +import isObjectLike from '../isObjectLike.js' + +/** + * The base implementation of `isEqual` which supports partial comparisons + * and tracks traversed objects. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {boolean} bitmask The bitmask flags. + * 1 - Unordered comparison + * 2 - Partial comparison + * @param {Function} [customizer] The function to customize comparisons. + * @param {Object} [stack] Tracks traversed `value` and `other` objects. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + */ +function baseIsEqual(value, other, bitmask, customizer, stack) { + if (value === other) { + return true + } + if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { + return value !== value && other !== other + } + return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack) +} + +export default baseIsEqual diff --git a/libs/lodash/.internal/baseIsEqualDeep.js b/libs/lodash/.internal/baseIsEqualDeep.js new file mode 100644 index 0000000..27749cd --- /dev/null +++ b/libs/lodash/.internal/baseIsEqualDeep.js @@ -0,0 +1,79 @@ +import Stack from './Stack.js' +import equalArrays from './equalArrays.js' +import equalByTag from './equalByTag.js' +import equalObjects from './equalObjects.js' +import getTag from './getTag.js' +import isBuffer from '../isBuffer.js' +import isTypedArray from '../isTypedArray.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 + +/** `Object#toString` result references. */ +const argsTag = '[object Arguments]' +const arrayTag = '[object Array]' +const objectTag = '[object Object]' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * A specialized version of `baseIsEqual` for arrays and objects which performs + * deep comparisons and tracks traversed objects enabling objects with circular + * references to be compared. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} [stack] Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { + let objIsArr = Array.isArray(object) + const othIsArr = Array.isArray(other) + let objTag = objIsArr ? arrayTag : getTag(object) + let othTag = othIsArr ? arrayTag : getTag(other) + + objTag = objTag == argsTag ? objectTag : objTag + othTag = othTag == argsTag ? objectTag : othTag + + let objIsObj = objTag == objectTag + const othIsObj = othTag == objectTag + const isSameTag = objTag == othTag + + if (isSameTag && isBuffer(object)) { + if (!isBuffer(other)) { + return false + } + objIsArr = true + objIsObj = false + } + if (isSameTag && !objIsObj) { + stack || (stack = new Stack) + return (objIsArr || isTypedArray(object)) + ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) + : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack) + } + if (!(bitmask & COMPARE_PARTIAL_FLAG)) { + const objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__') + const othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__') + + if (objIsWrapped || othIsWrapped) { + const objUnwrapped = objIsWrapped ? object.value() : object + const othUnwrapped = othIsWrapped ? other.value() : other + + stack || (stack = new Stack) + return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack) + } + } + if (!isSameTag) { + return false + } + stack || (stack = new Stack) + return equalObjects(object, other, bitmask, customizer, equalFunc, stack) +} + +export default baseIsEqualDeep diff --git a/libs/lodash/.internal/baseIsMatch.js b/libs/lodash/.internal/baseIsMatch.js new file mode 100644 index 0000000..07ab10e --- /dev/null +++ b/libs/lodash/.internal/baseIsMatch.js @@ -0,0 +1,64 @@ +import Stack from './Stack.js' +import baseIsEqual from './baseIsEqual.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 +const COMPARE_UNORDERED_FLAG = 2 + +/** + * The base implementation of `isMatch`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Array} matchData The property names, values, and compare flags to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + */ +function baseIsMatch(object, source, matchData, customizer) { + let index = matchData.length + const length = index + const noCustomizer = !customizer + + if (object == null) { + return !length + } + let data + let result + object = Object(object) + while (index--) { + data = matchData[index] + if ((noCustomizer && data[2]) + ? data[1] !== object[data[0]] + : !(data[0] in object) + ) { + return false + } + } + while (++index < length) { + data = matchData[index] + const key = data[0] + const objValue = object[key] + const srcValue = data[1] + + if (noCustomizer && data[2]) { + if (objValue === undefined && !(key in object)) { + return false + } + } else { + const stack = new Stack + if (customizer) { + result = customizer(objValue, srcValue, key, object, source, stack) + } + if (!(result === undefined + ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) + : result + )) { + return false + } + } + } + return true +} + +export default baseIsMatch diff --git a/libs/lodash/.internal/baseIsNaN.js b/libs/lodash/.internal/baseIsNaN.js new file mode 100644 index 0000000..1ca038c --- /dev/null +++ b/libs/lodash/.internal/baseIsNaN.js @@ -0,0 +1,12 @@ +/** + * The base implementation of `isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ +function baseIsNaN(value) { + return value !== value +} + +export default baseIsNaN diff --git a/libs/lodash/.internal/baseMatches.js b/libs/lodash/.internal/baseMatches.js new file mode 100644 index 0000000..cf294ac --- /dev/null +++ b/libs/lodash/.internal/baseMatches.js @@ -0,0 +1,20 @@ +import baseIsMatch from './baseIsMatch.js' +import getMatchData from './getMatchData.js' +import matchesStrictComparable from './matchesStrictComparable.js' + +/** + * The base implementation of `matches` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property values to match. + * @returns {Function} Returns the new spec function. + */ +function baseMatches(source) { + const matchData = getMatchData(source) + if (matchData.length === 1 && matchData[0][2]) { + return matchesStrictComparable(matchData[0][0], matchData[0][1]) + } + return (object) => object === source || baseIsMatch(object, source, matchData) +} + +export default baseMatches diff --git a/libs/lodash/.internal/baseMatchesProperty.js b/libs/lodash/.internal/baseMatchesProperty.js new file mode 100644 index 0000000..a7810c2 --- /dev/null +++ b/libs/lodash/.internal/baseMatchesProperty.js @@ -0,0 +1,33 @@ +import baseIsEqual from './baseIsEqual.js' +import get from '../get.js' +import hasIn from '../hasIn.js' +import isKey from './isKey.js' +import isStrictComparable from './isStrictComparable.js' +import matchesStrictComparable from './matchesStrictComparable.js' +import toKey from './toKey.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 +const COMPARE_UNORDERED_FLAG = 2 + +/** + * The base implementation of `matchesProperty` which doesn't clone `srcValue`. + * + * @private + * @param {string} path The path of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ +function baseMatchesProperty(path, srcValue) { + if (isKey(path) && isStrictComparable(srcValue)) { + return matchesStrictComparable(toKey(path), srcValue) + } + return (object) => { + const objValue = get(object, path) + return (objValue === undefined && objValue === srcValue) + ? hasIn(object, path) + : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG) + } +} + +export default baseMatchesProperty diff --git a/libs/lodash/.internal/baseMerge.js b/libs/lodash/.internal/baseMerge.js new file mode 100644 index 0000000..1efcced --- /dev/null +++ b/libs/lodash/.internal/baseMerge.js @@ -0,0 +1,41 @@ +import Stack from './Stack.js' +import assignMergeValue from './assignMergeValue.js' +import baseFor from './baseFor.js' +import baseMergeDeep from './baseMergeDeep.js' +import isObject from '../isObject.js' +import keysIn from '../keysIn.js' + +/** + * The base implementation of `merge` without support for multiple sources. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {number} srcIndex The index of `source`. + * @param {Function} [customizer] The function to customize merged values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ +function baseMerge(object, source, srcIndex, customizer, stack) { + if (object === source) { + return + } + baseFor(source, (srcValue, key) => { + if (isObject(srcValue)) { + stack || (stack = new Stack) + baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack) + } + else { + let newValue = customizer + ? customizer(object[key], srcValue, `${key}`, object, source, stack) + : undefined + + if (newValue === undefined) { + newValue = srcValue + } + assignMergeValue(object, key, newValue) + } + }, keysIn) +} + +export default baseMerge diff --git a/libs/lodash/.internal/baseMergeDeep.js b/libs/lodash/.internal/baseMergeDeep.js new file mode 100644 index 0000000..445bddc --- /dev/null +++ b/libs/lodash/.internal/baseMergeDeep.js @@ -0,0 +1,91 @@ +import assignMergeValue from './assignMergeValue.js' +import cloneBuffer from './cloneBuffer.js' +import cloneTypedArray from './cloneTypedArray.js' +import copyArray from './copyArray.js' +import initCloneObject from './initCloneObject.js' +import isArguments from '../isArguments.js' +import isArrayLikeObject from '../isArrayLikeObject.js' +import isBuffer from '../isBuffer.js' +import isObject from '../isObject.js' +import isPlainObject from '../isPlainObject.js' +import isTypedArray from '../isTypedArray.js' +import toPlainObject from '../toPlainObject.js' + +/** + * A specialized version of `baseMerge` for arrays and objects which performs + * deep merges and tracks traversed objects enabling objects with circular + * references to be merged. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {string} key The key of the value to merge. + * @param {number} srcIndex The index of `source`. + * @param {Function} mergeFunc The function to merge values. + * @param {Function} [customizer] The function to customize assigned values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ +function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { + const objValue = object[key] + const srcValue = source[key] + const stacked = stack.get(srcValue) + + if (stacked) { + assignMergeValue(object, key, stacked) + return + } + let newValue = customizer + ? customizer(objValue, srcValue, `${key}`, object, source, stack) + : undefined + + let isCommon = newValue === undefined + + if (isCommon) { + const isArr = Array.isArray(srcValue) + const isBuff = !isArr && isBuffer(srcValue) + const isTyped = !isArr && !isBuff && isTypedArray(srcValue) + + newValue = srcValue + if (isArr || isBuff || isTyped) { + if (Array.isArray(objValue)) { + newValue = objValue + } + else if (isArrayLikeObject(objValue)) { + newValue = copyArray(objValue) + } + else if (isBuff) { + isCommon = false + newValue = cloneBuffer(srcValue, true) + } + else if (isTyped) { + isCommon = false + newValue = cloneTypedArray(srcValue, true) + } + else { + newValue = [] + } + } + else if (isPlainObject(srcValue) || isArguments(srcValue)) { + newValue = objValue + if (isArguments(objValue)) { + newValue = toPlainObject(objValue) + } + else if (typeof objValue === 'function' || !isObject(objValue)) { + newValue = initCloneObject(srcValue) + } + } + else { + isCommon = false + } + } + if (isCommon) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue) + mergeFunc(newValue, srcValue, srcIndex, customizer, stack) + stack['delete'](srcValue) + } + assignMergeValue(object, key, newValue) +} + +export default baseMergeDeep diff --git a/libs/lodash/.internal/baseOrderBy.js b/libs/lodash/.internal/baseOrderBy.js new file mode 100644 index 0000000..439e06b --- /dev/null +++ b/libs/lodash/.internal/baseOrderBy.js @@ -0,0 +1,49 @@ +import baseEach from './baseEach.js' +import baseSortBy from './baseSortBy.js' +import baseGet from './baseGet.js' +import compareMultiple from './compareMultiple.js' +import isArrayLike from '../isArrayLike.js' + +const identity = (value) => value + +/** + * The base implementation of `orderBy` without param guards. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. + * @param {string[]} orders The sort orders of `iteratees`. + * @returns {Array} Returns the new sorted array. + */ +function baseOrderBy(collection, iteratees, orders) { + if (iteratees.length) { + iteratees = iteratees.map((iteratee) => { + if (Array.isArray(iteratee)) { + return (value) => baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee) + } + + return iteratee + }) + } else { + iteratees = [identity] + } + + let criteriaIndex = -1 + let eachIndex = -1 + + const result = isArrayLike(collection) ? new Array(collection.length) : [] + + baseEach(collection, (value) => { + const criteria = iteratees.map((iteratee) => iteratee(value)) + + result[++eachIndex] = { + criteria, + index: ++criteriaIndex, + value + } + }) + + return baseSortBy(result, (object, other) => compareMultiple(object, other, orders)) +} + +export default baseOrderBy diff --git a/libs/lodash/.internal/basePick.js b/libs/lodash/.internal/basePick.js new file mode 100644 index 0000000..813523c --- /dev/null +++ b/libs/lodash/.internal/basePick.js @@ -0,0 +1,17 @@ +import basePickBy from './basePickBy.js' +import hasIn from '../hasIn.js' + +/** + * The base implementation of `pick` without support for individual + * property identifiers. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @returns {Object} Returns the new object. + */ +function basePick(object, paths) { + return basePickBy(object, paths, (value, path) => hasIn(object, path)) +} + +export default basePick diff --git a/libs/lodash/.internal/basePickBy.js b/libs/lodash/.internal/basePickBy.js new file mode 100644 index 0000000..4b1f7cb --- /dev/null +++ b/libs/lodash/.internal/basePickBy.js @@ -0,0 +1,29 @@ +import baseGet from './baseGet.js' +import baseSet from './baseSet.js' +import castPath from './castPath.js' + +/** + * The base implementation of `pickBy`. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @param {Function} predicate The function invoked per property. + * @returns {Object} Returns the new object. + */ +function basePickBy(object, paths, predicate) { + let index = -1 + const length = paths.length + const result = {} + + while (++index < length) { + const path = paths[index] + const value = baseGet(object, path) + if (predicate(value, path)) { + baseSet(result, castPath(path, object), value) + } + } + return result +} + +export default basePickBy diff --git a/libs/lodash/.internal/baseProperty.js b/libs/lodash/.internal/baseProperty.js new file mode 100644 index 0000000..48b94ce --- /dev/null +++ b/libs/lodash/.internal/baseProperty.js @@ -0,0 +1,12 @@ +/** + * The base implementation of `property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ +function baseProperty(key) { + return (object) => object == null ? undefined : object[key] +} + +export default baseProperty diff --git a/libs/lodash/.internal/basePropertyDeep.js b/libs/lodash/.internal/basePropertyDeep.js new file mode 100644 index 0000000..32a12b9 --- /dev/null +++ b/libs/lodash/.internal/basePropertyDeep.js @@ -0,0 +1,14 @@ +import baseGet from './baseGet.js' + +/** + * A specialized version of `baseProperty` which supports deep paths. + * + * @private + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new accessor function. + */ +function basePropertyDeep(path) { + return (object) => baseGet(object, path) +} + +export default basePropertyDeep diff --git a/libs/lodash/.internal/basePropertyOf.js b/libs/lodash/.internal/basePropertyOf.js new file mode 100644 index 0000000..a948529 --- /dev/null +++ b/libs/lodash/.internal/basePropertyOf.js @@ -0,0 +1,12 @@ +/** + * The base implementation of `propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ +function basePropertyOf(object) { + return (key) => object == null ? undefined : object[key] +} + +export default basePropertyOf diff --git a/libs/lodash/.internal/basePullAll.js b/libs/lodash/.internal/basePullAll.js new file mode 100644 index 0000000..1121e47 --- /dev/null +++ b/libs/lodash/.internal/basePullAll.js @@ -0,0 +1,44 @@ +import map from '../map.js' +import baseIndexOf from './baseIndexOf.js' +import baseIndexOfWith from './baseIndexOfWith.js' +import copyArray from './copyArray.js' + +/** + * The base implementation of `pullAllBy`. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + */ +function basePullAll(array, values, iteratee, comparator) { + const indexOf = comparator ? baseIndexOfWith : baseIndexOf + const length = values.length + + let index = -1 + let seen = array + + if (array === values) { + values = copyArray(values) + } + if (iteratee) { + seen = map(array, (value) => iteratee(value)) + } + while (++index < length) { + let fromIndex = 0 + const value = values[index] + const computed = iteratee ? iteratee(value) : value + + while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { + if (seen !== array) { + seen.splice(fromIndex, 1) + } + array.splice(fromIndex, 1) + } + } + return array +} + +export default basePullAll diff --git a/libs/lodash/.internal/basePullAt.js b/libs/lodash/.internal/basePullAt.js new file mode 100644 index 0000000..c93b5d4 --- /dev/null +++ b/libs/lodash/.internal/basePullAt.js @@ -0,0 +1,32 @@ +import baseUnset from './baseUnset.js' +import isIndex from './isIndex.js' + +/** + * The base implementation of `pullAt` without support for individual + * indexes or capturing the removed elements. + * + * @private + * @param {Array} array The array to modify. + * @param {number[]} indexes The indexes of elements to remove. + * @returns {Array} Returns `array`. + */ +function basePullAt(array, indexes) { + let length = array ? indexes.length : 0 + const lastIndex = length - 1 + + while (length--) { + let previous + const index = indexes[length] + if (length === lastIndex || index !== previous) { + previous = index + if (isIndex(index)) { + array.splice(index, 1) + } else { + baseUnset(array, index) + } + } + } + return array +} + +export default basePullAt diff --git a/libs/lodash/.internal/baseRange.js b/libs/lodash/.internal/baseRange.js new file mode 100644 index 0000000..94491b4 --- /dev/null +++ b/libs/lodash/.internal/baseRange.js @@ -0,0 +1,24 @@ +/** + * The base implementation of `range` and `rangeRight` which doesn't + * coerce arguments. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the range of numbers. + */ +function baseRange(start, end, step, fromRight) { + let index = -1 + let length = Math.max(Math.ceil((end - start) / (step || 1)), 0) + const result = new Array(length) + + while (length--) { + result[fromRight ? length : ++index] = start + start += step + } + return result +} + +export default baseRange diff --git a/libs/lodash/.internal/baseReduce.js b/libs/lodash/.internal/baseReduce.js new file mode 100644 index 0000000..8c643ce --- /dev/null +++ b/libs/lodash/.internal/baseReduce.js @@ -0,0 +1,23 @@ +/** + * The base implementation of `reduce` and `reduceRight` which iterates + * over `collection` using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} accumulator The initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the accumulated value. + */ +function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { + eachFunc(collection, (value, index, collection) => { + accumulator = initAccum + ? (initAccum = false, value) + : iteratee(accumulator, value, index, collection) + }) + return accumulator +} + +export default baseReduce diff --git a/libs/lodash/.internal/baseSet.js b/libs/lodash/.internal/baseSet.js new file mode 100644 index 0000000..92bad87 --- /dev/null +++ b/libs/lodash/.internal/baseSet.js @@ -0,0 +1,48 @@ +import assignValue from './assignValue.js' +import castPath from './castPath.js' +import isIndex from './isIndex.js' +import isObject from '../isObject.js' +import toKey from './toKey.js' + +/** + * The base implementation of `set`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ +function baseSet(object, path, value, customizer) { + if (!isObject(object)) { + return object + } + path = castPath(path, object) + + const length = path.length + const lastIndex = length - 1 + + let index = -1 + let nested = object + + while (nested != null && ++index < length) { + const key = toKey(path[index]) + let newValue = value + + if (index != lastIndex) { + const objValue = nested[key] + newValue = customizer ? customizer(objValue, key, nested) : undefined + if (newValue === undefined) { + newValue = isObject(objValue) + ? objValue + : (isIndex(path[index + 1]) ? [] : {}) + } + } + assignValue(nested, key, newValue) + nested = nested[key] + } + return object +} + +export default baseSet diff --git a/libs/lodash/.internal/baseSortBy.js b/libs/lodash/.internal/baseSortBy.js new file mode 100644 index 0000000..9c1ed89 --- /dev/null +++ b/libs/lodash/.internal/baseSortBy.js @@ -0,0 +1,21 @@ +/** + * The base implementation of `sortBy` which uses `comparer` to define the + * sort order of `array` and replaces criteria objects with their corresponding + * values. + * + * @private + * @param {Array} array The array to sort. + * @param {Function} comparer The function to define sort order. + * @returns {Array} Returns `array`. + */ +function baseSortBy(array, comparer) { + let { length } = array + + array.sort(comparer) + while (length--) { + array[length] = array[length].value + } + return array +} + +export default baseSortBy diff --git a/libs/lodash/.internal/baseSortedIndex.js b/libs/lodash/.internal/baseSortedIndex.js new file mode 100644 index 0000000..865e3be --- /dev/null +++ b/libs/lodash/.internal/baseSortedIndex.js @@ -0,0 +1,40 @@ +import baseSortedIndexBy from './baseSortedIndexBy.js' +import isSymbol from '../isSymbol.js' + +/** Used as references for the maximum length and index of an array. */ +const MAX_ARRAY_LENGTH = 4294967295 +const HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1 + +/** + * The base implementation of `sortedIndex` and `sortedLastIndex` which + * performs a binary search of `array` to determine the index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ +function baseSortedIndex(array, value, retHighest) { + let low = 0 + let high = array == null ? low : array.length + + if (typeof value === 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { + while (low < high) { + const mid = (low + high) >>> 1 + const computed = array[mid] + if (computed !== null && !isSymbol(computed) && + (retHighest ? (computed <= value) : (computed < value))) { + low = mid + 1 + } else { + high = mid + } + } + return high + } + return baseSortedIndexBy(array, value, (value) => value, retHighest) +} + +export default baseSortedIndex diff --git a/libs/lodash/.internal/baseSortedIndexBy.js b/libs/lodash/.internal/baseSortedIndexBy.js new file mode 100644 index 0000000..4f3f849 --- /dev/null +++ b/libs/lodash/.internal/baseSortedIndexBy.js @@ -0,0 +1,65 @@ +import isSymbol from '../isSymbol.js' + +/** Used as references for the maximum length and index of an array. */ +const MAX_ARRAY_LENGTH = 4294967295 +const MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1 + +/** + * The base implementation of `sortedIndexBy` and `sortedLastIndexBy` + * which invokes `iteratee` for `value` and each element of `array` to compute + * their sort ranking. The iteratee is invoked with one argument (value). + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iteratee The iteratee invoked per element. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ +function baseSortedIndexBy(array, value, iteratee, retHighest) { + let low = 0 + let high = array == null ? 0 : array.length + if (high == 0) { + return 0 + } + + value = iteratee(value) + + const valIsNaN = value !== value + const valIsNull = value === null + const valIsSymbol = isSymbol(value) + const valIsUndefined = value === undefined + + while (low < high) { + let setLow + const mid = Math.floor((low + high) / 2) + const computed = iteratee(array[mid]) + const othIsDefined = computed !== undefined + const othIsNull = computed === null + const othIsReflexive = computed === computed + const othIsSymbol = isSymbol(computed) + + if (valIsNaN) { + setLow = retHighest || othIsReflexive + } else if (valIsUndefined) { + setLow = othIsReflexive && (retHighest || othIsDefined) + } else if (valIsNull) { + setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull) + } else if (valIsSymbol) { + setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol) + } else if (othIsNull || othIsSymbol) { + setLow = false + } else { + setLow = retHighest ? (computed <= value) : (computed < value) + } + if (setLow) { + low = mid + 1 + } else { + high = mid + } + } + return Math.min(high, MAX_ARRAY_INDEX) +} + +export default baseSortedIndexBy diff --git a/libs/lodash/.internal/baseSortedUniq.js b/libs/lodash/.internal/baseSortedUniq.js new file mode 100644 index 0000000..6539330 --- /dev/null +++ b/libs/lodash/.internal/baseSortedUniq.js @@ -0,0 +1,29 @@ +import eq from '../eq.js' + +/** + * The base implementation of `sortedUniq` and `sortedUniqBy`. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ +function baseSortedUniq(array, iteratee) { + let seen + let index = -1 + let resIndex = 0 + + const { length } = array + const result = [] + + while (++index < length) { + const value = array[index], computed = iteratee ? iteratee(value) : value + if (!index || !eq(computed, seen)) { + seen = computed + result[resIndex++] = value === 0 ? 0 : value + } + } + return result +} + +export default baseSortedUniq diff --git a/libs/lodash/.internal/baseSum.js b/libs/lodash/.internal/baseSum.js new file mode 100644 index 0000000..dbb6f61 --- /dev/null +++ b/libs/lodash/.internal/baseSum.js @@ -0,0 +1,21 @@ +/** + * The base implementation of `sum` and `sumBy`. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the sum. + */ +function baseSum(array, iteratee) { + let result + + for (const value of array) { + const current = iteratee(value) + if (current !== undefined) { + result = result === undefined ? current : (result + current) + } + } + return result +} + +export default baseSum diff --git a/libs/lodash/.internal/baseToNumber.js b/libs/lodash/.internal/baseToNumber.js new file mode 100644 index 0000000..a3b5890 --- /dev/null +++ b/libs/lodash/.internal/baseToNumber.js @@ -0,0 +1,24 @@ +import isSymbol from '../isSymbol.js' + +/** Used as references for various `Number` constants. */ +const NAN = 0 / 0 + +/** + * The base implementation of `toNumber` which doesn't ensure correct + * conversions of binary, hexadecimal, or octal string values. + * + * @private + * @param {*} value The value to process. + * @returns {number} Returns the number. + */ +function baseToNumber(value) { + if (typeof value === 'number') { + return value + } + if (isSymbol(value)) { + return NAN + } + return +value +} + +export default baseToNumber diff --git a/libs/lodash/.internal/baseToString.js b/libs/lodash/.internal/baseToString.js new file mode 100644 index 0000000..e472f11 --- /dev/null +++ b/libs/lodash/.internal/baseToString.js @@ -0,0 +1,33 @@ +import isSymbol from '../isSymbol.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** Used to convert symbols to primitives and strings. */ +const symbolToString = Symbol.prototype.toString + +/** + * The base implementation of `toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ +function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value === 'string') { + return value + } + if (Array.isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return `${value.map(baseToString)}` + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : '' + } + const result = `${value}` + return (result === '0' && (1 / value) === -INFINITY) ? '-0' : result +} + +export default baseToString diff --git a/libs/lodash/.internal/baseUniq.js b/libs/lodash/.internal/baseUniq.js new file mode 100644 index 0000000..d933bb8 --- /dev/null +++ b/libs/lodash/.internal/baseUniq.js @@ -0,0 +1,73 @@ +import SetCache from './SetCache.js' +import arrayIncludes from './arrayIncludes.js' +import arrayIncludesWith from './arrayIncludesWith.js' +import cacheHas from './cacheHas.js' +import createSet from './createSet.js' +import setToArray from './setToArray.js' + +/** Used as the size to enable large array optimizations. */ +const LARGE_ARRAY_SIZE = 200 + +/** + * The base implementation of `uniqBy`. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ +function baseUniq(array, iteratee, comparator) { + let index = -1 + let includes = arrayIncludes + let isCommon = true + + const { length } = array + const result = [] + let seen = result + + if (comparator) { + isCommon = false + includes = arrayIncludesWith + } + else if (length >= LARGE_ARRAY_SIZE) { + const set = iteratee ? null : createSet(array) + if (set) { + return setToArray(set) + } + isCommon = false + includes = cacheHas + seen = new SetCache + } + else { + seen = iteratee ? [] : result + } + outer: + while (++index < length) { + let value = array[index] + const computed = iteratee ? iteratee(value) : value + + value = (comparator || value !== 0) ? value : 0 + if (isCommon && computed === computed) { + let seenIndex = seen.length + while (seenIndex--) { + if (seen[seenIndex] === computed) { + continue outer + } + } + if (iteratee) { + seen.push(computed) + } + result.push(value) + } + else if (!includes(seen, computed, comparator)) { + if (seen !== result) { + seen.push(computed) + } + result.push(value) + } + } + return result +} + +export default baseUniq diff --git a/libs/lodash/.internal/baseUnset.js b/libs/lodash/.internal/baseUnset.js new file mode 100644 index 0000000..85a929f --- /dev/null +++ b/libs/lodash/.internal/baseUnset.js @@ -0,0 +1,20 @@ +import castPath from './castPath.js' +import last from '../last.js' +import parent from './parent.js' +import toKey from './toKey.js' + +/** + * The base implementation of `unset`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The property path to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + */ +function baseUnset(object, path) { + path = castPath(path, object) + object = parent(object, path) + return object == null || delete object[toKey(last(path))] +} + +export default baseUnset diff --git a/libs/lodash/.internal/baseUpdate.js b/libs/lodash/.internal/baseUpdate.js new file mode 100644 index 0000000..5ec0573 --- /dev/null +++ b/libs/lodash/.internal/baseUpdate.js @@ -0,0 +1,18 @@ +import baseGet from './baseGet.js' +import baseSet from './baseSet.js' + +/** + * The base implementation of `update`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to update. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ +function baseUpdate(object, path, updater, customizer) { + return baseSet(object, path, updater(baseGet(object, path)), customizer) +} + +export default baseUpdate diff --git a/libs/lodash/.internal/baseValues.js b/libs/lodash/.internal/baseValues.js new file mode 100644 index 0000000..8809d33 --- /dev/null +++ b/libs/lodash/.internal/baseValues.js @@ -0,0 +1,15 @@ +/** + * The base implementation of `values` and `valuesIn` which creates an + * array of `object` property values corresponding to the property names + * of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the array of property values. + */ +function baseValues(object, props) { + return props == null ? [] : props.map((key) => object[key]) +} + +export default baseValues diff --git a/libs/lodash/.internal/baseWhile.js b/libs/lodash/.internal/baseWhile.js new file mode 100644 index 0000000..a024ffb --- /dev/null +++ b/libs/lodash/.internal/baseWhile.js @@ -0,0 +1,25 @@ +import slice from '../slice.js' + +/** + * The base implementation of methods like `dropWhile` and `takeWhile`. + * + * @private + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @param {boolean} [isDrop] Specify dropping elements instead of taking them. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the slice of `array`. + */ +function baseWhile(array, predicate, isDrop, fromRight) { + const { length } = array + let index = fromRight ? length : -1 + + while ((fromRight ? index-- : ++index < length) && + predicate(array[index], index, array)) {} + + return isDrop + ? slice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) + : slice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)) +} + +export default baseWhile diff --git a/libs/lodash/.internal/baseXor.js b/libs/lodash/.internal/baseXor.js new file mode 100644 index 0000000..41493ac --- /dev/null +++ b/libs/lodash/.internal/baseXor.js @@ -0,0 +1,36 @@ +import baseDifference from './baseDifference.js' +import baseFlatten from './baseFlatten.js' +import baseUniq from './baseUniq.js' + +/** + * The base implementation of methods like `xor` which accepts an array of + * arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of values. + */ +function baseXor(arrays, iteratee, comparator) { + const length = arrays.length + if (length < 2) { + return length ? baseUniq(arrays[0]) : [] + } + let index = -1 + const result = new Array(length) + + while (++index < length) { + const array = arrays[index] + let othIndex = -1 + + while (++othIndex < length) { + if (othIndex != index) { + result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator) + } + } + } + return baseUniq(baseFlatten(result, 1), iteratee, comparator) +} + +export default baseXor diff --git a/libs/lodash/.internal/baseZipObject.js b/libs/lodash/.internal/baseZipObject.js new file mode 100644 index 0000000..6cf4dc3 --- /dev/null +++ b/libs/lodash/.internal/baseZipObject.js @@ -0,0 +1,23 @@ +/** + * This base implementation of `zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ +function baseZipObject(props, values, assignFunc) { + let index = -1 + const length = props.length + const valsLength = values.length + const result = {} + + while (++index < length) { + const value = index < valsLength ? values[index] : undefined + assignFunc(result, props[index], value) + } + return result +} + +export default baseZipObject diff --git a/libs/lodash/.internal/cacheHas.js b/libs/lodash/.internal/cacheHas.js new file mode 100644 index 0000000..553369f --- /dev/null +++ b/libs/lodash/.internal/cacheHas.js @@ -0,0 +1,13 @@ +/** + * Checks if a `cache` value for `key` exists. + * + * @private + * @param {Object} cache The cache to query. + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ +function cacheHas(cache, key) { + return cache.has(key) +} + +export default cacheHas diff --git a/libs/lodash/.internal/castArrayLikeObject.js b/libs/lodash/.internal/castArrayLikeObject.js new file mode 100644 index 0000000..9c120dc --- /dev/null +++ b/libs/lodash/.internal/castArrayLikeObject.js @@ -0,0 +1,14 @@ +import isArrayLikeObject from '../isArrayLikeObject.js' + +/** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ +function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : [] +} + +export default castArrayLikeObject diff --git a/libs/lodash/.internal/castPath.js b/libs/lodash/.internal/castPath.js new file mode 100644 index 0000000..edba410 --- /dev/null +++ b/libs/lodash/.internal/castPath.js @@ -0,0 +1,19 @@ +import isKey from './isKey.js' +import stringToPath from './stringToPath.js' + +/** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @param {Object} [object] The object to query keys on. + * @returns {Array} Returns the cast property path array. + */ +function castPath(value, object) { + if (Array.isArray(value)) { + return value + } + return isKey(value, object) ? [value] : stringToPath(value) +} + +export default castPath diff --git a/libs/lodash/.internal/castSlice.js b/libs/lodash/.internal/castSlice.js new file mode 100644 index 0000000..56a0699 --- /dev/null +++ b/libs/lodash/.internal/castSlice.js @@ -0,0 +1,18 @@ +import slice from '../slice.js' + +/** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ +function castSlice(array, start, end) { + const { length } = array + end = end === undefined ? length : end + return (!start && end >= length) ? array : slice(array, start, end) +} + +export default castSlice diff --git a/libs/lodash/.internal/charsEndIndex.js b/libs/lodash/.internal/charsEndIndex.js new file mode 100644 index 0000000..add260a --- /dev/null +++ b/libs/lodash/.internal/charsEndIndex.js @@ -0,0 +1,19 @@ +import baseIndexOf from './baseIndexOf.js' + +/** + * Used by `trim` and `trimEnd` to get the index of the last string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the last unmatched string symbol. + */ +function charsEndIndex(strSymbols, chrSymbols) { + let index = strSymbols.length + + while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index +} + +export default charsEndIndex diff --git a/libs/lodash/.internal/charsStartIndex.js b/libs/lodash/.internal/charsStartIndex.js new file mode 100644 index 0000000..e8ad163 --- /dev/null +++ b/libs/lodash/.internal/charsStartIndex.js @@ -0,0 +1,20 @@ +import baseIndexOf from './baseIndexOf.js' + +/** + * Used by `trim` and `trimStart` to get the index of the first string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the first unmatched string symbol. + */ +function charsStartIndex(strSymbols, chrSymbols) { + let index = -1 + const length = strSymbols.length + + while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index +} + +export default charsStartIndex diff --git a/libs/lodash/.internal/cloneArrayBuffer.js b/libs/lodash/.internal/cloneArrayBuffer.js new file mode 100644 index 0000000..8aff89e --- /dev/null +++ b/libs/lodash/.internal/cloneArrayBuffer.js @@ -0,0 +1,14 @@ +/** + * Creates a clone of `arrayBuffer`. + * + * @private + * @param {ArrayBuffer} arrayBuffer The array buffer to clone. + * @returns {ArrayBuffer} Returns the cloned array buffer. + */ +function cloneArrayBuffer(arrayBuffer) { + const result = new arrayBuffer.constructor(arrayBuffer.byteLength) + new Uint8Array(result).set(new Uint8Array(arrayBuffer)) + return result +} + +export default cloneArrayBuffer diff --git a/libs/lodash/.internal/cloneBuffer.js b/libs/lodash/.internal/cloneBuffer.js new file mode 100644 index 0000000..f1be8b5 --- /dev/null +++ b/libs/lodash/.internal/cloneBuffer.js @@ -0,0 +1,34 @@ +import root from './root.js' + +/** Detect free variable `exports`. */ +const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports + +/** Detect free variable `module`. */ +const freeModule = freeExports && typeof module === 'object' && module !== null && !module.nodeType && module + +/** Detect the popular CommonJS extension `module.exports`. */ +const moduleExports = freeModule && freeModule.exports === freeExports + +/** Built-in value references. */ +const Buffer = moduleExports ? root.Buffer : undefined, allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined + +/** + * Creates a clone of `buffer`. + * + * @private + * @param {Buffer} buffer The buffer to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Buffer} Returns the cloned buffer. + */ +function cloneBuffer(buffer, isDeep) { + if (isDeep) { + return buffer.slice() + } + const length = buffer.length + const result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length) + + buffer.copy(result) + return result +} + +export default cloneBuffer diff --git a/libs/lodash/.internal/cloneDataView.js b/libs/lodash/.internal/cloneDataView.js new file mode 100644 index 0000000..8b2a2a2 --- /dev/null +++ b/libs/lodash/.internal/cloneDataView.js @@ -0,0 +1,16 @@ +import cloneArrayBuffer from './cloneArrayBuffer.js' + +/** + * Creates a clone of `dataView`. + * + * @private + * @param {Object} dataView The data view to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned data view. + */ +function cloneDataView(dataView, isDeep) { + const buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer + return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength) +} + +export default cloneDataView diff --git a/libs/lodash/.internal/cloneRegExp.js b/libs/lodash/.internal/cloneRegExp.js new file mode 100644 index 0000000..6552bc2 --- /dev/null +++ b/libs/lodash/.internal/cloneRegExp.js @@ -0,0 +1,17 @@ +/** Used to match `RegExp` flags from their coerced string values. */ +const reFlags = /\w*$/ + +/** + * Creates a clone of `regexp`. + * + * @private + * @param {Object} regexp The regexp to clone. + * @returns {Object} Returns the cloned regexp. + */ +function cloneRegExp(regexp) { + const result = new regexp.constructor(regexp.source, reFlags.exec(regexp)) + result.lastIndex = regexp.lastIndex + return result +} + +export default cloneRegExp diff --git a/libs/lodash/.internal/cloneSymbol.js b/libs/lodash/.internal/cloneSymbol.js new file mode 100644 index 0000000..fd86d19 --- /dev/null +++ b/libs/lodash/.internal/cloneSymbol.js @@ -0,0 +1,15 @@ +/** Used to convert symbols to primitives and strings. */ +const symbolValueOf = Symbol.prototype.valueOf + +/** + * Creates a clone of the `symbol` object. + * + * @private + * @param {Object} symbol The symbol object to clone. + * @returns {Object} Returns the cloned symbol object. + */ +function cloneSymbol(symbol) { + return Object(symbolValueOf.call(symbol)) +} + +export default cloneSymbol diff --git a/libs/lodash/.internal/cloneTypedArray.js b/libs/lodash/.internal/cloneTypedArray.js new file mode 100644 index 0000000..62ddc38 --- /dev/null +++ b/libs/lodash/.internal/cloneTypedArray.js @@ -0,0 +1,16 @@ +import cloneArrayBuffer from './cloneArrayBuffer.js' + +/** + * Creates a clone of `typedArray`. + * + * @private + * @param {Object} typedArray The typed array to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned typed array. + */ +function cloneTypedArray(typedArray, isDeep) { + const buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer + return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length) +} + +export default cloneTypedArray diff --git a/libs/lodash/.internal/compareAscending.js b/libs/lodash/.internal/compareAscending.js new file mode 100644 index 0000000..d183976 --- /dev/null +++ b/libs/lodash/.internal/compareAscending.js @@ -0,0 +1,45 @@ +import isSymbol from '../isSymbol.js' + +/** + * Compares values to sort them in ascending order. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {number} Returns the sort order indicator for `value`. + */ +function compareAscending(value, other) { + if (value !== other) { + const valIsDefined = value !== undefined + const valIsNull = value === null + const valIsReflexive = value === value + const valIsSymbol = isSymbol(value) + + const othIsDefined = other !== undefined + const othIsNull = other === null + const othIsReflexive = other === other + const othIsSymbol = isSymbol(other) + + const val = typeof value === 'string' + ? value.localeCompare(other) + : -other + + if ((!othIsNull && !othIsSymbol && !valIsSymbol && val > 0) || + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || + !valIsReflexive) { + return 1 + } + if ((!valIsNull && !valIsSymbol && !othIsSymbol && val < 0) || + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || + !othIsReflexive) { + return -1 + } + } + return 0 +} + +export default compareAscending diff --git a/libs/lodash/.internal/compareMultiple.js b/libs/lodash/.internal/compareMultiple.js new file mode 100644 index 0000000..0d9fc2d --- /dev/null +++ b/libs/lodash/.internal/compareMultiple.js @@ -0,0 +1,45 @@ +import compareAscending from './compareAscending.js' + +/** + * Used by `orderBy` to compare multiple properties of a value to another + * and stable sort them. + * + * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, + * specify an order of "desc" for descending or "asc" for ascending sort order + * of corresponding values. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {(string|function)[]} orders The order to sort by for each property. + * @returns {number} Returns the sort order indicator for `object`. + */ +function compareMultiple(object, other, orders) { + let index = -1 + const objCriteria = object.criteria + const othCriteria = other.criteria + const length = objCriteria.length + const ordersLength = orders.length + + while (++index < length) { + const order = index < ordersLength ? orders[index] : null + const cmpFn = (order && typeof order === 'function') ? order: compareAscending + const result = cmpFn(objCriteria[index], othCriteria[index]) + if (result) { + if (order && typeof order !== 'function') { + return result * (order == 'desc' ? -1 : 1) + } + return result + } + } + // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications + // that causes it, under certain circumstances, to provide the same value for + // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 + // for more details. + // + // This also ensures a stable sort in V8 and other engines. + // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. + return object.index - other.index +} + +export default compareMultiple diff --git a/libs/lodash/.internal/composeArgs.js b/libs/lodash/.internal/composeArgs.js new file mode 100644 index 0000000..1b0406e --- /dev/null +++ b/libs/lodash/.internal/composeArgs.js @@ -0,0 +1,38 @@ +/** + * Creates an array that is the composition of partially applied arguments, + * placeholders, and provided arguments into a single array of arguments. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to prepend to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ +function composeArgs(args, partials, holders, isCurried) { + const argsLength = args.length + const holdersLength = holders.length + const leftLength = partials.length + + let argsIndex = -1 + let leftIndex = -1 + let rangeLength = Math.max(argsLength - holdersLength, 0) + + const result = new Array(leftLength + rangeLength) + const isUncurried = !isCurried + + while (++leftIndex < leftLength) { + result[leftIndex] = partials[leftIndex] + } + while (++argsIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[holders[argsIndex]] = args[argsIndex] + } + } + while (rangeLength--) { + result[leftIndex++] = args[argsIndex++] + } + return result +} + +export default composeArgs diff --git a/libs/lodash/.internal/composeArgsRight.js b/libs/lodash/.internal/composeArgsRight.js new file mode 100644 index 0000000..7e037c1 --- /dev/null +++ b/libs/lodash/.internal/composeArgsRight.js @@ -0,0 +1,39 @@ +/** + * This function is like `composeArgs` except that the arguments composition + * is tailored for `partialRight`. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to append to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ +function composeArgsRight(args, partials, holders, isCurried) { + let argsIndex = -1 + let holdersIndex = -1 + let rightIndex = -1 + + const argsLength = args.length + const holdersLength = holders.length + const rightLength = partials.length + const rangeLength = Math.max(argsLength - holdersLength, 0) + const result = new Array(rangeLength + rightLength) + const isUncurried = !isCurried + + while (++argsIndex < rangeLength) { + result[argsIndex] = args[argsIndex] + } + const offset = argsIndex + while (++rightIndex < rightLength) { + result[offset + rightIndex] = partials[rightIndex] + } + while (++holdersIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[offset + holders[holdersIndex]] = args[argsIndex++] + } + } + return result +} + +export default composeArgsRight diff --git a/libs/lodash/.internal/copyArray.js b/libs/lodash/.internal/copyArray.js new file mode 100644 index 0000000..408503b --- /dev/null +++ b/libs/lodash/.internal/copyArray.js @@ -0,0 +1,20 @@ +/** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ +function copyArray(source, array) { + let index = -1 + const length = source.length + + array || (array = new Array(length)) + while (++index < length) { + array[index] = source[index] + } + return array +} + +export default copyArray diff --git a/libs/lodash/.internal/copyObject.js b/libs/lodash/.internal/copyObject.js new file mode 100644 index 0000000..bcabc9b --- /dev/null +++ b/libs/lodash/.internal/copyObject.js @@ -0,0 +1,35 @@ +import assignValue from './assignValue.js' +import baseAssignValue from './baseAssignValue.js' + +/** + * Copies properties of `source` to `object`. + * + * @private + * @param {Object} source The object to copy properties from. + * @param {Array} props The property identifiers to copy. + * @param {Object} [object={}] The object to copy properties to. + * @param {Function} [customizer] The function to customize copied values. + * @returns {Object} Returns `object`. + */ +function copyObject(source, props, object, customizer) { + const isNew = !object + object || (object = {}) + + for (const key of props) { + let newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : undefined + + if (newValue === undefined) { + newValue = source[key] + } + if (isNew) { + baseAssignValue(object, key, newValue) + } else { + assignValue(object, key, newValue) + } + } + return object +} + +export default copyObject diff --git a/libs/lodash/.internal/copySymbols.js b/libs/lodash/.internal/copySymbols.js new file mode 100644 index 0000000..319562c --- /dev/null +++ b/libs/lodash/.internal/copySymbols.js @@ -0,0 +1,16 @@ +import copyObject from './copyObject.js' +import getSymbols from './getSymbols.js' + +/** + * Copies own symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ +function copySymbols(source, object) { + return copyObject(source, getSymbols(source), object) +} + +export default copySymbols diff --git a/libs/lodash/.internal/copySymbolsIn.js b/libs/lodash/.internal/copySymbolsIn.js new file mode 100644 index 0000000..30ba034 --- /dev/null +++ b/libs/lodash/.internal/copySymbolsIn.js @@ -0,0 +1,16 @@ +import copyObject from './copyObject.js' +import getSymbolsIn from './getSymbolsIn.js' + +/** + * Copies own and inherited symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ +function copySymbolsIn(source, object) { + return copyObject(source, getSymbolsIn(source), object) +} + +export default copySymbolsIn diff --git a/libs/lodash/.internal/createAssigner.js b/libs/lodash/.internal/createAssigner.js new file mode 100644 index 0000000..b0bfe35 --- /dev/null +++ b/libs/lodash/.internal/createAssigner.js @@ -0,0 +1,36 @@ +import isIterateeCall from './isIterateeCall.js' + +/** + * Creates a function like `assign`. + * + * @private + * @param {Function} assigner The function to assign values. + * @returns {Function} Returns the new assigner function. + */ +function createAssigner(assigner) { + return (object, ...sources) => { + let index = -1 + let length = sources.length + let customizer = length > 1 ? sources[length - 1] : undefined + const guard = length > 2 ? sources[2] : undefined + + customizer = (assigner.length > 3 && typeof customizer === 'function') + ? (length--, customizer) + : undefined + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? undefined : customizer + length = 1 + } + object = Object(object) + while (++index < length) { + const source = sources[index] + if (source) { + assigner(object, source, index, customizer) + } + } + return object + } +} + +export default createAssigner diff --git a/libs/lodash/.internal/createCaseFirst.js b/libs/lodash/.internal/createCaseFirst.js new file mode 100644 index 0000000..2d4cfee --- /dev/null +++ b/libs/lodash/.internal/createCaseFirst.js @@ -0,0 +1,34 @@ +import castSlice from './castSlice.js' +import hasUnicode from './hasUnicode.js' +import stringToArray from './stringToArray.js' + +/** + * Creates a function like `lowerFirst`. + * + * @private + * @param {string} methodName The name of the `String` case method to use. + * @returns {Function} Returns the new case function. + */ +function createCaseFirst(methodName) { + return (string) => { + if (!string) { + return '' + } + + const strSymbols = hasUnicode(string) + ? stringToArray(string) + : undefined + + const chr = strSymbols + ? strSymbols[0] + : string[0] + + const trailing = strSymbols + ? castSlice(strSymbols, 1).join('') + : string.slice(1) + + return chr[methodName]() + trailing + } +} + +export default createCaseFirst diff --git a/libs/lodash/.internal/createMathOperation.js b/libs/lodash/.internal/createMathOperation.js new file mode 100644 index 0000000..d35ce6c --- /dev/null +++ b/libs/lodash/.internal/createMathOperation.js @@ -0,0 +1,35 @@ +import baseToNumber from './baseToNumber.js' +import baseToString from './baseToString.js' + +/** + * Creates a function that performs a mathematical operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @param {number} [defaultValue] The value used for `undefined` arguments. + * @returns {Function} Returns the new mathematical operation function. + */ +function createMathOperation(operator, defaultValue) { + return (value, other) => { + if (value === undefined && other === undefined) { + return defaultValue + } + if (value !== undefined && other === undefined) { + return value + } + if (other !== undefined && value === undefined) { + return other + } + if (typeof value === 'string' || typeof other === 'string') { + value = baseToString(value) + other = baseToString(other) + } + else { + value = baseToNumber(value) + other = baseToNumber(other) + } + return operator(value, other) + } +} + +export default createMathOperation diff --git a/libs/lodash/.internal/createPadding.js b/libs/lodash/.internal/createPadding.js new file mode 100644 index 0000000..099f0d7 --- /dev/null +++ b/libs/lodash/.internal/createPadding.js @@ -0,0 +1,30 @@ +import repeat from '../repeat.js' +import baseToString from './baseToString.js' +import castSlice from './castSlice.js' +import hasUnicode from './hasUnicode.js' +import stringSize from './stringSize.js' +import stringToArray from './stringToArray.js' + +/** + * Creates the padding for `string` based on `length`. The `chars` string + * is truncated if the number of characters exceeds `length`. + * + * @private + * @param {number} length The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padding for `string`. + */ +function createPadding(length, chars) { + chars = chars === undefined ? ' ' : baseToString(chars) + + const charsLength = chars.length + if (charsLength < 2) { + return charsLength ? repeat(chars, length) : chars + } + const result = repeat(chars, Math.ceil(length / stringSize(chars))) + return hasUnicode(chars) + ? castSlice(stringToArray(result), 0, length).join('') + : result.slice(0, length) +} + +export default createPadding diff --git a/libs/lodash/.internal/createRange.js b/libs/lodash/.internal/createRange.js new file mode 100644 index 0000000..dd46129 --- /dev/null +++ b/libs/lodash/.internal/createRange.js @@ -0,0 +1,26 @@ +import baseRange from './baseRange.js' +import toFinite from '../toFinite.js' + +/** + * Creates a `range` or `rangeRight` function. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new range function. + */ +function createRange(fromRight) { + return (start, end, step) => { + // Ensure the sign of `-0` is preserved. + start = toFinite(start) + if (end === undefined) { + end = start + start = 0 + } else { + end = toFinite(end) + } + step = step === undefined ? (start < end ? 1 : -1) : toFinite(step) + return baseRange(start, end, step, fromRight) + } +} + +export default createRange diff --git a/libs/lodash/.internal/createRound.js b/libs/lodash/.internal/createRound.js new file mode 100644 index 0000000..b520ba1 --- /dev/null +++ b/libs/lodash/.internal/createRound.js @@ -0,0 +1,25 @@ +/** + * Creates a function like `round`. + * + * @private + * @param {string} methodName The name of the `Math` method to use when rounding. + * @returns {Function} Returns the new round function. + */ +function createRound(methodName) { + const func = Math[methodName] + return (number, precision) => { + precision = precision == null ? 0 : (precision >= 0 ? Math.min(precision, 292) : Math.max(precision, -292)) + if (precision) { + // Shift with exponential notation to avoid floating-point issues. + // See [MDN](https://mdn.io/round#Examples) for more details. + let pair = `${number}e`.split('e') + const value = func(`${pair[0]}e${+pair[1] + precision}`) + + pair = `${value}e`.split('e') + return +`${pair[0]}e${+pair[1] - precision}` + } + return func(number) + } +} + +export default createRound diff --git a/libs/lodash/.internal/createSet.js b/libs/lodash/.internal/createSet.js new file mode 100644 index 0000000..0e86dc5 --- /dev/null +++ b/libs/lodash/.internal/createSet.js @@ -0,0 +1,17 @@ +import setToArray from './setToArray.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** + * Creates a set object of `values`. + * + * @private + * @param {Array} values The values to add to the set. + * @returns {Object} Returns the new set. + */ +const createSet = (Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) + ? (values) => new Set(values) + : () => {} + +export default createSet diff --git a/libs/lodash/.internal/customDefaultsMerge.js b/libs/lodash/.internal/customDefaultsMerge.js new file mode 100644 index 0000000..7a14251 --- /dev/null +++ b/libs/lodash/.internal/customDefaultsMerge.js @@ -0,0 +1,28 @@ +import baseMerge from './baseMerge.js' +import isObject from '../isObject.js' + +/** + * Used by `defaultsDeep` to customize its `merge` use to merge source + * objects into destination objects that are passed thru. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to merge. + * @param {Object} object The parent object of `objValue`. + * @param {Object} source The parent object of `srcValue`. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + * @returns {*} Returns the value to assign. + */ +function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { + if (isObject(objValue) && isObject(srcValue)) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue) + baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack) + stack['delete'](srcValue) + } + return objValue +} + +export default customDefaultsMerge diff --git a/libs/lodash/.internal/deburrLetter.js b/libs/lodash/.internal/deburrLetter.js new file mode 100644 index 0000000..fef37ad --- /dev/null +++ b/libs/lodash/.internal/deburrLetter.js @@ -0,0 +1,71 @@ +import basePropertyOf from './basePropertyOf.js' + +/** Used to map Latin Unicode letters to basic Latin letters. */ +const deburredLetters = { + // Latin-1 Supplement block. + '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', + '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', + '\xc7': 'C', '\xe7': 'c', + '\xd0': 'D', '\xf0': 'd', + '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', + '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', + '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', + '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', + '\xd1': 'N', '\xf1': 'n', + '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', + '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', + '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', + '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', + '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', + '\xc6': 'Ae', '\xe6': 'ae', + '\xde': 'Th', '\xfe': 'th', + '\xdf': 'ss', + // Latin Extended-A block. + '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', + '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', + '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', + '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', + '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', + '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', + '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', + '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', + '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', + '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', + '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', + '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', + '\u0134': 'J', '\u0135': 'j', + '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', + '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', + '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', + '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', + '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', + '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', + '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', + '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', + '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', + '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', + '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', + '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', + '\u0163': 't', '\u0165': 't', '\u0167': 't', + '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', + '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', + '\u0174': 'W', '\u0175': 'w', + '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', + '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', + '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', + '\u0132': 'IJ', '\u0133': 'ij', + '\u0152': 'Oe', '\u0153': 'oe', + '\u0149': "'n", '\u017f': 's' +} + +/** + * Used by `deburr` to convert Latin-1 Supplement and Latin Extended-A + * letters to basic Latin letters. + * + * @private + * @param {string} letter The matched letter to deburr. + * @returns {string} Returns the deburred letter. + */ +const deburrLetter = basePropertyOf(deburredLetters) + +export default deburrLetter diff --git a/libs/lodash/.internal/equalArrays.js b/libs/lodash/.internal/equalArrays.js new file mode 100644 index 0000000..fac53cb --- /dev/null +++ b/libs/lodash/.internal/equalArrays.js @@ -0,0 +1,84 @@ +import SetCache from './SetCache.js' +import some from '../some.js' +import cacheHas from './cacheHas.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 +const COMPARE_UNORDERED_FLAG = 2 + +/** + * A specialized version of `baseIsEqualDeep` for arrays with support for + * partial deep comparisons. + * + * @private + * @param {Array} array The array to compare. + * @param {Array} other The other array to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `array` and `other` objects. + * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. + */ +function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { + const isPartial = bitmask & COMPARE_PARTIAL_FLAG + const arrLength = array.length + const othLength = other.length + + if (arrLength != othLength && !(isPartial && othLength > arrLength)) { + return false + } + // Assume cyclic values are equal. + const stacked = stack.get(array) + if (stacked && stack.get(other)) { + return stacked == other + } + let index = -1 + let result = true + const seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined + + stack.set(array, other) + stack.set(other, array) + + // Ignore non-index properties. + while (++index < arrLength) { + let compared + const arrValue = array[index] + const othValue = other[index] + + if (customizer) { + compared = isPartial + ? customizer(othValue, arrValue, index, other, array, stack) + : customizer(arrValue, othValue, index, array, other, stack) + } + if (compared !== undefined) { + if (compared) { + continue + } + result = false + break + } + // Recursively compare arrays (susceptible to call stack limits). + if (seen) { + if (!some(other, (othValue, othIndex) => { + if (!cacheHas(seen, othIndex) && + (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { + return seen.push(othIndex) + } + })) { + result = false + break + } + } else if (!( + arrValue === othValue || + equalFunc(arrValue, othValue, bitmask, customizer, stack) + )) { + result = false + break + } + } + stack['delete'](array) + stack['delete'](other) + return result +} + +export default equalArrays diff --git a/libs/lodash/.internal/equalByTag.js b/libs/lodash/.internal/equalByTag.js new file mode 100644 index 0000000..fd8f80c --- /dev/null +++ b/libs/lodash/.internal/equalByTag.js @@ -0,0 +1,109 @@ +import eq from '../eq.js' +import equalArrays from './equalArrays.js' +import mapToArray from './mapToArray.js' +import setToArray from './setToArray.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 +const COMPARE_UNORDERED_FLAG = 2 + +/** `Object#toString` result references. */ +const boolTag = '[object Boolean]' +const dateTag = '[object Date]' +const errorTag = '[object Error]' +const mapTag = '[object Map]' +const numberTag = '[object Number]' +const regexpTag = '[object RegExp]' +const setTag = '[object Set]' +const stringTag = '[object String]' +const symbolTag = '[object Symbol]' + +const arrayBufferTag = '[object ArrayBuffer]' +const dataViewTag = '[object DataView]' + +/** Used to convert symbols to primitives and strings. */ +const symbolValueOf = Symbol.prototype.valueOf + +/** + * A specialized version of `baseIsEqualDeep` for comparing objects of + * the same `toStringTag`. + * + * **Note:** This function only supports comparing values with tags of + * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {string} tag The `toStringTag` of the objects to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { + switch (tag) { + case dataViewTag: + if ((object.byteLength != other.byteLength) || + (object.byteOffset != other.byteOffset)) { + return false + } + object = object.buffer + other = other.buffer + + case arrayBufferTag: + if ((object.byteLength != other.byteLength) || + !equalFunc(new Uint8Array(object), new Uint8Array(other))) { + return false + } + return true + + case boolTag: + case dateTag: + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other) + + case errorTag: + return object.name == other.name && object.message == other.message + + case regexpTag: + case stringTag: + // Coerce regexes to strings and treat strings, primitives and objects, + // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring + // for more details. + return object == `${other}` + + case mapTag: + let convert = mapToArray + + case setTag: + const isPartial = bitmask & COMPARE_PARTIAL_FLAG + convert || (convert = setToArray) + + if (object.size != other.size && !isPartial) { + return false + } + // Assume cyclic values are equal. + const stacked = stack.get(object) + if (stacked) { + return stacked == other + } + bitmask |= COMPARE_UNORDERED_FLAG + + // Recursively compare objects (susceptible to call stack limits). + stack.set(object, other) + const result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack) + stack['delete'](object) + return result + + case symbolTag: + if (symbolValueOf) { + return symbolValueOf.call(object) == symbolValueOf.call(other) + } + } + return false +} + +export default equalByTag diff --git a/libs/lodash/.internal/equalObjects.js b/libs/lodash/.internal/equalObjects.js new file mode 100644 index 0000000..8b884cd --- /dev/null +++ b/libs/lodash/.internal/equalObjects.js @@ -0,0 +1,88 @@ +import getAllKeys from './getAllKeys.js' + +/** Used to compose bitmasks for value comparisons. */ +const COMPARE_PARTIAL_FLAG = 1 + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * A specialized version of `baseIsEqualDeep` for objects with support for + * partial deep comparisons. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { + const isPartial = bitmask & COMPARE_PARTIAL_FLAG + const objProps = getAllKeys(object) + const objLength = objProps.length + const othProps = getAllKeys(other) + const othLength = othProps.length + + if (objLength != othLength && !isPartial) { + return false + } + let key + let index = objLength + while (index--) { + key = objProps[index] + if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { + return false + } + } + // Assume cyclic values are equal. + const stacked = stack.get(object) + if (stacked && stack.get(other)) { + return stacked == other + } + let result = true + stack.set(object, other) + stack.set(other, object) + + let compared + let skipCtor = isPartial + while (++index < objLength) { + key = objProps[index] + const objValue = object[key] + const othValue = other[key] + + if (customizer) { + compared = isPartial + ? customizer(othValue, objValue, key, other, object, stack) + : customizer(objValue, othValue, key, object, other, stack) + } + // Recursively compare objects (susceptible to call stack limits). + if (!(compared === undefined + ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) + : compared + )) { + result = false + break + } + skipCtor || (skipCtor = key == 'constructor') + } + if (result && !skipCtor) { + const objCtor = object.constructor + const othCtor = other.constructor + + // Non `Object` object instances with different constructors are not equal. + if (objCtor != othCtor && + ('constructor' in object && 'constructor' in other) && + !(typeof objCtor === 'function' && objCtor instanceof objCtor && + typeof othCtor === 'function' && othCtor instanceof othCtor)) { + result = false + } + } + stack['delete'](object) + stack['delete'](other) + return result +} + +export default equalObjects diff --git a/libs/lodash/.internal/freeGlobal.js b/libs/lodash/.internal/freeGlobal.js new file mode 100644 index 0000000..59519fe --- /dev/null +++ b/libs/lodash/.internal/freeGlobal.js @@ -0,0 +1,4 @@ +/** Detect free variable `global` from Node.js. */ +const freeGlobal = typeof global === 'object' && global !== null && global.Object === Object && global + +export default freeGlobal diff --git a/libs/lodash/.internal/getAllKeys.js b/libs/lodash/.internal/getAllKeys.js new file mode 100644 index 0000000..6c11a58 --- /dev/null +++ b/libs/lodash/.internal/getAllKeys.js @@ -0,0 +1,19 @@ +import getSymbols from './getSymbols.js' +import keys from '../keys.js' + +/** + * Creates an array of own enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ +function getAllKeys(object) { + const result = keys(object) + if (!Array.isArray(object)) { + result.push(...getSymbols(object)) + } + return result +} + +export default getAllKeys diff --git a/libs/lodash/.internal/getAllKeysIn.js b/libs/lodash/.internal/getAllKeysIn.js new file mode 100644 index 0000000..c9714e1 --- /dev/null +++ b/libs/lodash/.internal/getAllKeysIn.js @@ -0,0 +1,21 @@ +import getSymbolsIn from './getSymbolsIn.js' + +/** + * Creates an array of own and inherited enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ +function getAllKeysIn(object) { + const result = [] + for (const key in object) { + result.push(key) + } + if (!Array.isArray(object)) { + result.push(...getSymbolsIn(object)) + } + return result +} + +export default getAllKeysIn diff --git a/libs/lodash/.internal/getHolder.js b/libs/lodash/.internal/getHolder.js new file mode 100644 index 0000000..d63e905 --- /dev/null +++ b/libs/lodash/.internal/getHolder.js @@ -0,0 +1,13 @@ +/** + * Gets the argument placeholder value for `func`. + * + * @private + * @param {Function} func The function to inspect. + * @returns {*} Returns the placeholder value. + */ +function getHolder(func) { + const object = func + return object.placeholder +} + +export default getHolder diff --git a/libs/lodash/.internal/getMatchData.js b/libs/lodash/.internal/getMatchData.js new file mode 100644 index 0000000..baf1b5f --- /dev/null +++ b/libs/lodash/.internal/getMatchData.js @@ -0,0 +1,23 @@ +import isStrictComparable from './isStrictComparable.js' +import keys from '../keys.js' + +/** + * Gets the property names, values, and compare flags of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the match data of `object`. + */ +function getMatchData(object) { + const result = keys(object) + let length = result.length + + while (length--) { + const key = result[length] + const value = object[key] + result[length] = [key, value, isStrictComparable(value)] + } + return result +} + +export default getMatchData diff --git a/libs/lodash/.internal/getSymbols.js b/libs/lodash/.internal/getSymbols.js new file mode 100644 index 0000000..17c2221 --- /dev/null +++ b/libs/lodash/.internal/getSymbols.js @@ -0,0 +1,22 @@ +/** Built-in value references. */ +const propertyIsEnumerable = Object.prototype.propertyIsEnumerable + +/* Built-in method references for those with the same name as other `lodash` methods. */ +const nativeGetSymbols = Object.getOwnPropertySymbols + +/** + * Creates an array of the own enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ +function getSymbols(object) { + if (object == null) { + return [] + } + object = Object(object) + return nativeGetSymbols(object).filter((symbol) => propertyIsEnumerable.call(object, symbol)) +} + +export default getSymbols diff --git a/libs/lodash/.internal/getSymbolsIn.js b/libs/lodash/.internal/getSymbolsIn.js new file mode 100644 index 0000000..697e915 --- /dev/null +++ b/libs/lodash/.internal/getSymbolsIn.js @@ -0,0 +1,19 @@ +import getSymbols from './getSymbols.js' + +/** + * Creates an array of the own and inherited enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ +function getSymbolsIn(object) { + const result = [] + while (object) { + result.push(...getSymbols(object)) + object = Object.getPrototypeOf(Object(object)) + } + return result +} + +export default getSymbolsIn diff --git a/libs/lodash/.internal/getTag.js b/libs/lodash/.internal/getTag.js new file mode 100644 index 0000000..977c44b --- /dev/null +++ b/libs/lodash/.internal/getTag.js @@ -0,0 +1,17 @@ +const toString = Object.prototype.toString + +/** + * Gets the `toStringTag` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ +function getTag(value) { + if (value == null) { + return value === undefined ? '[object Undefined]' : '[object Null]' + } + return toString.call(value) +} + +export default getTag diff --git a/libs/lodash/.internal/hasUnicode.js b/libs/lodash/.internal/hasUnicode.js new file mode 100644 index 0000000..9762171 --- /dev/null +++ b/libs/lodash/.internal/hasUnicode.js @@ -0,0 +1,28 @@ +/** Used to compose unicode character classes. */ +const rsAstralRange = '\\ud800-\\udfff' +const rsComboMarksRange = '\\u0300-\\u036f' +const reComboHalfMarksRange = '\\ufe20-\\ufe2f' +const rsComboSymbolsRange = '\\u20d0-\\u20ff' +const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff' +const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff' +const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange +const rsVarRange = '\\ufe0e\\ufe0f' + +/** Used to compose unicode capture groups. */ +const rsZWJ = '\\u200d' + +/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ +const reHasUnicode = RegExp(`[${rsZWJ + rsAstralRange + rsComboRange + rsVarRange}]`) + +/** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ +function hasUnicode(string) { + return reHasUnicode.test(string) +} + +export default hasUnicode diff --git a/libs/lodash/.internal/initCloneObject.js b/libs/lodash/.internal/initCloneObject.js new file mode 100644 index 0000000..d63a8d4 --- /dev/null +++ b/libs/lodash/.internal/initCloneObject.js @@ -0,0 +1,16 @@ +import isPrototype from './isPrototype.js' + +/** + * Initializes an object clone. + * + * @private + * @param {Object} object The object to clone. + * @returns {Object} Returns the initialized clone. + */ +function initCloneObject(object) { + return (typeof object.constructor === 'function' && !isPrototype(object)) + ? Object.create(Object.getPrototypeOf(object)) + : {} +} + +export default initCloneObject diff --git a/libs/lodash/.internal/isFlattenable.js b/libs/lodash/.internal/isFlattenable.js new file mode 100644 index 0000000..40f90d3 --- /dev/null +++ b/libs/lodash/.internal/isFlattenable.js @@ -0,0 +1,18 @@ +import isArguments from '../isArguments.js' + +/** Built-in value reference. */ +const spreadableSymbol = Symbol.isConcatSpreadable + +/** + * Checks if `value` is a flattenable `arguments` object or array. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. + */ +function isFlattenable(value) { + return Array.isArray(value) || isArguments(value) || + !!(value && value[spreadableSymbol]) +} + +export default isFlattenable diff --git a/libs/lodash/.internal/isIndex.js b/libs/lodash/.internal/isIndex.js new file mode 100644 index 0000000..641a0f8 --- /dev/null +++ b/libs/lodash/.internal/isIndex.js @@ -0,0 +1,25 @@ +/** Used as references for various `Number` constants. */ +const MAX_SAFE_INTEGER = 9007199254740991 + +/** Used to detect unsigned integer values. */ +const reIsUint = /^(?:0|[1-9]\d*)$/ + +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + const type = typeof value + length = length == null ? MAX_SAFE_INTEGER : length + + return !!length && + (type === 'number' || + (type !== 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length) +} + +export default isIndex diff --git a/libs/lodash/.internal/isIterateeCall.js b/libs/lodash/.internal/isIterateeCall.js new file mode 100644 index 0000000..0699092 --- /dev/null +++ b/libs/lodash/.internal/isIterateeCall.js @@ -0,0 +1,31 @@ +import isArrayLike from '../isArrayLike.js' +import isIndex from './isIndex.js' +import isObject from '../isObject.js' +import eq from '../eq.js' + +/** + * Checks if the given arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. + */ + +function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false + } + const type = typeof index + if (type === 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type === 'string' && index in object) + ) { + return eq(object[index], value) + } + return false +} + +export default isIterateeCall diff --git a/libs/lodash/.internal/isKey.js b/libs/lodash/.internal/isKey.js new file mode 100644 index 0000000..0b5badd --- /dev/null +++ b/libs/lodash/.internal/isKey.js @@ -0,0 +1,27 @@ +import isSymbol from '../isSymbol.js' + +/** Used to match property names within property paths. */ +const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/ +const reIsPlainProp = /^\w*$/ + +/** + * Checks if `value` is a property name and not a property path. + * + * @private + * @param {*} value The value to check. + * @param {Object} [object] The object to query keys on. + * @returns {boolean} Returns `true` if `value` is a property name, else `false`. + */ +function isKey(value, object) { + if (Array.isArray(value)) { + return false + } + const type = typeof value + if (type === 'number' || type === 'boolean' || value == null || isSymbol(value)) { + return true + } + return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (object != null && value in Object(object)) +} + +export default isKey diff --git a/libs/lodash/.internal/isPrototype.js b/libs/lodash/.internal/isPrototype.js new file mode 100644 index 0000000..05e33c8 --- /dev/null +++ b/libs/lodash/.internal/isPrototype.js @@ -0,0 +1,18 @@ +/** Used for built-in method references. */ +const objectProto = Object.prototype + +/** + * Checks if `value` is likely a prototype object. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. + */ +function isPrototype(value) { + const Ctor = value && value.constructor + const proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto + + return value === proto +} + +export default isPrototype diff --git a/libs/lodash/.internal/isStrictComparable.js b/libs/lodash/.internal/isStrictComparable.js new file mode 100644 index 0000000..edbe94d --- /dev/null +++ b/libs/lodash/.internal/isStrictComparable.js @@ -0,0 +1,15 @@ +import isObject from '../isObject.js' + +/** + * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` if suitable for strict + * equality comparisons, else `false`. + */ +function isStrictComparable(value) { + return value === value && !isObject(value) +} + +export default isStrictComparable diff --git a/libs/lodash/.internal/iteratorToArray.js b/libs/lodash/.internal/iteratorToArray.js new file mode 100644 index 0000000..894e092 --- /dev/null +++ b/libs/lodash/.internal/iteratorToArray.js @@ -0,0 +1,18 @@ +/** + * Converts `iterator` to an array. + * + * @private + * @param {Object} iterator The iterator to convert. + * @returns {Array} Returns the converted array. + */ +function iteratorToArray(iterator) { + let data + const result = [] + + while (!(data = iterator.next()).done) { + result.push(data.value) + } + return result +} + +export default iteratorToArray diff --git a/libs/lodash/.internal/mapToArray.js b/libs/lodash/.internal/mapToArray.js new file mode 100644 index 0000000..1f61b8b --- /dev/null +++ b/libs/lodash/.internal/mapToArray.js @@ -0,0 +1,18 @@ +/** + * Converts `map` to its key-value pairs. + * + * @private + * @param {Object} map The map to convert. + * @returns {Array} Returns the key-value pairs. + */ +function mapToArray(map) { + let index = -1 + const result = new Array(map.size) + + map.forEach((value, key) => { + result[++index] = [key, value] + }) + return result +} + +export default mapToArray diff --git a/libs/lodash/.internal/matchesStrictComparable.js b/libs/lodash/.internal/matchesStrictComparable.js new file mode 100644 index 0000000..fcc9193 --- /dev/null +++ b/libs/lodash/.internal/matchesStrictComparable.js @@ -0,0 +1,20 @@ +/** + * A specialized version of `matchesProperty` for source values suitable + * for strict equality comparisons, i.e. `===`. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ +function matchesStrictComparable(key, srcValue) { + return (object) => { + if (object == null) { + return false + } + return object[key] === srcValue && + (srcValue !== undefined || (key in Object(object))) + } +} + +export default matchesStrictComparable diff --git a/libs/lodash/.internal/memoizeCapped.js b/libs/lodash/.internal/memoizeCapped.js new file mode 100644 index 0000000..d4ea59f --- /dev/null +++ b/libs/lodash/.internal/memoizeCapped.js @@ -0,0 +1,26 @@ +import memoize from '../memoize.js' + +/** Used as the maximum memoize cache size. */ +const MAX_MEMOIZE_SIZE = 500 + +/** + * A specialized version of `memoize` which clears the memoized function's + * cache when it exceeds `MAX_MEMOIZE_SIZE`. + * + * @private + * @param {Function} func The function to have its output memoized. + * @returns {Function} Returns the new memoized function. + */ +function memoizeCapped(func) { + const result = memoize(func, (key) => { + const { cache } = result + if (cache.size === MAX_MEMOIZE_SIZE) { + cache.clear() + } + return key + }) + + return result +} + +export default memoizeCapped diff --git a/libs/lodash/.internal/metaMap.js b/libs/lodash/.internal/metaMap.js new file mode 100644 index 0000000..261cd39 --- /dev/null +++ b/libs/lodash/.internal/metaMap.js @@ -0,0 +1 @@ +export default new WeakMap diff --git a/libs/lodash/.internal/nodeTypes.js b/libs/lodash/.internal/nodeTypes.js new file mode 100644 index 0000000..608c0f9 --- /dev/null +++ b/libs/lodash/.internal/nodeTypes.js @@ -0,0 +1,28 @@ +import freeGlobal from './freeGlobal.js' + +/** Detect free variable `exports`. */ +const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports + +/** Detect free variable `module`. */ +const freeModule = freeExports && typeof module === 'object' && module !== null && !module.nodeType && module + +/** Detect the popular CommonJS extension `module.exports`. */ +const moduleExports = freeModule && freeModule.exports === freeExports + +/** Detect free variable `process` from Node.js. */ +const freeProcess = moduleExports && freeGlobal.process + +/** Used to access faster Node.js helpers. */ +const nodeTypes = ((() => { + try { + /* Detect public `util.types` helpers for Node.js v10+. */ + /* Node.js deprecation code: DEP0103. */ + const typesHelper = freeModule && freeModule.require && freeModule.require('util').types + return typesHelper + ? typesHelper + /* Legacy process.binding('util') for Node.js earlier than v10. */ + : freeProcess && freeProcess.binding && freeProcess.binding('util') + } catch (e) {} +})()) + +export default nodeTypes diff --git a/libs/lodash/.internal/parent.js b/libs/lodash/.internal/parent.js new file mode 100644 index 0000000..12180de --- /dev/null +++ b/libs/lodash/.internal/parent.js @@ -0,0 +1,16 @@ +import baseGet from './baseGet.js' +import slice from '../slice.js' + +/** + * Gets the parent value at `path` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} path The path to get the parent value of. + * @returns {*} Returns the parent value. + */ +function parent(object, path) { + return path.length < 2 ? object : baseGet(object, slice(path, 0, -1)) +} + +export default parent diff --git a/libs/lodash/.internal/reEscape.js b/libs/lodash/.internal/reEscape.js new file mode 100644 index 0000000..e98fa45 --- /dev/null +++ b/libs/lodash/.internal/reEscape.js @@ -0,0 +1,4 @@ +/** Used to match template delimiters. */ +const reEscape = /<%-([\s\S]+?)%>/g + +export default reEscape diff --git a/libs/lodash/.internal/reEvaluate.js b/libs/lodash/.internal/reEvaluate.js new file mode 100644 index 0000000..f0df1b3 --- /dev/null +++ b/libs/lodash/.internal/reEvaluate.js @@ -0,0 +1,4 @@ +/** Used to match template delimiters. */ +const reEvaluate = /<%([\s\S]+?)%>/g + +export default reEvaluate diff --git a/libs/lodash/.internal/reInterpolate.js b/libs/lodash/.internal/reInterpolate.js new file mode 100644 index 0000000..8c681d9 --- /dev/null +++ b/libs/lodash/.internal/reInterpolate.js @@ -0,0 +1,4 @@ +/** Used to match template delimiters. */ +const reInterpolate = /<%=([\s\S]+?)%>/g + +export default reInterpolate diff --git a/libs/lodash/.internal/root.js b/libs/lodash/.internal/root.js new file mode 100644 index 0000000..58abec6 --- /dev/null +++ b/libs/lodash/.internal/root.js @@ -0,0 +1,13 @@ +/* global globalThis, self */ +import freeGlobal from './freeGlobal.js' + +/** Detect free variable `globalThis` */ +const freeGlobalThis = typeof globalThis === 'object' && globalThis !== null && globalThis.Object == Object && globalThis + +/** Detect free variable `self`. */ +const freeSelf = typeof self === 'object' && self !== null && self.Object === Object && self + +/** Used as a reference to the global object. */ +const root = freeGlobalThis || freeGlobal || freeSelf || Function('return this')() + +export default root diff --git a/libs/lodash/.internal/setToArray.js b/libs/lodash/.internal/setToArray.js new file mode 100644 index 0000000..c16f93e --- /dev/null +++ b/libs/lodash/.internal/setToArray.js @@ -0,0 +1,18 @@ +/** + * Converts `set` to an array of its values. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the values. + */ +function setToArray(set) { + let index = -1 + const result = new Array(set.size) + + set.forEach((value) => { + result[++index] = value + }) + return result +} + +export default setToArray diff --git a/libs/lodash/.internal/setToPairs.js b/libs/lodash/.internal/setToPairs.js new file mode 100644 index 0000000..d9ca757 --- /dev/null +++ b/libs/lodash/.internal/setToPairs.js @@ -0,0 +1,18 @@ +/** + * Converts `set` to its value-value pairs. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the value-value pairs. + */ +function setToPairs(set) { + let index = -1 + const result = new Array(set.size) + + set.forEach((value) => { + result[++index] = [value, value] + }) + return result +} + +export default setToPairs diff --git a/libs/lodash/.internal/setToString.js b/libs/lodash/.internal/setToString.js new file mode 100644 index 0000000..88a5873 --- /dev/null +++ b/libs/lodash/.internal/setToString.js @@ -0,0 +1,18 @@ +/** + * Sets the `toString` method of `func` to return `string`. + * + * @private + * @param {Function} func The function to modify. + * @param {Function} string The `toString` result. + * @returns {Function} Returns `func`. + */ +function setToString(func, string) { + return Object.defineProperty(func, 'toString', { + 'configurable': true, + 'enumerable': false, + 'value': () => string, + 'writable': true + }) +} + +export default setToString diff --git a/libs/lodash/.internal/strictIndexOf.js b/libs/lodash/.internal/strictIndexOf.js new file mode 100644 index 0000000..286031e --- /dev/null +++ b/libs/lodash/.internal/strictIndexOf.js @@ -0,0 +1,23 @@ +/** + * A specialized version of `indexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function strictIndexOf(array, value, fromIndex) { + let index = fromIndex - 1 + const { length } = array + + while (++index < length) { + if (array[index] === value) { + return index + } + } + return -1 +} + +export default strictIndexOf diff --git a/libs/lodash/.internal/strictLastIndexOf.js b/libs/lodash/.internal/strictLastIndexOf.js new file mode 100644 index 0000000..8b81bfd --- /dev/null +++ b/libs/lodash/.internal/strictLastIndexOf.js @@ -0,0 +1,21 @@ +/** + * A specialized version of `lastIndexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function strictLastIndexOf(array, value, fromIndex) { + let index = fromIndex + 1 + while (index--) { + if (array[index] === value) { + return index + } + } + return index +} + +export default strictLastIndexOf diff --git a/libs/lodash/.internal/stringSize.js b/libs/lodash/.internal/stringSize.js new file mode 100644 index 0000000..25a108e --- /dev/null +++ b/libs/lodash/.internal/stringSize.js @@ -0,0 +1,16 @@ +import asciiSize from './asciiSize.js' +import hasUnicode from './hasUnicode.js' +import unicodeSize from './unicodeSize.js' + +/** + * Gets the number of symbols in `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the string size. + */ +function stringSize(string) { + return hasUnicode(string) ? unicodeSize(string) : asciiSize(string) +} + +export default stringSize diff --git a/libs/lodash/.internal/stringToArray.js b/libs/lodash/.internal/stringToArray.js new file mode 100644 index 0000000..38aceed --- /dev/null +++ b/libs/lodash/.internal/stringToArray.js @@ -0,0 +1,18 @@ +import asciiToArray from './asciiToArray.js' +import hasUnicode from './hasUnicode.js' +import unicodeToArray from './unicodeToArray.js' + +/** + * Converts `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function stringToArray(string) { + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string) +} + +export default stringToArray diff --git a/libs/lodash/.internal/stringToPath.js b/libs/lodash/.internal/stringToPath.js new file mode 100644 index 0000000..d9def59 --- /dev/null +++ b/libs/lodash/.internal/stringToPath.js @@ -0,0 +1,44 @@ +import memoizeCapped from './memoizeCapped.js' + +const charCodeOfDot = '.'.charCodeAt(0) +const reEscapeChar = /\\(\\)?/g +const rePropName = RegExp( + // Match anything that isn't a dot or bracket. + '[^.[\\]]+' + '|' + + // Or match property names within brackets. + '\\[(?:' + + // Match a non-string expression. + '([^"\'][^[]*)' + '|' + + // Or match strings (supports escaping characters). + '(["\'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2' + + ')\\]'+ '|' + + // Or match "" as the space between consecutive dots or empty brackets. + '(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))' + , 'g') + +/** + * Converts `string` to a property path array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the property path array. + */ +const stringToPath = memoizeCapped((string) => { + const result = [] + if (string.charCodeAt(0) === charCodeOfDot) { + result.push('') + } + string.replace(rePropName, (match, expression, quote, subString) => { + let key = match + if (quote) { + key = subString.replace(reEscapeChar, '$1') + } + else if (expression) { + key = expression.trim() + } + result.push(key) + }) + return result +}) + +export default stringToPath diff --git a/libs/lodash/.internal/toKey.js b/libs/lodash/.internal/toKey.js new file mode 100644 index 0000000..cc450c8 --- /dev/null +++ b/libs/lodash/.internal/toKey.js @@ -0,0 +1,21 @@ +import isSymbol from '../isSymbol.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** + * Converts `value` to a string key if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the key. + */ +function toKey(value) { + if (typeof value === 'string' || isSymbol(value)) { + return value + } + const result = `${value}` + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result +} + +export default toKey diff --git a/libs/lodash/.internal/unicodeSize.js b/libs/lodash/.internal/unicodeSize.js new file mode 100644 index 0000000..ff08bfb --- /dev/null +++ b/libs/lodash/.internal/unicodeSize.js @@ -0,0 +1,47 @@ +/** Used to compose unicode character classes. */ +const rsAstralRange = '\\ud800-\\udfff' +const rsComboMarksRange = '\\u0300-\\u036f' +const reComboHalfMarksRange = '\\ufe20-\\ufe2f' +const rsComboSymbolsRange = '\\u20d0-\\u20ff' +const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff' +const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff' +const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange +const rsVarRange = '\\ufe0e\\ufe0f' + +/** Used to compose unicode capture groups. */ +const rsAstral = `[${rsAstralRange}]` +const rsCombo = `[${rsComboRange}]` +const rsFitz = '\\ud83c[\\udffb-\\udfff]' +const rsModifier = `(?:${rsCombo}|${rsFitz})` +const rsNonAstral = `[^${rsAstralRange}]` +const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' +const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' +const rsZWJ = '\\u200d' + +/** Used to compose unicode regexes. */ +const reOptMod = `${rsModifier}?` +const rsOptVar = `[${rsVarRange}]?` +const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*` +const rsSeq = rsOptVar + reOptMod + rsOptJoin +const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?` +const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})` + +/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ +const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g') + +/** + * Gets the size of a Unicode `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ +function unicodeSize(string) { + let result = reUnicode.lastIndex = 0 + while (reUnicode.test(string)) { + ++result + } + return result +} + +export default unicodeSize diff --git a/libs/lodash/.internal/unicodeToArray.js b/libs/lodash/.internal/unicodeToArray.js new file mode 100644 index 0000000..af1ff26 --- /dev/null +++ b/libs/lodash/.internal/unicodeToArray.js @@ -0,0 +1,43 @@ +/** Used to compose unicode character classes. */ +const rsAstralRange = '\\ud800-\\udfff' +const rsComboMarksRange = '\\u0300-\\u036f' +const reComboHalfMarksRange = '\\ufe20-\\ufe2f' +const rsComboSymbolsRange = '\\u20d0-\\u20ff' +const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff' +const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff' +const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange +const rsVarRange = '\\ufe0e\\ufe0f' + +/** Used to compose unicode capture groups. */ +const rsAstral = `[${rsAstralRange}]` +const rsCombo = `[${rsComboRange}]` +const rsFitz = '\\ud83c[\\udffb-\\udfff]' +const rsModifier = `(?:${rsCombo}|${rsFitz})` +const rsNonAstral = `[^${rsAstralRange}]` +const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' +const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' +const rsZWJ = '\\u200d' + +/** Used to compose unicode regexes. */ +const reOptMod = `${rsModifier}?` +const rsOptVar = `[${rsVarRange}]?` +const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*` +const rsSeq = rsOptVar + reOptMod + rsOptJoin +const rsNonAstralCombo = `${rsNonAstral}${rsCombo}?` +const rsSymbol = `(?:${[rsNonAstralCombo, rsCombo, rsRegional, rsSurrPair, rsAstral].join('|')})` + +/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ +const reUnicode = RegExp(`${rsFitz}(?=${rsFitz})|${rsSymbol + rsSeq}`, 'g') + +/** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ +function unicodeToArray(string) { + return string.match(reUnicode) || [] +} + +export default unicodeToArray diff --git a/libs/lodash/.internal/unicodeWords.js b/libs/lodash/.internal/unicodeWords.js new file mode 100644 index 0000000..16e8af6 --- /dev/null +++ b/libs/lodash/.internal/unicodeWords.js @@ -0,0 +1,70 @@ +/** Used to compose unicode character classes. */ +const rsAstralRange = '\\ud800-\\udfff' +const rsComboMarksRange = '\\u0300-\\u036f' +const reComboHalfMarksRange = '\\ufe20-\\ufe2f' +const rsComboSymbolsRange = '\\u20d0-\\u20ff' +const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff' +const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff' +const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange +const rsDingbatRange = '\\u2700-\\u27bf' +const rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff' +const rsMathOpRange = '\\xac\\xb1\\xd7\\xf7' +const rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf' +const rsPunctuationRange = '\\u2000-\\u206f' +const rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000' +const rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde' +const rsVarRange = '\\ufe0e\\ufe0f' +const rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange + +/** Used to compose unicode capture groups. */ +const rsApos = "['\u2019]" +const rsBreak = `[${rsBreakRange}]` +const rsCombo = `[${rsComboRange}]` +const rsDigit = '\\d' +const rsDingbat = `[${rsDingbatRange}]` +const rsLower = `[${rsLowerRange}]` +const rsMisc = `[^${rsAstralRange}${rsBreakRange + rsDigit + rsDingbatRange + rsLowerRange + rsUpperRange}]` +const rsFitz = '\\ud83c[\\udffb-\\udfff]' +const rsModifier = `(?:${rsCombo}|${rsFitz})` +const rsNonAstral = `[^${rsAstralRange}]` +const rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}' +const rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]' +const rsUpper = `[${rsUpperRange}]` +const rsZWJ = '\\u200d' + +/** Used to compose unicode regexes. */ +const rsMiscLower = `(?:${rsLower}|${rsMisc})` +const rsMiscUpper = `(?:${rsUpper}|${rsMisc})` +const rsOptContrLower = `(?:${rsApos}(?:d|ll|m|re|s|t|ve))?` +const rsOptContrUpper = `(?:${rsApos}(?:D|LL|M|RE|S|T|VE))?` +const reOptMod = `${rsModifier}?` +const rsOptVar = `[${rsVarRange}]?` +const rsOptJoin = `(?:${rsZWJ}(?:${[rsNonAstral, rsRegional, rsSurrPair].join('|')})${rsOptVar + reOptMod})*` +const rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])' +const rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])' +const rsSeq = rsOptVar + reOptMod + rsOptJoin +const rsEmoji = `(?:${[rsDingbat, rsRegional, rsSurrPair].join('|')})${rsSeq}` + +const reUnicodeWords = RegExp([ + `${rsUpper}?${rsLower}+${rsOptContrLower}(?=${[rsBreak, rsUpper, '$'].join('|')})`, + `${rsMiscUpper}+${rsOptContrUpper}(?=${[rsBreak, rsUpper + rsMiscLower, '$'].join('|')})`, + `${rsUpper}?${rsMiscLower}+${rsOptContrLower}`, + `${rsUpper}+${rsOptContrUpper}`, + rsOrdUpper, + rsOrdLower, + `${rsDigit}+`, + rsEmoji +].join('|'), 'g') + +/** + * Splits a Unicode `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ +function unicodeWords(string) { + return string.match(reUnicodeWords) +} + +export default unicodeWords diff --git a/libs/lodash/LICENSE b/libs/lodash/LICENSE new file mode 100644 index 0000000..4773fd8 --- /dev/null +++ b/libs/lodash/LICENSE @@ -0,0 +1,49 @@ +The MIT License + +Copyright JS Foundation and other contributors + +Based on Underscore.js, copyright Jeremy Ashkenas, +DocumentCloud and Investigative Reporters & Editors + +This software consists of voluntary contributions made by many +individuals. For exact contribution history, see the revision history +available at https://github.com/lodash/lodash + +The following license applies to all parts of this software except as +documented below: + +==== + +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: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +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. + +==== + +Copyright and related rights for sample code are waived via CC0. Sample +code is defined as all source code displayed within the prose of the +documentation. + +CC0: http://creativecommons.org/publicdomain/zero/1.0/ + +==== + +Files located in the node_modules and vendor directories are externally +maintained libraries used by this software which have their own +licenses; we recommend you read them, as their terms may differ from the +terms above. diff --git a/libs/lodash/README.md b/libs/lodash/README.md new file mode 100644 index 0000000..75f0abd --- /dev/null +++ b/libs/lodash/README.md @@ -0,0 +1,80 @@ +# lodash + +[Site](https://lodash.com/) | +[Docs](https://lodash.com/docs) | +[FP Guide](https://github.com/lodash/lodash/wiki/FP-Guide) | +[Contributing](https://github.com/lodash/lodash/blob/master/.github/CONTRIBUTING.md) | +[Wiki](https://github.com/lodash/lodash/wiki "Changelog, Roadmap, etc.") | +[Code of Conduct](https://code-of-conduct.openjsf.org) | +[Twitter](https://twitter.com/bestiejs) | +[Chat](https://gitter.im/lodash/lodash) + +The [Lodash](https://lodash.com/) library exported as a [UMD](https://github.com/umdjs/umd) module. + +Generated using [lodash-cli](https://www.npmjs.com/package/lodash-cli): +```shell +$ npm run build +$ lodash -o ./dist/lodash.js +$ lodash core -o ./dist/lodash.core.js +``` + +## Download + + * [Core build](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/core.js) ([~4 kB gzipped](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/core.min.js)) + * [Full build](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/lodash.js) ([~24 kB gzipped](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/lodash.min.js)) + * [CDN copies](https://www.jsdelivr.com/projects/lodash) [![jsDelivr Hits](https://data.jsdelivr.com/v1/package/npm/lodash/badge)](https://www.jsdelivr.com/package/npm/lodash) + +Lodash is released under the [MIT license](https://raw.githubusercontent.com/lodash/lodash/4.17.10-npm/LICENSE) & supports modern environments.
+Review the [build differences](https://github.com/lodash/lodash/wiki/build-differences) & pick one that’s right for you. + +## Installation + +In a browser: +```html + +``` + +Using npm: +```shell +$ npm i -g npm +$ npm i lodash +``` +Note: add `--save` if you are using npm < 5.0.0 + +In Node.js: +```js +// Load the full build. +var _ = require('lodash'); +// Load the core build. +var _ = require('lodash/core'); +// Load the FP build for immutable auto-curried iteratee-first data-last methods. +var fp = require('lodash/fp'); + +// Load method categories. +var array = require('lodash/array'); +var object = require('lodash/fp/object'); + +// Cherry-pick methods for smaller browserify/rollup/webpack bundles. +var at = require('lodash/at'); +var curryN = require('lodash/fp/curryN'); +``` + +Looking for Lodash modules written in ES6 or smaller bundle sizes? Check out [lodash-es](https://www.npmjs.com/package/lodash-es). + +## Why Lodash? + +Lodash makes JavaScript easier by taking the hassle out of working with arrays,
+numbers, objects, strings, etc. Lodash’s modular methods are great for: + + * Iterating arrays, objects, & strings + * Manipulating & testing values + * Creating composite functions + +## Module Formats + +Lodash is available in a [variety of builds](https://lodash.com/custom-builds) & module formats. + + * [lodash](https://www.npmjs.com/package/lodash) & [per method packages](https://www.npmjs.com/search?q=keywords:lodash-modularized) + * [lodash-es](https://www.npmjs.com/package/lodash-es), [babel-plugin-lodash](https://www.npmjs.com/package/babel-plugin-lodash), & [lodash-webpack-plugin](https://www.npmjs.com/package/lodash-webpack-plugin) + * [lodash/fp](https://github.com/lodash/lodash/tree/npm/fp) + * [lodash-amd](https://www.npmjs.com/package/lodash-amd) diff --git a/libs/lodash/SECURITY.md b/libs/lodash/SECURITY.md new file mode 100644 index 0000000..ab901dc --- /dev/null +++ b/libs/lodash/SECURITY.md @@ -0,0 +1,34 @@ +# Security Policy + +## Supported versions + +The following table describes the versions of this project that are currently supported with security updates: + +| Version | Supported | +| ------- | ------------------ | +| 4.x | :white_check_mark: | +| 3.x | :x: | +| 2.x | :x: | +| 1.x | :x: | + +## Responsible disclosure security policy + +A responsible disclosure policy helps protect users of the project from publicly disclosed security vulnerabilities without a fix by employing a process where vulnerabilities are first triaged in a private manner, and only publicly disclosed after a reasonable time period that allows patching the vulnerability and provides an upgrade path for users. + +When contacting us directly via email, we will do our best efforts to respond in a reasonable time to resolve the issue. When contacting a security program their disclosure policy will provide details on time-frame, processes and paid bounties. + +We kindly ask you to refrain from malicious acts that put our users, the project, or any of the project’s team members at risk. + +## Reporting a security issue + +We consider the security of our systems a top priority. But no matter how much effort we put into system security, there can still be vulnerabilities present. + +If you discover a security vulnerability, please use one of the following means of communications to report it to us: + +- Report the security issue to the Node.js Security Working Group through the [HackerOne program](https://hackerone.com/nodejs-ecosystem) for ecosystem modules on npm, or to [Snyk Security Team](https://snyk.io/vulnerability-disclosure). They will help triage the security issue and work with all involved parties to remediate and release a fix. + +Note that time-frame and processes are subject to each program’s own policy. + +- Report the security issue to the project maintainers directly at [security@lodash.com](mailto:security@lodash.com). + +Your efforts to responsibly disclose your findings are sincerely appreciated and will be taken into account to acknowledge your contributions. diff --git a/libs/lodash/add.js b/libs/lodash/add.js new file mode 100644 index 0000000..1e69176 --- /dev/null +++ b/libs/lodash/add.js @@ -0,0 +1,18 @@ +import createMathOperation from './.internal/createMathOperation.js' + +/** + * Adds two numbers. + * + * @since 3.4.0 + * @category Math + * @param {number} augend The first number in an addition. + * @param {number} addend The second number in an addition. + * @returns {number} Returns the total. + * @example + * + * add(6, 4) + * // => 10 + */ +const add = createMathOperation((augend, addend) => augend + addend, 0) + +export default add diff --git a/libs/lodash/after.js b/libs/lodash/after.js new file mode 100644 index 0000000..dade4fd --- /dev/null +++ b/libs/lodash/after.js @@ -0,0 +1,30 @@ +/** + * The opposite of `before`. This method creates a function that invokes + * `func` once it's called `n` or more times. + * + * @since 0.1.0 + * @category Function + * @param {number} n The number of calls before `func` is invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * const saves = ['profile', 'settings'] + * const done = after(saves.length, () => console.log('done saving!')) + * + * forEach(saves, type => asyncSave({ 'type': type, 'complete': done })) + * // => Logs 'done saving!' after the two async saves have completed. + */ +function after(n, func) { + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + n = n || 0 + return function(...args) { + if (--n < 1) { + return func.apply(this, args) + } + } +} + +export default after diff --git a/libs/lodash/at.js b/libs/lodash/at.js new file mode 100644 index 0000000..69bcecc --- /dev/null +++ b/libs/lodash/at.js @@ -0,0 +1,21 @@ +import baseAt from './.internal/baseAt.js' +import baseFlatten from './.internal/baseFlatten.js' + +/** + * Creates an array of values corresponding to `paths` of `object`. + * + * @since 1.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Array} Returns the picked values. + * @example + * + * const object = { 'a': [{ 'b': { 'c': 3 } }, 4] } + * + * at(object, ['a[0].b.c', 'a[1]']) + * // => [3, 4] + */ +const at = (object, ...paths) => baseAt(object, baseFlatten(paths, 1)) + +export default at diff --git a/libs/lodash/attempt.js b/libs/lodash/attempt.js new file mode 100644 index 0000000..ee6c482 --- /dev/null +++ b/libs/lodash/attempt.js @@ -0,0 +1,30 @@ +import isError from './isError.js' + +/** + * Attempts to invoke `func`, returning either the result or the caught error + * object. Any additional arguments are provided to `func` when it's invoked. + * + * @since 3.0.0 + * @category Util + * @param {Function} func The function to attempt. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {*} Returns the `func` result or error object. + * @example + * + * // Avoid throwing errors for invalid selectors. + * const elements = attempt(selector => + * document.querySelectorAll(selector), '>_>') + * + * if (isError(elements)) { + * elements = [] + * } + */ +function attempt(func, ...args) { + try { + return func(...args) + } catch (e) { + return isError(e) ? e : new Error(e) + } +} + +export default attempt diff --git a/libs/lodash/before.js b/libs/lodash/before.js new file mode 100644 index 0000000..88ba32f --- /dev/null +++ b/libs/lodash/before.js @@ -0,0 +1,32 @@ +/** + * Creates a function that invokes `func`, with the `this` binding and arguments + * of the created function, while it's called less than `n` times. Subsequent + * calls to the created function return the result of the last `func` invocation. + * + * @since 3.0.0 + * @category Function + * @param {number} n The number of calls at which `func` is no longer invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * jQuery(element).on('click', before(5, addContactToList)) + * // => Allows adding up to 4 contacts to the list. + */ +function before(n, func) { + let result + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + return function(...args) { + if (--n > 0) { + result = func.apply(this, args) + } + if (n <= 1) { + func = undefined + } + return result + } +} + +export default before diff --git a/libs/lodash/camelCase.js b/libs/lodash/camelCase.js new file mode 100644 index 0000000..9882da6 --- /dev/null +++ b/libs/lodash/camelCase.js @@ -0,0 +1,31 @@ +import upperFirst from './upperFirst.js' +import words from './words.js' +import toString from './toString.js' + +/** + * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the camel cased string. + * @see lowerCase, kebabCase, snakeCase, startCase, upperCase, upperFirst + * @example + * + * camelCase('Foo Bar') + * // => 'fooBar' + * + * camelCase('--foo-bar--') + * // => 'fooBar' + * + * camelCase('__FOO_BAR__') + * // => 'fooBar' + */ +const camelCase = (string) => ( + words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => { + word = word.toLowerCase() + return result + (index ? upperFirst(word) : word) + }, '') +) + +export default camelCase diff --git a/libs/lodash/capitalize.js b/libs/lodash/capitalize.js new file mode 100644 index 0000000..2ad2ffe --- /dev/null +++ b/libs/lodash/capitalize.js @@ -0,0 +1,20 @@ +import upperFirst from './upperFirst.js' +import toString from './toString.js' + +/** + * Converts the first character of `string` to upper case and the remaining + * to lower case. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to capitalize. + * @returns {string} Returns the capitalized string. + * @example + * + * capitalize('FRED') + * // => 'Fred' + */ +const capitalize = (string) => upperFirst(toString(string).toLowerCase()) + + +export default capitalize diff --git a/libs/lodash/castArray.js b/libs/lodash/castArray.js new file mode 100644 index 0000000..d00bd36 --- /dev/null +++ b/libs/lodash/castArray.js @@ -0,0 +1,41 @@ + +/** + * Casts `value` as an array if it's not one. + * + * @since 4.4.0 + * @category Lang + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast array. + * @example + * + * castArray(1) + * // => [1] + * + * castArray({ 'a': 1 }) + * // => [{ 'a': 1 }] + * + * castArray('abc') + * // => ['abc'] + * + * castArray(null) + * // => [null] + * + * castArray(undefined) + * // => [undefined] + * + * castArray() + * // => [] + * + * const array = [1, 2, 3] + * console.log(castArray(array) === array) + * // => true + */ +function castArray(...args) { + if (!args.length) { + return [] + } + const value = args[0] + return Array.isArray(value) ? value : [value] +} + +export default castArray diff --git a/libs/lodash/ceil.js b/libs/lodash/ceil.js new file mode 100644 index 0000000..ffb78b3 --- /dev/null +++ b/libs/lodash/ceil.js @@ -0,0 +1,24 @@ +import createRound from './.internal/createRound.js' + +/** + * Computes `number` rounded up to `precision`. (Round up: the smallest integer greater than or equal to a given number.) + * + * @since 3.10.0 + * @category Math + * @param {number} number The number to round up. + * @param {number} [precision=0] The precision to round up to. + * @returns {number} Returns the rounded up number. + * @example + * + * ceil(4.006) + * // => 5 + * + * ceil(6.004, 2) + * // => 6.01 + * + * ceil(6040, -2) + * // => 6100 + */ +const ceil = createRound('ceil') + +export default ceil diff --git a/libs/lodash/chunk.js b/libs/lodash/chunk.js new file mode 100644 index 0000000..8d57b4b --- /dev/null +++ b/libs/lodash/chunk.js @@ -0,0 +1,38 @@ +import slice from './slice.js' +import toInteger from './toInteger.js' + +/** + * Creates an array of elements split into groups the length of `size`. + * If `array` can't be split evenly, the final chunk will be the remaining + * elements. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to process. + * @param {number} [size=1] The length of each chunk + * @returns {Array} Returns the new array of chunks. + * @example + * + * chunk(['a', 'b', 'c', 'd'], 2) + * // => [['a', 'b'], ['c', 'd']] + * + * chunk(['a', 'b', 'c', 'd'], 3) + * // => [['a', 'b', 'c'], ['d']] + */ +function chunk(array, size = 1) { + size = Math.max(toInteger(size), 0) + const length = array == null ? 0 : array.length + if (!length || size < 1) { + return [] + } + let index = 0 + let resIndex = 0 + const result = new Array(Math.ceil(length / size)) + + while (index < length) { + result[resIndex++] = slice(array, index, (index += size)) + } + return result +} + +export default chunk diff --git a/libs/lodash/clamp.js b/libs/lodash/clamp.js new file mode 100644 index 0000000..6023771 --- /dev/null +++ b/libs/lodash/clamp.js @@ -0,0 +1,31 @@ +/** + * Clamps `number` within the inclusive `lower` and `upper` bounds. + * + * @since 4.0.0 + * @category Number + * @param {number} number The number to clamp. + * @param {number} lower The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + * @example + * + * clamp(-10, -5, 5) + * // => -5 + * + * clamp(10, -5, 5) + * // => 5 + */ +function clamp(number, lower, upper) { + number = +number + lower = +lower + upper = +upper + lower = lower === lower ? lower : 0 + upper = upper === upper ? upper : 0 + if (number === number) { + number = number <= upper ? number : upper + number = number >= lower ? number : lower + } + return number +} + +export default clamp diff --git a/libs/lodash/clone.js b/libs/lodash/clone.js new file mode 100644 index 0000000..97d084f --- /dev/null +++ b/libs/lodash/clone.js @@ -0,0 +1,35 @@ +import baseClone from './.internal/baseClone.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_SYMBOLS_FLAG = 4 + +/** + * Creates a shallow clone of `value`. + * + * **Note:** This method is loosely based on the + * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) + * and supports cloning arrays, array buffers, booleans, date objects, maps, + * numbers, `Object` objects, regexes, sets, strings, symbols, and typed + * arrays. The own enumerable properties of `arguments` objects are cloned + * as plain objects. Object inheritance is preserved. An empty object is + * returned for uncloneable values such as error objects, functions, DOM nodes, + * and WeakMaps. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to clone. + * @returns {*} Returns the cloned value. + * @see cloneDeep + * @example + * + * const objects = [{ 'a': 1 }, { 'b': 2 }] + * + * const shallow = clone(objects) + * console.log(shallow[0] === objects[0]) + * // => true + */ +function clone(value) { + return baseClone(value, CLONE_SYMBOLS_FLAG) +} + +export default clone diff --git a/libs/lodash/cloneDeep.js b/libs/lodash/cloneDeep.js new file mode 100644 index 0000000..390e945 --- /dev/null +++ b/libs/lodash/cloneDeep.js @@ -0,0 +1,28 @@ +import baseClone from './.internal/baseClone.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 +const CLONE_SYMBOLS_FLAG = 4 + +/** + * This method is like `clone` except that it recursively clones `value`. + * Object inheritance is preserved. + * + * @since 1.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @returns {*} Returns the deep cloned value. + * @see clone + * @example + * + * const objects = [{ 'a': 1 }, { 'b': 2 }] + * + * const deep = cloneDeep(objects) + * console.log(deep[0] === objects[0]) + * // => false + */ +function cloneDeep(value) { + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG) +} + +export default cloneDeep diff --git a/libs/lodash/cloneDeepWith.js b/libs/lodash/cloneDeepWith.js new file mode 100644 index 0000000..4c29b9e --- /dev/null +++ b/libs/lodash/cloneDeepWith.js @@ -0,0 +1,40 @@ +import baseClone from './.internal/baseClone.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 +const CLONE_SYMBOLS_FLAG = 4 + +/** + * This method is like `cloneWith` except that it recursively clones `value`. + * The customizer is invoked with up to four arguments + * (value [, index|key, object, stack]). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the deep cloned value. + * @see cloneWith + * @example + * + * function customizer(value) { + * if (isElement(value)) { + * return value.cloneNode(true) + * } + * } + * + * const el = cloneDeepWith(document.body, customizer) + * + * console.log(el === document.body) + * // => false + * console.log(el.nodeName) + * // => 'BODY' + * console.log(el.childNodes.length) + * // => 20 + */ +function cloneDeepWith(value, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer) +} + +export default cloneDeepWith diff --git a/libs/lodash/cloneWith.js b/libs/lodash/cloneWith.js new file mode 100644 index 0000000..58da039 --- /dev/null +++ b/libs/lodash/cloneWith.js @@ -0,0 +1,40 @@ +import baseClone from './.internal/baseClone.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_SYMBOLS_FLAG = 4 + +/** + * This method is like `clone` except that it accepts `customizer` which + * is invoked to produce the cloned value. If `customizer` returns `undefined`, + * cloning is handled by the method instead. The `customizer` is invoked with + * one argument (value). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the cloned value. + * @see cloneDeepWith + * @example + * + * function customizer(value) { + * if (isElement(value)) { + * return value.cloneNode(false) + * } + * } + * + * const el = cloneWith(document.body, customizer) + * + * console.log(el === document.body) + * // => false + * console.log(el.nodeName) + * // => 'BODY' + * console.log(el.childNodes.length) + * // => 0 + */ +function cloneWith(value, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + return baseClone(value, CLONE_SYMBOLS_FLAG, customizer) +} + +export default cloneWith diff --git a/libs/lodash/compact.js b/libs/lodash/compact.js new file mode 100644 index 0000000..5078673 --- /dev/null +++ b/libs/lodash/compact.js @@ -0,0 +1,30 @@ +/** + * Creates an array with all falsey values removed. The values `false`, `null`, + * `0`, `""`, `undefined`, and `NaN` are falsey. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to compact. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * compact([0, 1, false, 2, '', 3]) + * // => [1, 2, 3] + */ +function compact(array) { + let resIndex = 0 + const result = [] + + if (array == null) { + return result + } + + for (const value of array) { + if (value) { + result[resIndex++] = value + } + } + return result +} + +export default compact diff --git a/libs/lodash/cond.js b/libs/lodash/cond.js new file mode 100644 index 0000000..2927110 --- /dev/null +++ b/libs/lodash/cond.js @@ -0,0 +1,49 @@ +import map from './map.js' + +/** + * Creates a function that iterates over `pairs` and invokes the corresponding + * function of the first predicate to return truthy. The predicate-function + * pairs are invoked with the `this` binding and arguments of the created + * function. + * + * @since 4.0.0 + * @category Util + * @param {Array} pairs The predicate-function pairs. + * @returns {Function} Returns the new composite function. + * @example + * + * const func = cond([ + * [matches({ 'a': 1 }), () => 'matches A'], + * [conforms({ 'b': isNumber }), () => 'matches B'], + * [() => true, () => 'no match'] + * ]) + * + * func({ 'a': 1, 'b': 2 }) + * // => 'matches A' + * + * func({ 'a': 0, 'b': 1 }) + * // => 'matches B' + * + * func({ 'a': '1', 'b': '2' }) + * // => 'no match' + */ +function cond(pairs) { + const length = pairs == null ? 0 : pairs.length + + pairs = !length ? [] : map(pairs, (pair) => { + if (typeof pair[1] !== 'function') { + throw new TypeError('Expected a function') + } + return [pair[0], pair[1]] + }) + + return (...args) => { + for (const pair of pairs) { + if (pair[0].apply(this, args)) { + return pair[1].apply(this, args) + } + } + } +} + +export default cond diff --git a/libs/lodash/conforms.js b/libs/lodash/conforms.js new file mode 100644 index 0000000..843035e --- /dev/null +++ b/libs/lodash/conforms.js @@ -0,0 +1,33 @@ +import baseClone from './.internal/baseClone.js' +import baseConforms from './.internal/baseConforms.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 + +/** + * Creates a function that invokes the predicate properties of `source` with + * the corresponding property values of a given object, returning `true` if + * all predicates return truthy, else `false`. + * + * **Note:** The created function is equivalent to `conformsTo` with + * `source` partially applied. + * + * @since 4.0.0 + * @category Util + * @param {Object} source The object of property predicates to conform to. + * @returns {Function} Returns the new spec function. + * @example + * + * const objects = [ + * { 'a': 2, 'b': 1 }, + * { 'a': 1, 'b': 2 } + * ] + * + * filter(objects, conforms({ 'b': function(n) { return n > 1 } })) + * // => [{ 'a': 1, 'b': 2 }] + */ +function conforms(source) { + return baseConforms(baseClone(source, CLONE_DEEP_FLAG)) +} + +export default conforms diff --git a/libs/lodash/conformsTo.js b/libs/lodash/conformsTo.js new file mode 100644 index 0000000..ffe4703 --- /dev/null +++ b/libs/lodash/conformsTo.js @@ -0,0 +1,30 @@ +import baseConformsTo from './.internal/baseConformsTo.js' +import keys from './keys.js' + +/** + * Checks if `object` conforms to `source` by invoking the predicate + * properties of `source` with the corresponding property values of `object`. + * + * **Note:** This method is equivalent to `conforms` when `source` is + * partially applied. + * + * @since 4.14.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + * @example + * + * const object = { 'a': 1, 'b': 2 } + * + * conformsTo(object, { 'b': function(n) { return n > 1 } }) + * // => true + * + * conformsTo(object, { 'b': function(n) { return n > 2 } }) + * // => false + */ +function conformsTo(object, source) { + return source == null || baseConformsTo(object, source, keys(source)) +} + +export default conformsTo diff --git a/libs/lodash/countBy.js b/libs/lodash/countBy.js new file mode 100644 index 0000000..94f45ed --- /dev/null +++ b/libs/lodash/countBy.js @@ -0,0 +1,41 @@ +import baseAssignValue from './.internal/baseAssignValue.js' +import reduce from './reduce.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'betty', 'active': true }, + * { 'user': 'fred', 'active': false } + * ] + * + * countBy(users, value => value.active); + * // => { 'true': 2, 'false': 1 } + */ +function countBy(collection, iteratee) { + return reduce(collection, (result, value, key) => { + key = iteratee(value) + if (hasOwnProperty.call(result, key)) { + ++result[key] + } else { + baseAssignValue(result, key, 1) + } + return result + }, {}) +} + +export default countBy diff --git a/libs/lodash/create.js b/libs/lodash/create.js new file mode 100644 index 0000000..cd01b4d --- /dev/null +++ b/libs/lodash/create.js @@ -0,0 +1,39 @@ +/** + * Creates an object that inherits from the `prototype` object. If a + * `properties` object is given, its own enumerable string keyed properties + * are assigned to the created object. + * + * @since 2.3.0 + * @category Object + * @param {Object} prototype The object to inherit from. + * @param {Object} [properties] The properties to assign to the object. + * @returns {Object} Returns the new object. + * @example + * + * function Shape() { + * this.x = 0 + * this.y = 0 + * } + * + * function Circle() { + * Shape.call(this) + * } + * + * Circle.prototype = create(Shape.prototype, { + * 'constructor': Circle + * }) + * + * const circle = new Circle + * circle instanceof Circle + * // => true + * + * circle instanceof Shape + * // => true + */ +function create(prototype, properties) { + prototype = prototype === null ? null : Object(prototype) + const result = Object.create(prototype) + return properties == null ? result : Object.assign(result, properties) +} + +export default create diff --git a/libs/lodash/debounce.js b/libs/lodash/debounce.js new file mode 100644 index 0000000..2a799a6 --- /dev/null +++ b/libs/lodash/debounce.js @@ -0,0 +1,213 @@ +import isObject from './isObject.js' +import root from './.internal/root.js' + +/** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked, or until the next browser frame is drawn. The debounced function + * comes with a `cancel` method to cancel delayed `func` invocations and a + * `flush` method to immediately invoke them. Provide `options` to indicate + * whether `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. The `func` is invoked with the last arguments provided to the + * debounced function. Subsequent calls to the debounced function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the debounced function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until the next tick, similar to `setTimeout` with a timeout of `0`. + * + * If `wait` is omitted in an environment with `requestAnimationFrame`, `func` + * invocation will be deferred until the next frame is drawn (typically about + * 16ms). + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `debounce` and `throttle`. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] + * The number of milliseconds to delay; if omitted, `requestAnimationFrame` is + * used (if available). + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // Avoid costly calculations while the window size is in flux. + * jQuery(window).on('resize', debounce(calculateLayout, 150)) + * + * // Invoke `sendMail` when clicked, debouncing subsequent calls. + * jQuery(element).on('click', debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })) + * + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. + * const debounced = debounce(batchLog, 250, { 'maxWait': 1000 }) + * const source = new EventSource('/stream') + * jQuery(source).on('message', debounced) + * + * // Cancel the trailing debounced invocation. + * jQuery(window).on('popstate', debounced.cancel) + * + * // Check for pending invocations. + * const status = debounced.pending() ? "Pending..." : "Ready" + */ +function debounce(func, wait, options) { + let lastArgs, + lastThis, + maxWait, + result, + timerId, + lastCallTime + + let lastInvokeTime = 0 + let leading = false + let maxing = false + let trailing = true + + // Bypass `requestAnimationFrame` by explicitly setting `wait=0`. + const useRAF = (!wait && wait !== 0 && typeof root.requestAnimationFrame === 'function') + + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + wait = +wait || 0 + if (isObject(options)) { + leading = !!options.leading + maxing = 'maxWait' in options + maxWait = maxing ? Math.max(+options.maxWait || 0, wait) : maxWait + trailing = 'trailing' in options ? !!options.trailing : trailing + } + + function invokeFunc(time) { + const args = lastArgs + const thisArg = lastThis + + lastArgs = lastThis = undefined + lastInvokeTime = time + result = func.apply(thisArg, args) + return result + } + + function startTimer(pendingFunc, wait) { + if (useRAF) { + root.cancelAnimationFrame(timerId) + return root.requestAnimationFrame(pendingFunc) + } + return setTimeout(pendingFunc, wait) + } + + function cancelTimer(id) { + if (useRAF) { + return root.cancelAnimationFrame(id) + } + clearTimeout(id) + } + + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time + // Start the timer for the trailing edge. + timerId = startTimer(timerExpired, wait) + // Invoke the leading edge. + return leading ? invokeFunc(time) : result + } + + function remainingWait(time) { + const timeSinceLastCall = time - lastCallTime + const timeSinceLastInvoke = time - lastInvokeTime + const timeWaiting = wait - timeSinceLastCall + + return maxing + ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) + : timeWaiting + } + + function shouldInvoke(time) { + const timeSinceLastCall = time - lastCallTime + const timeSinceLastInvoke = time - lastInvokeTime + + // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + return (lastCallTime === undefined || (timeSinceLastCall >= wait) || + (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)) + } + + function timerExpired() { + const time = Date.now() + if (shouldInvoke(time)) { + return trailingEdge(time) + } + // Restart the timer. + timerId = startTimer(timerExpired, remainingWait(time)) + } + + function trailingEdge(time) { + timerId = undefined + + // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + if (trailing && lastArgs) { + return invokeFunc(time) + } + lastArgs = lastThis = undefined + return result + } + + function cancel() { + if (timerId !== undefined) { + cancelTimer(timerId) + } + lastInvokeTime = 0 + lastArgs = lastCallTime = lastThis = timerId = undefined + } + + function flush() { + return timerId === undefined ? result : trailingEdge(Date.now()) + } + + function pending() { + return timerId !== undefined + } + + function debounced(...args) { + const time = Date.now() + const isInvoking = shouldInvoke(time) + + lastArgs = args + lastThis = this + lastCallTime = time + + if (isInvoking) { + if (timerId === undefined) { + return leadingEdge(lastCallTime) + } + if (maxing) { + // Handle invocations in a tight loop. + timerId = startTimer(timerExpired, wait) + return invokeFunc(lastCallTime) + } + } + if (timerId === undefined) { + timerId = startTimer(timerExpired, wait) + } + return result + } + debounced.cancel = cancel + debounced.flush = flush + debounced.pending = pending + return debounced +} + +export default debounce diff --git a/libs/lodash/deburr.js b/libs/lodash/deburr.js new file mode 100644 index 0000000..8475fab --- /dev/null +++ b/libs/lodash/deburr.js @@ -0,0 +1,43 @@ +import deburrLetter from './.internal/deburrLetter.js' + +/** Used to match Latin Unicode letters (excluding mathematical operators). */ +const reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g + +/** Used to compose unicode character classes. */ +const rsComboMarksRange = '\\u0300-\\u036f' +const reComboHalfMarksRange = '\\ufe20-\\ufe2f' +const rsComboSymbolsRange = '\\u20d0-\\u20ff' +const rsComboMarksExtendedRange = '\\u1ab0-\\u1aff' +const rsComboMarksSupplementRange = '\\u1dc0-\\u1dff' +const rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange + rsComboMarksExtendedRange + rsComboMarksSupplementRange + +/** Used to compose unicode capture groups. */ +const rsCombo = `[${rsComboRange}]` + +/** + * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and + * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). + */ +const reComboMark = RegExp(rsCombo, 'g') + +/** + * Deburrs `string` by converting + * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) + * letters to basic Latin letters and removing + * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to deburr. + * @returns {string} Returns the deburred string. + * @example + * + * deburr('déjà vu') + * // => 'deja vu' + */ +function deburr(string) { + return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '') +} + +export default deburr diff --git a/libs/lodash/defaultTo.js b/libs/lodash/defaultTo.js new file mode 100644 index 0000000..6f43f29 --- /dev/null +++ b/libs/lodash/defaultTo.js @@ -0,0 +1,23 @@ +/** + * Checks `value` to determine whether a default value should be returned in + * its place. The `defaultValue` is returned if `value` is `NaN`, `null`, + * or `undefined`. + * + * @since 4.14.0 + * @category Util + * @param {*} value The value to check. + * @param {*} defaultValue The default value. + * @returns {*} Returns the resolved value. + * @example + * + * defaultTo(1, 10) + * // => 1 + * + * defaultTo(undefined, 10) + * // => 10 + */ +function defaultTo(value, defaultValue) { + return (value == null || value !== value) ? defaultValue : value +} + +export default defaultTo diff --git a/libs/lodash/defaultToAny.js b/libs/lodash/defaultToAny.js new file mode 100644 index 0000000..038730c --- /dev/null +++ b/libs/lodash/defaultToAny.js @@ -0,0 +1,32 @@ +import arrayReduce from './.internal/arrayReduce.js' +import defaultTo from './defaultTo.js' + +/** + * This method is like `defaultTo` except that it accepts multiple default values and returns the first one that is not + * `NaN`, `null`, or `undefined`. + * + * @since 5.0.0 + * @category Util + * @param {*} value The value to check. + * @param {...*} defaultValues The default values. + * @returns {*} Returns the resolved value. + * @see _.defaultTo + * @example + * + * defaultToAny(1, 10, 20) + * // => 1 + * + * defaultToAny(undefined, 10, 20) + * // => 10 + * + * defaultToAny(undefined, null, 20) + * // => 20 + * + * defaultToAny(undefined, null, NaN) + * // => NaN + */ +function defaultToAny(value, ...defaultValues) { + return arrayReduce(defaultValues, defaultTo, value) +} + +export default defaultToAny diff --git a/libs/lodash/defaults.js b/libs/lodash/defaults.js new file mode 100644 index 0000000..99e234d --- /dev/null +++ b/libs/lodash/defaults.js @@ -0,0 +1,45 @@ +import eq from './eq.js' + +/** Used for built-in method references. */ +const objectProto = Object.prototype + +/** Used to check objects for own properties. */ +const hasOwnProperty = objectProto.hasOwnProperty + +/** + * Assigns own and inherited enumerable string keyed properties of source + * objects to the destination object for all destination properties that + * resolve to `undefined`. Source objects are applied from left to right. + * Once a property is set, additional values of the same property are ignored. + * + * **Note:** This method mutates `object`. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see defaultsDeep + * @example + * + * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }) + * // => { 'a': 1, 'b': 2 } + */ +function defaults(object, ...sources) { + object = Object(object) + sources.forEach((source) => { + if (source != null) { + source = Object(source) + for (const key in source) { + const value = object[key] + if (value === undefined || + (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { + object[key] = source[key] + } + } + } + }) + return object +} + +export default defaults diff --git a/libs/lodash/defaultsDeep.js b/libs/lodash/defaultsDeep.js new file mode 100644 index 0000000..ae942f0 --- /dev/null +++ b/libs/lodash/defaultsDeep.js @@ -0,0 +1,26 @@ +import customDefaultsMerge from './.internal/customDefaultsMerge.js' +import mergeWith from './mergeWith.js' + +/** + * This method is like `defaults` except that it recursively assigns + * default properties. + * + * **Note:** This method mutates `object`. + * + * @since 3.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see defaults + * @example + * + * defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }) + * // => { 'a': { 'b': 2, 'c': 3 } } + */ +function defaultsDeep(...args) { + args.push(undefined, customDefaultsMerge) + return mergeWith.apply(undefined, args) +} + +export default defaultsDeep diff --git a/libs/lodash/defer.js b/libs/lodash/defer.js new file mode 100644 index 0000000..77c3da6 --- /dev/null +++ b/libs/lodash/defer.js @@ -0,0 +1,22 @@ +/** + * Defers invoking the `func` until the current call stack has cleared. Any + * additional arguments are provided to `func` when it's invoked. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to defer. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * defer(text => console.log(text), 'deferred') + * // => Logs 'deferred' after one millisecond. + */ +function defer(func, ...args) { + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + return setTimeout(func, 1, ...args) +} + +export default defer diff --git a/libs/lodash/delay.js b/libs/lodash/delay.js new file mode 100644 index 0000000..52258b2 --- /dev/null +++ b/libs/lodash/delay.js @@ -0,0 +1,23 @@ +/** + * Invokes `func` after `wait` milliseconds. Any additional arguments are + * provided to `func` when it's invoked. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * delay(text => console.log(text), 1000, 'later') + * // => Logs 'later' after one second. + */ +function delay(func, wait, ...args) { + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + return setTimeout(func, +wait || 0, ...args) +} + +export default delay diff --git a/libs/lodash/difference.js b/libs/lodash/difference.js new file mode 100644 index 0000000..6a25b1e --- /dev/null +++ b/libs/lodash/difference.js @@ -0,0 +1,30 @@ +import baseDifference from './.internal/baseDifference.js' +import baseFlatten from './.internal/baseFlatten.js' +import isArrayLikeObject from './isArrayLikeObject.js' + +/** + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * **Note:** Unlike `pullAll`, this method returns a new array. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see union, unionBy, unionWith, without, xor, xorBy, xorWith, + * @example + * + * difference([2, 1], [2, 3]) + * // => [1] + */ +function difference(array, ...values) { + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) + : [] +} + +export default difference diff --git a/libs/lodash/differenceBy.js b/libs/lodash/differenceBy.js new file mode 100644 index 0000000..f4c063e --- /dev/null +++ b/libs/lodash/differenceBy.js @@ -0,0 +1,36 @@ +import baseDifference from './.internal/baseDifference.js' +import baseFlatten from './.internal/baseFlatten.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `difference` except that it accepts `iteratee` which + * is invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * **Note:** Unlike `pullAllBy`, this method returns a new array. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor) + * // => [1.2] + */ +function differenceBy(array, ...values) { + let iteratee = last(values) + if (isArrayLikeObject(iteratee)) { + iteratee = undefined + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), iteratee) + : [] +} + +export default differenceBy diff --git a/libs/lodash/differenceWith.js b/libs/lodash/differenceWith.js new file mode 100644 index 0000000..542cf2a --- /dev/null +++ b/libs/lodash/differenceWith.js @@ -0,0 +1,37 @@ +import baseDifference from './.internal/baseDifference.js' +import baseFlatten from './.internal/baseFlatten.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `difference` except that it accepts `comparator` + * which is invoked to compare elements of `array` to `values`. The order and + * references of result values are determined by the first array. The comparator + * is invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `pullAllWith`, this method returns a new array. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + * + * differenceWith(objects, [{ 'x': 1, 'y': 2 }], isEqual) + * // => [{ 'x': 2, 'y': 1 }] + */ +function differenceWith(array, ...values) { + let comparator = last(values) + if (isArrayLikeObject(comparator)) { + comparator = undefined + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator) + : [] +} + +export default differenceWith diff --git a/libs/lodash/divide.js b/libs/lodash/divide.js new file mode 100644 index 0000000..70f6f4d --- /dev/null +++ b/libs/lodash/divide.js @@ -0,0 +1,18 @@ +import createMathOperation from './.internal/createMathOperation.js' + +/** + * Divide two numbers. + * + * @since 4.7.0 + * @category Math + * @param {number} dividend The first number in a division. + * @param {number} divisor The second number in a division. + * @returns {number} Returns the quotient. + * @example + * + * divide(6, 4) + * // => 1.5 + */ +const divide = createMathOperation((dividend, divisor) => dividend / divisor, 1) + +export default divide diff --git a/libs/lodash/drop.js b/libs/lodash/drop.js new file mode 100644 index 0000000..438f1e2 --- /dev/null +++ b/libs/lodash/drop.js @@ -0,0 +1,33 @@ +import slice from './slice.js' +import toInteger from './toInteger.js' + +/** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @returns {Array} Returns the slice of `array`. + * @example + * + * drop([1, 2, 3]) + * // => [2, 3] + * + * drop([1, 2, 3], 2) + * // => [3] + * + * drop([1, 2, 3], 5) + * // => [] + * + * drop([1, 2, 3], 0) + * // => [1, 2, 3] + */ +function drop(array, n=1) { + const length = array == null ? 0 : array.length + return length + ? slice(array, n < 0 ? 0 : toInteger(n), length) + : [] +} + +export default drop diff --git a/libs/lodash/dropRight.js b/libs/lodash/dropRight.js new file mode 100644 index 0000000..2f023ae --- /dev/null +++ b/libs/lodash/dropRight.js @@ -0,0 +1,32 @@ +import slice from './slice.js' +import toInteger from './toInteger.js' + +/** + * Creates a slice of `array` with `n` elements dropped from the end. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @returns {Array} Returns the slice of `array`. + * @example + * + * dropRight([1, 2, 3]) + * // => [1, 2] + * + * dropRight([1, 2, 3], 2) + * // => [1] + * + * dropRight([1, 2, 3], 5) + * // => [] + * + * dropRight([1, 2, 3], 0) + * // => [1, 2, 3] + */ +function dropRight(array, n=1) { + const length = array == null ? 0 : array.length + n = length - toInteger(n) + return length ? slice(array, 0, n < 0 ? 0 : n) : [] +} + +export default dropRight diff --git a/libs/lodash/dropRightWhile.js b/libs/lodash/dropRightWhile.js new file mode 100644 index 0000000..e209b70 --- /dev/null +++ b/libs/lodash/dropRightWhile.js @@ -0,0 +1,30 @@ +import baseWhile from './.internal/baseWhile.js' + +/** + * Creates a slice of `array` excluding elements dropped from the end. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': true }, + * { 'user': 'pebbles', 'active': true } + * ] + * + * dropRightWhile(users, ({ active }) => active) + * // => objects for ['barney'] + */ +function dropRightWhile(array, predicate) { + return (array != null && array.length) + ? baseWhile(array, predicate, true, true) + : [] +} + +export default dropRightWhile diff --git a/libs/lodash/dropWhile.js b/libs/lodash/dropWhile.js new file mode 100644 index 0000000..88b7b6c --- /dev/null +++ b/libs/lodash/dropWhile.js @@ -0,0 +1,30 @@ +import baseWhile from './.internal/baseWhile.js' + +/** + * Creates a slice of `array` excluding elements dropped from the beginning. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': true }, + * { 'user': 'pebbles', 'active': false } + * ] + * + * dropWhile(users, ({ active }) => active) + * // => objects for ['pebbles'] + */ +function dropWhile(array, predicate) { + return (array != null && array.length) + ? baseWhile(array, predicate, true) + : [] +} + +export default dropWhile diff --git a/libs/lodash/each.js b/libs/lodash/each.js new file mode 100644 index 0000000..d2fd2ff --- /dev/null +++ b/libs/lodash/each.js @@ -0,0 +1 @@ +export { default } from './forEach.js' diff --git a/libs/lodash/eachRight.js b/libs/lodash/eachRight.js new file mode 100644 index 0000000..b08d8f5 --- /dev/null +++ b/libs/lodash/eachRight.js @@ -0,0 +1 @@ +export { default } from './forEachRight.js' diff --git a/libs/lodash/endsWith.js b/libs/lodash/endsWith.js new file mode 100644 index 0000000..9cba731 --- /dev/null +++ b/libs/lodash/endsWith.js @@ -0,0 +1,37 @@ +/** + * Checks if `string` ends with the given target string. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=string.length] The position to search up to. + * @returns {boolean} Returns `true` if `string` ends with `target`, + * else `false`. + * @see includes, startsWith + * @example + * + * endsWith('abc', 'c') + * // => true + * + * endsWith('abc', 'b') + * // => false + * + * endsWith('abc', 'b', 2) + * // => true + */ +function endsWith(string, target, position) { + const { length } = string + position = position === undefined ? length : +position + if (position < 0 || position != position) { + position = 0 + } + else if (position > length) { + position = length + } + const end = position + position -= target.length + return position >= 0 && string.slice(position, end) == target +} + +export default endsWith diff --git a/libs/lodash/eq.js b/libs/lodash/eq.js new file mode 100644 index 0000000..06333c4 --- /dev/null +++ b/libs/lodash/eq.js @@ -0,0 +1,35 @@ +/** + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * comparison between two values to determine if they are equivalent. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * const object = { 'a': 1 } + * const other = { 'a': 1 } + * + * eq(object, object) + * // => true + * + * eq(object, other) + * // => false + * + * eq('a', 'a') + * // => true + * + * eq('a', Object('a')) + * // => false + * + * eq(NaN, NaN) + * // => true + */ +function eq(value, other) { + return value === other || (value !== value && other !== other) +} + +export default eq diff --git a/libs/lodash/eqDeep.js b/libs/lodash/eqDeep.js new file mode 100644 index 0000000..b1870f5 --- /dev/null +++ b/libs/lodash/eqDeep.js @@ -0,0 +1,33 @@ +import baseIsEqual from './.internal/baseIsEqual.js' + +/** + * Performs a deep comparison between two values to determine if they are + * equivalent. + * + * **Note:** This method supports comparing arrays, array buffers, booleans, + * date objects, error objects, maps, numbers, `Object` objects, regexes, + * sets, strings, symbols, and typed arrays. `Object` objects are compared + * by their own, not inherited, enumerable properties. Functions and DOM + * nodes are compared by strict equality, i.e. `===`. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * const object = { 'a': 1 } + * const other = { 'a': 1 } + * + * isEqual(object, other) + * // => true + * + * object === other + * // => false + */ +function isEqual(value, other) { + return baseIsEqual(value, other) +} + +export default isEqual diff --git a/libs/lodash/escape.js b/libs/lodash/escape.js new file mode 100644 index 0000000..eda499a --- /dev/null +++ b/libs/lodash/escape.js @@ -0,0 +1,47 @@ +/** Used to map characters to HTML entities. */ +const htmlEscapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' +} + +/** Used to match HTML entities and HTML characters. */ +const reUnescapedHtml = /[&<>"']/g +const reHasUnescapedHtml = RegExp(reUnescapedHtml.source) + +/** + * Converts the characters "&", "<", ">", '"', and "'" in `string` to their + * corresponding HTML entities. + * + * **Note:** No other characters are escaped. To escape additional + * characters use a third-party library like [_he_](https://mths.be/he). + * + * Though the ">" character is escaped for symmetry, characters like + * ">" and "/" don't need escaping in HTML and have no special meaning + * unless they're part of a tag or unquoted attribute value. See + * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) + * (under "semi-related fun fact") for more details. + * + * When working with HTML you should always + * [quote attribute values](http://wonko.com/post/html-escaping) to reduce + * XSS vectors. + * + * @since 0.1.0 + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @see escapeRegExp, unescape + * @example + * + * escape('fred, barney, & pebbles') + * // => 'fred, barney, & pebbles' + */ +function escape(string) { + return (string && reHasUnescapedHtml.test(string)) + ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) + : (string || '') +} + +export default escape diff --git a/libs/lodash/escapeRegExp.js b/libs/lodash/escapeRegExp.js new file mode 100644 index 0000000..6c77d42 --- /dev/null +++ b/libs/lodash/escapeRegExp.js @@ -0,0 +1,28 @@ +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ +const reRegExpChar = /[\\^$.*+?()[\]{}|]/g +const reHasRegExpChar = RegExp(reRegExpChar.source) + +/** + * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", + * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @see escape, escapeRegExp, unescape + * @example + * + * escapeRegExp('[lodash](https://lodash.com/)') + * // => '\[lodash\]\(https://lodash\.com/\)' + */ +function escapeRegExp(string) { + return (string && reHasRegExpChar.test(string)) + ? string.replace(reRegExpChar, '\\$&') + : (string || '') +} + +export default escapeRegExp diff --git a/libs/lodash/every.js b/libs/lodash/every.js new file mode 100644 index 0000000..045cde6 --- /dev/null +++ b/libs/lodash/every.js @@ -0,0 +1,34 @@ +/** + * Checks if `predicate` returns truthy for **all** elements of `array`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * **Note:** This method returns `true` for + * [empty arrays](https://en.wikipedia.org/wiki/Empty_set) because + * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of + * elements of empty arrays. + * + * @since 5.0.0 + * @category Array + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + * @example + * + * every([true, 1, null, 'yes'], Boolean) + * // => false + */ +function every(array, predicate) { + let index = -1 + const length = array == null ? 0 : array.length + + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false + } + } + return true +} + +export default every diff --git a/libs/lodash/everyValue.js b/libs/lodash/everyValue.js new file mode 100644 index 0000000..bec5e7a --- /dev/null +++ b/libs/lodash/everyValue.js @@ -0,0 +1,34 @@ +/** + * Checks if `predicate` returns truthy for **all** properties of `object`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, key, object). + * + * **Note:** This method returns `true` for + * [empty objects](https://en.wikipedia.org/wiki/Empty_set) because + * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of + * elements of empty objects. + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all properties pass the predicate check, + * else `false`. + * @example + * + * everyValue({ 'a': 0, 'b': 'yes', 'c': false }, Boolean) + * // => false + */ +function everyValue(object, predicate) { + object = Object(object) + const props = Object.keys(object) + + for (const key of props) { + if (!predicate(object[key], key, object)) { + return false + } + } + return true +} + +export default everyValue diff --git a/libs/lodash/filter.js b/libs/lodash/filter.js new file mode 100644 index 0000000..98606e5 --- /dev/null +++ b/libs/lodash/filter.js @@ -0,0 +1,39 @@ +/** + * Iterates over elements of `array`, returning an array of all elements + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index, array). + * + * **Note:** Unlike `remove`, this method returns a new array. + * + * @since 5.0.0 + * @category Array + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ] + * + * filter(users, ({ active }) => active) + * // => objects for ['barney'] + */ +function filter(array, predicate) { + let index = -1 + let resIndex = 0 + const length = array == null ? 0 : array.length + const result = [] + + while (++index < length) { + const value = array[index] + if (predicate(value, index, array)) { + result[resIndex++] = value + } + } + return result +} + +export default filter diff --git a/libs/lodash/filterObject.js b/libs/lodash/filterObject.js new file mode 100644 index 0000000..08631f5 --- /dev/null +++ b/libs/lodash/filterObject.js @@ -0,0 +1,34 @@ +/** + * Iterates over properties of `object`, returning an array of all elements + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, key, object). + * + * If you want an object in return, consider `pickBy`. + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see pickBy, pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, reject + * @example + * + * const object = { 'a': 5, 'b': 8, 'c': 10 } + * + * filterObject(object, (n) => !(n % 5)) + * // => [5, 10] + */ +function filterObject(object, predicate) { + object = Object(object) + const result = [] + + Object.keys(object).forEach((key) => { + const value = object[key] + if (predicate(value, key, object)) { + result.push(value) + } + }) + return result +} + +export default filterObject diff --git a/libs/lodash/findKey.js b/libs/lodash/findKey.js new file mode 100644 index 0000000..1cced32 --- /dev/null +++ b/libs/lodash/findKey.js @@ -0,0 +1,38 @@ +/** + * This method is like `find` except that it returns the key of the first + * element `predicate` returns truthy for instead of the element itself. + * + * @since 1.1.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} predicate The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @see find, findIndex, findLast, findLastIndex, findLastKey + * @example + * + * const users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * } + * + * findKey(users, ({ age }) => age < 40) + * // => 'barney' (iteration order is not guaranteed) + */ +function findKey(object, predicate) { + let result + if (object == null) { + return result + } + Object.keys(object).some((key) => { + const value = object[key] + if (predicate(value, key, object)) { + result = key + return true + } + }) + return result +} + +export default findKey diff --git a/libs/lodash/findLast.js b/libs/lodash/findLast.js new file mode 100644 index 0000000..391b5e9 --- /dev/null +++ b/libs/lodash/findLast.js @@ -0,0 +1,32 @@ +import findLastIndex from './findLastIndex.js' +import isArrayLike from './isArrayLike.js' + +/** + * This method is like `find` except that it iterates over elements of + * `collection` from right to left. + * + * @since 2.0.0 + * @category Collection + * @param {Array|Object} collection The collection to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} [fromIndex=collection.length-1] The index to search from. + * @returns {*} Returns the matched element, else `undefined`. + * @see find, findIndex, findKey, findLastIndex, findLastKey + * @example + * + * findLast([1, 2, 3, 4], n => n % 2 == 1) + * // => 3 + */ +function findLast(collection, predicate, fromIndex) { + let iteratee + const iterable = Object(collection) + if (!isArrayLike(collection)) { + collection = Object.keys(collection) + iteratee = predicate + predicate = (key) => iteratee(iterable[key], key, iterable) + } + const index = findLastIndex(collection, predicate, fromIndex) + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined +} + +export default findLast diff --git a/libs/lodash/findLastIndex.js b/libs/lodash/findLastIndex.js new file mode 100644 index 0000000..f38fc08 --- /dev/null +++ b/libs/lodash/findLastIndex.js @@ -0,0 +1,41 @@ +import baseFindIndex from './.internal/baseFindIndex.js' +import toInteger from './toInteger.js' + +/** + * This method is like `findIndex` except that it iterates over elements + * of `collection` from right to left. + * + * @since 2.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the found element, else `-1`. + * @see find, findIndex, findKey, findLast, findLastKey + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ] + * + * findLastIndex(users, ({ user }) => user == 'pebbles') + * // => 2 + */ +function findLastIndex(array, predicate, fromIndex) { + const length = array == null ? 0 : array.length + if (!length) { + return -1 + } + let index = length - 1 + if (fromIndex !== undefined) { + index = toInteger(fromIndex) + index = fromIndex < 0 + ? Math.max(length + index, 0) + : Math.min(index, length - 1) + } + return baseFindIndex(array, predicate, index, true) +} + +export default findLastIndex diff --git a/libs/lodash/findLastKey.js b/libs/lodash/findLastKey.js new file mode 100644 index 0000000..879f3ad --- /dev/null +++ b/libs/lodash/findLastKey.js @@ -0,0 +1,30 @@ +import baseFindKey from './.internal/baseFindKey.js' +import baseForOwnRight from './.internal/baseForOwnRight.js' + +/** + * This method is like `findKey` except that it iterates over elements of + * a collection in the opposite order. + * + * @since 2.0.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} predicate The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @see find, findIndex, findKey, findLast, findLastIndex + * @example + * + * const users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * } + * + * findLastKey(users, ({ age }) => age < 40) + * // => returns 'pebbles' assuming `findKey` returns 'barney' + */ +function findLastKey(object, predicate) { + return baseFindKey(object, predicate, baseForOwnRight) +} + +export default findLastKey diff --git a/libs/lodash/first.js b/libs/lodash/first.js new file mode 100644 index 0000000..db707ff --- /dev/null +++ b/libs/lodash/first.js @@ -0,0 +1 @@ +export { default } from './head.js' diff --git a/libs/lodash/flatMap.js b/libs/lodash/flatMap.js new file mode 100644 index 0000000..54d8844 --- /dev/null +++ b/libs/lodash/flatMap.js @@ -0,0 +1,28 @@ +import baseFlatten from './.internal/baseFlatten.js' +import map from './map.js' + +/** + * Creates a flattened array of values by running each element in `collection` + * thru `iteratee` and flattening the mapped results. The iteratee is invoked + * with three arguments: (value, index|key, collection). + * + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @see flatMapDeep, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues + * @example + * + * function duplicate(n) { + * return [n, n] + * } + * + * flatMap([1, 2], duplicate) + * // => [1, 1, 2, 2] + */ +function flatMap(collection, iteratee) { + return baseFlatten(map(collection, iteratee), 1) +} + +export default flatMap diff --git a/libs/lodash/flatMapDeep.js b/libs/lodash/flatMapDeep.js new file mode 100644 index 0000000..9c9c5d8 --- /dev/null +++ b/libs/lodash/flatMapDeep.js @@ -0,0 +1,30 @@ +import baseFlatten from './.internal/baseFlatten.js' +import map from './map.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** + * This method is like `flatMap` except that it recursively flattens the + * mapped results. + * + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @see flatMap, flatMapDepth, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues + * @example + * + * function duplicate(n) { + * return [[[n, n]]] + * } + * + * flatMapDeep([1, 2], duplicate) + * // => [1, 1, 2, 2] + */ +function flatMapDeep(collection, iteratee) { + return baseFlatten(map(collection, iteratee), INFINITY) +} + +export default flatMapDeep diff --git a/libs/lodash/flatMapDepth.js b/libs/lodash/flatMapDepth.js new file mode 100644 index 0000000..8a1ee20 --- /dev/null +++ b/libs/lodash/flatMapDepth.js @@ -0,0 +1,29 @@ +import baseFlatten from './.internal/baseFlatten.js' +import map from './map.js' + +/** + * This method is like `flatMap` except that it recursively flattens the + * mapped results up to `depth` times. + * + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @see flatMap, flatMapDeep, flatten, flattenDeep, flattenDepth, map, mapKeys, mapValues + * @example + * + * function duplicate(n) { + * return [[[n, n]]] + * } + * + * flatMapDepth([1, 2], duplicate, 2) + * // => [[1, 1], [2, 2]] + */ +function flatMapDepth(collection, iteratee, depth) { + depth = depth === undefined ? 1 : +depth + return baseFlatten(map(collection, iteratee), depth) +} + +export default flatMapDepth diff --git a/libs/lodash/flatten.js b/libs/lodash/flatten.js new file mode 100644 index 0000000..75a834c --- /dev/null +++ b/libs/lodash/flatten.js @@ -0,0 +1,21 @@ +import baseFlatten from './.internal/baseFlatten.js' + +/** + * Flattens `array` a single level deep. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @see flatMap, flatMapDeep, flatMapDepth, flattenDeep, flattenDepth + * @example + * + * flatten([1, [2, [3, [4]], 5]]) + * // => [1, 2, [3, [4]], 5] + */ +function flatten(array) { + const length = array == null ? 0 : array.length + return length ? baseFlatten(array, 1) : [] +} + +export default flatten diff --git a/libs/lodash/flattenDeep.js b/libs/lodash/flattenDeep.js new file mode 100644 index 0000000..8a96f58 --- /dev/null +++ b/libs/lodash/flattenDeep.js @@ -0,0 +1,24 @@ +import baseFlatten from './.internal/baseFlatten.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** + * Recursively flattens `array`. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @see flatMap, flatMapDeep, flatMapDepth, flatten, flattenDepth + * @example + * + * flattenDeep([1, [2, [3, [4]], 5]]) + * // => [1, 2, 3, 4, 5] + */ +function flattenDeep(array) { + const length = array == null ? 0 : array.length + return length ? baseFlatten(array, INFINITY) : [] +} + +export default flattenDeep diff --git a/libs/lodash/flattenDepth.js b/libs/lodash/flattenDepth.js new file mode 100644 index 0000000..0a8c456 --- /dev/null +++ b/libs/lodash/flattenDepth.js @@ -0,0 +1,31 @@ +import baseFlatten from './.internal/baseFlatten.js' + +/** + * Recursively flatten `array` up to `depth` times. + * + * @since 4.4.0 + * @category Array + * @param {Array} array The array to flatten. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @see flatMap, flatMapDeep, flatMapDepth, flattenDeep + * @example + * + * const array = [1, [2, [3, [4]], 5]] + * + * flattenDepth(array, 1) + * // => [1, 2, [3, [4]], 5] + * + * flattenDepth(array, 2) + * // => [1, 2, 3, [4], 5] + */ +function flattenDepth(array, depth) { + const length = array == null ? 0 : array.length + if (!length) { + return [] + } + depth = depth === undefined ? 1 : +depth + return baseFlatten(array, depth) +} + +export default flattenDepth diff --git a/libs/lodash/flip.js b/libs/lodash/flip.js new file mode 100644 index 0000000..99297aa --- /dev/null +++ b/libs/lodash/flip.js @@ -0,0 +1,25 @@ +/** + * Creates a function that invokes `func` with arguments reversed. + * + * @since 4.0.0 + * @category Function + * @param {Function} func The function to flip arguments for. + * @returns {Function} Returns the new flipped function. + * @see reverse + * @example + * + * const flipped = flip((...args) => args) + * + * flipped('a', 'b', 'c', 'd') + * // => ['d', 'c', 'b', 'a'] + */ +function flip(func) { + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + return function(...args) { + return func.apply(this, args.reverse()) + } +} + +export default flip diff --git a/libs/lodash/floor.js b/libs/lodash/floor.js new file mode 100644 index 0000000..b9124a6 --- /dev/null +++ b/libs/lodash/floor.js @@ -0,0 +1,24 @@ +import createRound from './.internal/createRound.js' + +/** + * Computes `number` rounded down to `precision`. + * + * @since 3.10.0 + * @category Math + * @param {number} number The number to round down. + * @param {number} [precision=0] The precision to round down to. + * @returns {number} Returns the rounded down number. + * @example + * + * floor(4.006) + * // => 4 + * + * floor(0.046, 2) + * // => 0.04 + * + * floor(4060, -2) + * // => 4000 + */ +const floor = createRound('floor') + +export default floor diff --git a/libs/lodash/flow.js b/libs/lodash/flow.js new file mode 100644 index 0000000..c797a72 --- /dev/null +++ b/libs/lodash/flow.js @@ -0,0 +1,41 @@ +/** + * Composes a function that returns the result of invoking the given functions + * with the `this` binding of the created function, where each successive + * invocation is supplied the return value of the previous. + * + * @since 3.0.0 + * @category Util + * @param {Function[]} [funcs] The functions to invoke. + * @returns {Function} Returns the new composite function. + * @see flowRight + * @example + * + * import add from 'lodash/add' + * + * function square(n) { + * return n * n + * } + * + * const addSquare = flow(add, square) + * addSquare(1, 2) + * // => 9 + */ +function flow(...funcs) { + const length = funcs.length + let index = length + while (index--) { + if (typeof funcs[index] !== 'function') { + throw new TypeError('Expected a function') + } + } + return function(...args) { + let index = 0 + let result = length ? funcs[index].apply(this, args) : args[0] + while (++index < length) { + result = funcs[index].call(this, result) + } + return result + } +} + +export default flow diff --git a/libs/lodash/flowRight.js b/libs/lodash/flowRight.js new file mode 100644 index 0000000..c1fafff --- /dev/null +++ b/libs/lodash/flowRight.js @@ -0,0 +1,28 @@ +import flow from './flow.js' + +/** + * This method is like `flow` except that it composes a function that + * invokes the given functions from right to left. + * + * @since 3.0.0 + * @category Util + * @param {Function[]} [funcs] The functions to invoke. + * @returns {Function} Returns the new composite function. + * @see flow + * @example + * + * import add from 'lodash/add' + * + * function square(n) { + * return n * n + * } + * + * const addSquare = flowRight(square, add) + * addSquare(1, 2) + * // => 9 + */ +function flowRight(...funcs) { + return flow(...funcs.reverse()) +} + +export default flowRight diff --git a/libs/lodash/forEach.js b/libs/lodash/forEach.js new file mode 100644 index 0000000..facccb0 --- /dev/null +++ b/libs/lodash/forEach.js @@ -0,0 +1,33 @@ +import arrayEach from './.internal/arrayEach.js' +import baseEach from './.internal/baseEach.js' + +/** + * Iterates over elements of `collection` and invokes `iteratee` for each element. + * The iteratee is invoked with three arguments: (value, index|key, collection). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * **Note:** As with other "Collections" methods, objects with a "length" + * property are iterated like arrays. To avoid this behavior use `forIn` + * or `forOwn` for object iteration. + * + * @since 0.1.0 + * @alias each + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see forEachRight, forIn, forInRight, forOwn, forOwnRight + * @example + * + * forEach([1, 2], value => console.log(value)) + * // => Logs `1` then `2`. + * + * forEach({ 'a': 1, 'b': 2 }, (value, key) => console.log(key)) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ +function forEach(collection, iteratee) { + const func = Array.isArray(collection) ? arrayEach : baseEach + return func(collection, iteratee) +} + +export default forEach diff --git a/libs/lodash/forEachRight.js b/libs/lodash/forEachRight.js new file mode 100644 index 0000000..b8682b9 --- /dev/null +++ b/libs/lodash/forEachRight.js @@ -0,0 +1,25 @@ +import arrayEachRight from './.internal/arrayEachRight.js' +import baseEachRight from './.internal/baseEachRight.js' + +/** + * This method is like `forEach` except that it iterates over elements of + * `collection` from right to left. + * + * @since 2.0.0 + * @alias eachRight + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see forEach, forIn, forInRight, forOwn, forOwnRight + * @example + * + * forEachRight([1, 2], value => console.log(value)) + * // => Logs `2` then `1`. + */ +function forEachRight(collection, iteratee) { + const func = Array.isArray(collection) ? arrayEachRight : baseEachRight + return func(collection, iteratee) +} + +export default forEachRight diff --git a/libs/lodash/forOwn.js b/libs/lodash/forOwn.js new file mode 100644 index 0000000..40ea48b --- /dev/null +++ b/libs/lodash/forOwn.js @@ -0,0 +1,31 @@ +/** + * Iterates over own enumerable string keyed properties of an object and + * invokes `iteratee` for each property. The iteratee is invoked with three + * arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. + * + * @since 0.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @see forEach, forEachRight, forIn, forInRight, forOwnRight + * @example + * + * function Foo() { + * this.a = 1 + * this.b = 2 + * } + * + * Foo.prototype.c = 3 + * + * forOwn(new Foo, function(value, key) { + * console.log(key) + * }) + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ +function forOwn(object, iteratee) { + object = Object(object) + Object.keys(object).forEach((key) => iteratee(object[key], key, object)) +} + +export default forOwn diff --git a/libs/lodash/forOwnRight.js b/libs/lodash/forOwnRight.js new file mode 100644 index 0000000..5fbfbd5 --- /dev/null +++ b/libs/lodash/forOwnRight.js @@ -0,0 +1,36 @@ +/** + * This method is like `forOwn` except that it iterates over properties of + * `object` in the opposite order. + * + * @since 2.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see forEach, forEachRight, forIn, forInRight, forOwn + * @example + * + * function Foo() { + * this.a = 1 + * this.b = 2 + * } + * + * Foo.prototype.c = 3 + * + * forOwnRight(new Foo, function(value, key) { + * console.log(key) + * }) + * // => Logs 'b' then 'a' assuming `forOwn` logs 'a' then 'b'. + */ +function forOwnRight(object, iteratee) { + if (object == null) { + return + } + const props = Object.keys(object) + let length = props.length + while (length--) { + iteratee(object[props[length]], iteratee, object) + } +} + +export default forOwnRight diff --git a/libs/lodash/fromEntries.js b/libs/lodash/fromEntries.js new file mode 100644 index 0000000..cd21ba0 --- /dev/null +++ b/libs/lodash/fromEntries.js @@ -0,0 +1,25 @@ +/** + * The inverse of `entries`is method returns an object composed + * from key-value `pairs`. + * + * @since 4.0.0 + * @category Array + * @param {Array} pairs The key-value pairs. + * @returns {Object} Returns the new object. + * @example + * + * fromEntries([['a', 1], ['b', 2]]) + * // => { 'a': 1, 'b': 2 } + */ +function fromEntries(pairs) { + const result = {} + if (pairs == null) { + return result + } + for (const pair of pairs) { + result[pair[0]] = pair[1] + } + return result +} + +export default fromEntries diff --git a/libs/lodash/functions.js b/libs/lodash/functions.js new file mode 100644 index 0000000..f59d8a7 --- /dev/null +++ b/libs/lodash/functions.js @@ -0,0 +1,29 @@ +/** + * Creates an array of function property names from own enumerable properties + * of `object`. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The object to inspect. + * @returns {Array} Returns the function names. + * @see functionsIn + * @example + * + * function Foo() { + * this.a = () => 'a' + * this.b = () => 'b' + * } + * + * Foo.prototype.c = () => 'c' + * + * functions(new Foo) + * // => ['a', 'b'] + */ +function functions(object) { + if (object == null) { + return [] + } + return Object.keys(object).filter((key) => typeof object[key] === 'function') +} + +export default functions diff --git a/libs/lodash/get.js b/libs/lodash/get.js new file mode 100644 index 0000000..ca4354c --- /dev/null +++ b/libs/lodash/get.js @@ -0,0 +1,32 @@ +import baseGet from './.internal/baseGet.js' + +/** + * Gets the value at `path` of `object`. If the resolved value is + * `undefined`, the `defaultValue` is returned in its place. + * + * @since 3.7.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @see has, hasIn, set, unset + * @example + * + * const object = { 'a': [{ 'b': { 'c': 3 } }] } + * + * get(object, 'a[0].b.c') + * // => 3 + * + * get(object, ['a', '0', 'b', 'c']) + * // => 3 + * + * get(object, 'a.b.c', 'default') + * // => 'default' + */ +function get(object, path, defaultValue) { + const result = object == null ? undefined : baseGet(object, path) + return result === undefined ? defaultValue : result +} + +export default get diff --git a/libs/lodash/groupBy.js b/libs/lodash/groupBy.js new file mode 100644 index 0000000..03b5ea5 --- /dev/null +++ b/libs/lodash/groupBy.js @@ -0,0 +1,36 @@ +import baseAssignValue from './.internal/baseAssignValue.js' +import reduce from './reduce.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The order of grouped values + * is determined by the order they occur in `collection`. The corresponding + * value of each key is an array of elements responsible for generating the + * key. The iteratee is invoked with one argument: (value). + * + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * groupBy([6.1, 4.2, 6.3], Math.floor) + * // => { '4': [4.2], '6': [6.1, 6.3] } + */ +function groupBy(collection, iteratee) { + return reduce(collection, (result, value, key) => { + key = iteratee(value) + if (hasOwnProperty.call(result, key)) { + result[key].push(value) + } else { + baseAssignValue(result, key, [value]) + } + return result + }, {}) +} + +export default groupBy diff --git a/libs/lodash/gt.js b/libs/lodash/gt.js new file mode 100644 index 0000000..5359e16 --- /dev/null +++ b/libs/lodash/gt.js @@ -0,0 +1,30 @@ +/** + * Checks if `value` is greater than `other`. + * + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + * @see gte, lt, lte + * @example + * + * gt(3, 1) + * // => true + * + * gt(3, 3) + * // => false + * + * gt(1, 3) + * // => false + */ +function gt(value, other) { + if (!(typeof value === 'string' && typeof other === 'string')) { + value = +value + other = +other + } + return value > other +} + +export default gt diff --git a/libs/lodash/gte.js b/libs/lodash/gte.js new file mode 100644 index 0000000..b6fa0e5 --- /dev/null +++ b/libs/lodash/gte.js @@ -0,0 +1,30 @@ +/** + * Checks if `value` is greater than or equal to `other`. + * + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than or equal to + * `other`, else `false`. + * @see gt, lt, lte + * @example + * + * gte(3, 1) + * // => true + * + * gte(3, 3) + * // => true + * + * gte(1, 3) + * // => false + */ +function gte(value, other) { + if (!(typeof value === 'string' && typeof other === 'string')) { + value = +value + other = +other + } + return value >= other +} + +export default gte diff --git a/libs/lodash/has.js b/libs/lodash/has.js new file mode 100644 index 0000000..9cec79d --- /dev/null +++ b/libs/lodash/has.js @@ -0,0 +1,28 @@ +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Checks if `key` is a direct property of `object`. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The object to query. + * @param {string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + * @see hasIn, hasPath, hasPathIn + * @example + * + * const object = { 'a': { 'b': 2 } } + * const other = create({ 'a': create({ 'b': 2 }) }) + * + * has(object, 'a') + * // => true + * + * has(other, 'a') + * // => false + */ +function has(object, key) { + return object != null && hasOwnProperty.call(object, key) +} + +export default has diff --git a/libs/lodash/hasIn.js b/libs/lodash/hasIn.js new file mode 100644 index 0000000..71d35d5 --- /dev/null +++ b/libs/lodash/hasIn.js @@ -0,0 +1,24 @@ +/** + * Checks if `path` is a direct or inherited property of `object`. + * + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + * @see has, hasPath, hasPathIn + * @example + * + * const object = create({ 'a': create({ 'b': 2 }) }) + * + * hasIn(object, 'a') + * // => true + * + * hasIn(object, 'b') + * // => false + */ +function hasIn(object, key) { + return object != null && key in Object(object) +} + +export default hasIn diff --git a/libs/lodash/hasPath.js b/libs/lodash/hasPath.js new file mode 100644 index 0000000..2a3a7fb --- /dev/null +++ b/libs/lodash/hasPath.js @@ -0,0 +1,53 @@ +import castPath from './.internal/castPath.js' +import isArguments from './isArguments.js' +import isIndex from './.internal/isIndex.js' +import isLength from './isLength.js' +import toKey from './.internal/toKey.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Checks if `path` is a direct property of `object`. + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @see has, hasIn, hasPathIn + * @example + * + * const object = { 'a': { 'b': 2 } } + * const other = create({ 'a': create({ 'b': 2 }) }) + * + * hasPath(object, 'a.b') + * // => true + * + * hasPath(object, ['a', 'b']) + * // => true + */ +function hasPath(object, path) { + path = castPath(path, object) + + let index = -1 + let { length } = path + let result = false + let key + + while (++index < length) { + key = toKey(path[index]) + if (!(result = object != null && hasOwnProperty.call(object, key))) { + break + } + object = object[key] + } + if (result || ++index != length) { + return result + } + length = object == null ? 0 : object.length + return !!length && isLength(length) && isIndex(key, length) && + (Array.isArray(object) || isArguments(object)) +} + +export default hasPath diff --git a/libs/lodash/hasPathIn.js b/libs/lodash/hasPathIn.js new file mode 100644 index 0000000..5b9b5a2 --- /dev/null +++ b/libs/lodash/hasPathIn.js @@ -0,0 +1,50 @@ +import castPath from './.internal/castPath.js' +import isArguments from './isArguments.js' +import isIndex from './.internal/isIndex.js' +import isLength from './isLength.js' +import toKey from './.internal/toKey.js' + +/** + * Checks if `path` is a direct property of `object`. + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @see has, hasIn hasPath + * @example + * + * const object = { 'a': { 'b': 2 } } + * const other = create({ 'a': create({ 'b': 2 }) }) + * + * hasPathIn(object, 'a.b') + * // => true + * + * hasPathIn(object, ['a', 'b']) + * // => true + */ +function hasPathIn(object, path) { + path = castPath(path, object) + + let index = -1 + let { length } = path + let result = false + let key + + while (++index < length) { + key = toKey(path[index]) + if (!(result = object != null && key in Object(object))) { + break + } + object = object[key] + } + if (result || ++index != length) { + return result + } + length = object == null ? 0 : object.length + return !!length && isLength(length) && isIndex(key, length) && + (Array.isArray(object) || isArguments(object)) +} + +export default hasPathIn diff --git a/libs/lodash/head.js b/libs/lodash/head.js new file mode 100644 index 0000000..a9df411 --- /dev/null +++ b/libs/lodash/head.js @@ -0,0 +1,24 @@ +/** + * Gets the first element of `array`. + * + * @since 0.1.0 + * @alias first + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the first element of `array`. + * @see last + * @example + * + * head([1, 2, 3]) + * // => 1 + * + * head([]) + * // => undefined + */ +function head(array) { + return (array != null && array.length) + ? array[0] + : undefined +} + +export default head diff --git a/libs/lodash/inRange.js b/libs/lodash/inRange.js new file mode 100644 index 0000000..ce2962d --- /dev/null +++ b/libs/lodash/inRange.js @@ -0,0 +1,47 @@ +import baseInRange from './.internal/baseInRange.js' + +/** + * Checks if `number` is between `start` and up to, but not including, `end`. If + * `end` is not specified, it's set to `start` with `start` then set to `0`. + * If `start` is greater than `end` the params are swapped to support + * negative ranges. + * + * @since 3.3.0 + * @category Number + * @param {number} number The number to check. + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + * @see range, rangeRight + * @example + * + * inRange(3, 2, 4) + * // => true + * + * inRange(4, 8) + * // => true + * + * inRange(4, 2) + * // => false + * + * inRange(2, 2) + * // => false + * + * inRange(1.2, 2) + * // => true + * + * inRange(5.2, 4) + * // => false + * + * inRange(-3, -2, -6) + * // => true + */ +function inRange(number, start, end) { + if (end === undefined) { + end = start + start = 0 + } + return baseInRange(+number, +start, +end) +} + +export default inRange diff --git a/libs/lodash/indexOf.js b/libs/lodash/indexOf.js new file mode 100644 index 0000000..358fff4 --- /dev/null +++ b/libs/lodash/indexOf.js @@ -0,0 +1,37 @@ +import baseIndexOf from './.internal/baseIndexOf.js' +import toInteger from './toInteger.js' + +/** + * Gets the index at which the first occurrence of `value` is found in `array` + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it's used as the + * offset from the end of `array`. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * indexOf([1, 2, 1, 2], 2) + * // => 1 + * + * // Search from the `fromIndex`. + * indexOf([1, 2, 1, 2], 2, 2) + * // => 3 + */ +function indexOf(array, value, fromIndex) { + const length = array == null ? 0 : array.length + if (!length) { + return -1 + } + let index = fromIndex == null ? 0 : toInteger(fromIndex) + if (index < 0) { + index = Math.max(length + index, 0) + } + return baseIndexOf(array, value, index) +} + +export default indexOf diff --git a/libs/lodash/initial.js b/libs/lodash/initial.js new file mode 100644 index 0000000..1a4b1d8 --- /dev/null +++ b/libs/lodash/initial.js @@ -0,0 +1,20 @@ +import slice from './slice.js' + +/** + * Gets all but the last element of `array`. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * initial([1, 2, 3]) + * // => [1, 2] + */ +function initial(array) { + const length = array == null ? 0 : array.length + return length ? slice(array, 0, -1) : [] +} + +export default initial diff --git a/libs/lodash/intersection.js b/libs/lodash/intersection.js new file mode 100644 index 0000000..0b16d3b --- /dev/null +++ b/libs/lodash/intersection.js @@ -0,0 +1,27 @@ +import map from './map.js' +import baseIntersection from './.internal/baseIntersection.js' +import castArrayLikeObject from './.internal/castArrayLikeObject.js' + +/** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * intersection([2, 1], [2, 3]) + * // => [2] + */ +function intersection(...arrays) { + const mapped = map(arrays, castArrayLikeObject) + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : [] +} + +export default intersection diff --git a/libs/lodash/intersectionBy.js b/libs/lodash/intersectionBy.js new file mode 100644 index 0000000..3f1f852 --- /dev/null +++ b/libs/lodash/intersectionBy.js @@ -0,0 +1,37 @@ +import map from './map.js' +import baseIntersection from './.internal/baseIntersection.js' +import castArrayLikeObject from './.internal/castArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `intersection` except that it accepts `iteratee` + * which is invoked for each element of each `arrays` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor) + * // => [2.1] + */ +function intersectionBy(...arrays) { + let iteratee = last(arrays) + const mapped = map(arrays, castArrayLikeObject) + + if (iteratee === last(mapped)) { + iteratee = undefined + } else { + mapped.pop() + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, iteratee) + : [] +} + +export default intersectionBy diff --git a/libs/lodash/intersectionWith.js b/libs/lodash/intersectionWith.js new file mode 100644 index 0000000..7621de8 --- /dev/null +++ b/libs/lodash/intersectionWith.js @@ -0,0 +1,38 @@ +import map from './map.js' +import baseIntersection from './.internal/baseIntersection.js' +import castArrayLikeObject from './.internal/castArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `intersection` except that it accepts `comparator` + * which is invoked to compare elements of `arrays`. The order and references + * of result values are determined by the first array. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + * const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }] + * + * intersectionWith(objects, others, isEqual) + * // => [{ 'x': 1, 'y': 2 }] + */ +function intersectionWith(...arrays) { + let comparator = last(arrays) + const mapped = map(arrays, castArrayLikeObject) + + comparator = typeof comparator === 'function' ? comparator : undefined + if (comparator) { + mapped.pop() + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, undefined, comparator) + : [] +} + +export default intersectionWith diff --git a/libs/lodash/invert.js b/libs/lodash/invert.js new file mode 100644 index 0000000..f6e6739 --- /dev/null +++ b/libs/lodash/invert.js @@ -0,0 +1,31 @@ +const toString = Object.prototype.toString + +/** + * Creates an object composed of the inverted keys and values of `object`. + * If `object` contains duplicate values, subsequent values overwrite + * property assignments of previous values. + * + * @since 0.7.0 + * @category Object + * @param {Object} object The object to invert. + * @returns {Object} Returns the new inverted object. + * @example + * + * const object = { 'a': 1, 'b': 2, 'c': 1 } + * + * invert(object) + * // => { '1': 'c', '2': 'b' } + */ +function invert(object) { + const result = {} + Object.keys(object).forEach((key) => { + let value = object[key] + if (value != null && typeof value.toString !== 'function') { + value = toString.call(value) + } + result[value] = key + }) + return result +} + +export default invert diff --git a/libs/lodash/invertBy.js b/libs/lodash/invertBy.js new file mode 100644 index 0000000..856f9f7 --- /dev/null +++ b/libs/lodash/invertBy.js @@ -0,0 +1,36 @@ +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * This method is like `invert` except that the inverted object is generated + * from the results of running each element of `object` thru `iteratee`. The + * corresponding inverted value of each inverted key is an array of keys + * responsible for generating the inverted value. The iteratee is invoked + * with one argument: (value). + * + * @since 4.1.0 + * @category Object + * @param {Object} object The object to invert. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Object} Returns the new inverted object. + * @example + * + * const object = { 'a': 1, 'b': 2, 'c': 1 } + * + * invertBy(object, value => `group${value}`) + * // => { 'group1': ['a', 'c'], 'group2': ['b'] } + */ +function invertBy(object, iteratee) { + const result = {} + Object.keys(object).forEach((key) => { + const value = iteratee(object[key]) + if (hasOwnProperty.call(result, value)) { + result[value].push(key) + } else { + result[value] = [key] + } + }) + return result +} + +export default invertBy diff --git a/libs/lodash/invoke.js b/libs/lodash/invoke.js new file mode 100644 index 0000000..6767b99 --- /dev/null +++ b/libs/lodash/invoke.js @@ -0,0 +1,29 @@ +import castPath from './.internal/castPath.js' +import last from './last.js' +import parent from './.internal/parent.js' +import toKey from './.internal/toKey.js' + +/** + * Invokes the method at `path` of `object`. + * + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the method to invoke. + * @param {Array} [args] The arguments to invoke the method with. + * @returns {*} Returns the result of the invoked method. + * @example + * + * const object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] } + * + * invoke(object, 'a[0].b.c.slice', [1, 3]) + * // => [2, 3] + */ +function invoke(object, path, args) { + path = castPath(path, object) + object = parent(object, path) + const func = object == null ? object : object[toKey(last(path))] + return func == null ? undefined : func.apply(object, args) +} + +export default invoke diff --git a/libs/lodash/invokeMap.js b/libs/lodash/invokeMap.js new file mode 100644 index 0000000..f52890b --- /dev/null +++ b/libs/lodash/invokeMap.js @@ -0,0 +1,37 @@ +import baseEach from './.internal/baseEach.js' +import invoke from './invoke.js' +import isArrayLike from './isArrayLike.js' + +/** + * Invokes the method at `path` of each element in `collection`, returning + * an array of the results of each invoked method. Any additional arguments + * are provided to each invoked method. If `path` is a function, it's invoked + * for, and `this` bound to, each element in `collection`. + * + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|string} path The path of the method to invoke or + * the function invoked per iteration. + * @param {Array} [args] The arguments to invoke each method with. + * @returns {Array} Returns the array of results. + * @example + * + * invokeMap([[5, 1, 7], [3, 2, 1]], 'sort') + * // => [[1, 5, 7], [1, 2, 3]] + * + * invokeMap([123, 456], String.prototype.split, ['']) + * // => [['1', '2', '3'], ['4', '5', '6']] + */ +function invokeMap(collection, path, args) { + let index = -1 + const isFunc = typeof path === 'function' + const result = isArrayLike(collection) ? new Array(collection.length) : [] + + baseEach(collection, (value) => { + result[++index] = isFunc ? path.apply(value, args) : invoke(value, path, args) + }) + return result +} + +export default invokeMap diff --git a/libs/lodash/isArguments.js b/libs/lodash/isArguments.js new file mode 100644 index 0000000..acddb7f --- /dev/null +++ b/libs/lodash/isArguments.js @@ -0,0 +1,23 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is likely an `arguments` object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, else `false`. + * @example + * + * isArguments(function() { return arguments }()) + * // => true + * + * isArguments([1, 2, 3]) + * // => false + */ +function isArguments(value) { + return isObjectLike(value) && getTag(value) == '[object Arguments]' +} + +export default isArguments diff --git a/libs/lodash/isArrayBuffer.js b/libs/lodash/isArrayBuffer.js new file mode 100644 index 0000000..add5067 --- /dev/null +++ b/libs/lodash/isArrayBuffer.js @@ -0,0 +1,27 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' +import nodeTypes from './.internal/nodeTypes.js' + +/* Node.js helper references. */ +const nodeIsArrayBuffer = nodeTypes && nodeTypes.isArrayBuffer + +/** + * Checks if `value` is classified as an `ArrayBuffer` object. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + * @example + * + * isArrayBuffer(new ArrayBuffer(2)) + * // => true + * + * isArrayBuffer(new Array(2)) + * // => false + */ +const isArrayBuffer = nodeIsArrayBuffer + ? (value) => nodeIsArrayBuffer(value) + : (value) => isObjectLike(value) && getTag(value) == '[object ArrayBuffer]' + +export default isArrayBuffer diff --git a/libs/lodash/isArrayLike.js b/libs/lodash/isArrayLike.js new file mode 100644 index 0000000..ab72a63 --- /dev/null +++ b/libs/lodash/isArrayLike.js @@ -0,0 +1,30 @@ +import isLength from './isLength.js' + +/** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * isArrayLike([1, 2, 3]) + * // => true + * + * isArrayLike(document.body.children) + * // => true + * + * isArrayLike('abc') + * // => true + * + * isArrayLike(Function) + * // => false + */ +function isArrayLike(value) { + return value != null && typeof value !== 'function' && isLength(value.length) +} + +export default isArrayLike diff --git a/libs/lodash/isArrayLikeObject.js b/libs/lodash/isArrayLikeObject.js new file mode 100644 index 0000000..50ac56b --- /dev/null +++ b/libs/lodash/isArrayLikeObject.js @@ -0,0 +1,31 @@ +import isArrayLike from './isArrayLike.js' +import isObjectLike from './isObjectLike.js' + +/** + * This method is like `isArrayLike` except that it also checks if `value` + * is an object. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. + * @example + * + * isArrayLikeObject([1, 2, 3]) + * // => true + * + * isArrayLikeObject(document.body.children) + * // => true + * + * isArrayLikeObject('abc') + * // => false + * + * isArrayLikeObject(Function) + * // => false + */ +function isArrayLikeObject(value) { + return isObjectLike(value) && isArrayLike(value) +} + +export default isArrayLikeObject diff --git a/libs/lodash/isBoolean.js b/libs/lodash/isBoolean.js new file mode 100644 index 0000000..04a5c53 --- /dev/null +++ b/libs/lodash/isBoolean.js @@ -0,0 +1,24 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is classified as a boolean primitive or object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. + * @example + * + * isBoolean(false) + * // => true + * + * isBoolean(null) + * // => false + */ +function isBoolean(value) { + return value === true || value === false || + (isObjectLike(value) && getTag(value) == '[object Boolean]') +} + +export default isBoolean diff --git a/libs/lodash/isBuffer.js b/libs/lodash/isBuffer.js new file mode 100644 index 0000000..1831fe3 --- /dev/null +++ b/libs/lodash/isBuffer.js @@ -0,0 +1,35 @@ +import root from './.internal/root.js' + +/** Detect free variable `exports`. */ +const freeExports = typeof exports === 'object' && exports !== null && !exports.nodeType && exports + +/** Detect free variable `module`. */ +const freeModule = freeExports && typeof module === 'object' && module !== null && !module.nodeType && module + +/** Detect the popular CommonJS extension `module.exports`. */ +const moduleExports = freeModule && freeModule.exports === freeExports + +/** Built-in value references. */ +const Buffer = moduleExports ? root.Buffer : undefined + +/* Built-in method references for those with the same name as other `lodash` methods. */ +const nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined + +/** + * Checks if `value` is a buffer. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. + * @example + * + * isBuffer(new Buffer(2)) + * // => true + * + * isBuffer(new Uint8Array(2)) + * // => false + */ +const isBuffer = nativeIsBuffer || (() => false) + +export default isBuffer diff --git a/libs/lodash/isDate.js b/libs/lodash/isDate.js new file mode 100644 index 0000000..1486be6 --- /dev/null +++ b/libs/lodash/isDate.js @@ -0,0 +1,27 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' +import nodeTypes from './.internal/nodeTypes.js' + +/* Node.js helper references. */ +const nodeIsDate = nodeTypes && nodeTypes.isDate + +/** + * Checks if `value` is classified as a `Date` object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + * @example + * + * isDate(new Date) + * // => true + * + * isDate('Mon April 23 2012') + * // => false + */ +const isDate = nodeIsDate + ? (value) => nodeIsDate(value) + : (value) => isObjectLike(value) && getTag(value) == '[object Date]' + +export default isDate diff --git a/libs/lodash/isElement.js b/libs/lodash/isElement.js new file mode 100644 index 0000000..636d792 --- /dev/null +++ b/libs/lodash/isElement.js @@ -0,0 +1,23 @@ +import isObjectLike from './isObjectLike.js' +import isPlainObject from './isPlainObject.js' + +/** + * Checks if `value` is likely a DOM element. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @example + * + * isElement(document.body) + * // => true + * + * isElement('') + * // => false + */ +function isElement(value) { + return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value) +} + +export default isElement diff --git a/libs/lodash/isEmpty.js b/libs/lodash/isEmpty.js new file mode 100644 index 0000000..346b051 --- /dev/null +++ b/libs/lodash/isEmpty.js @@ -0,0 +1,69 @@ +import getTag from './.internal/getTag.js' +import isArguments from './isArguments.js' +import isArrayLike from './isArrayLike.js' +import isBuffer from './isBuffer.js' +import isPrototype from './.internal/isPrototype.js' +import isTypedArray from './isTypedArray.js' + +/** Used to check objects for own properties. */ +const hasOwnProperty = Object.prototype.hasOwnProperty + +/** + * Checks if `value` is an empty object, collection, map, or set. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Array-like values such as `arguments` objects, arrays, buffers, strings, or + * jQuery-like collections are considered empty if they have a `length` of `0`. + * Similarly, maps and sets are considered empty if they have a `size` of `0`. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * isEmpty(null) + * // => true + * + * isEmpty(true) + * // => true + * + * isEmpty(1) + * // => true + * + * isEmpty([1, 2, 3]) + * // => false + * + * isEmpty('abc') + * // => false + * + * isEmpty({ 'a': 1 }) + * // => false + */ +function isEmpty(value) { + if (value == null) { + return true + } + if (isArrayLike(value) && + (Array.isArray(value) || typeof value === 'string' || typeof value.splice === 'function' || + isBuffer(value) || isTypedArray(value) || isArguments(value))) { + return !value.length + } + const tag = getTag(value) + if (tag == '[object Map]' || tag == '[object Set]') { + return !value.size + } + if (isPrototype(value)) { + return !Object.keys(value).length + } + for (const key in value) { + if (hasOwnProperty.call(value, key)) { + return false + } + } + return true +} + +export default isEmpty diff --git a/libs/lodash/isEqualWith.js b/libs/lodash/isEqualWith.js new file mode 100644 index 0000000..98ab4f7 --- /dev/null +++ b/libs/lodash/isEqualWith.js @@ -0,0 +1,39 @@ +import baseIsEqual from './.internal/baseIsEqual.js' + +/** + * This method is like `isEqual` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with up to + * six arguments: (objValue, othValue [, index|key, object, other, stack]). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value) + * } + * + * function customizer(objValue, othValue) { + * if (isGreeting(objValue) && isGreeting(othValue)) { + * return true + * } + * } + * + * const array = ['hello', 'goodbye'] + * const other = ['hi', 'goodbye'] + * + * isEqualWith(array, other, customizer) + * // => true + */ +function isEqualWith(value, other, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + const result = customizer ? customizer(value, other) : undefined + return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result +} + +export default isEqualWith diff --git a/libs/lodash/isError.js b/libs/lodash/isError.js new file mode 100644 index 0000000..1e85ff5 --- /dev/null +++ b/libs/lodash/isError.js @@ -0,0 +1,30 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' +import isPlainObject from './isPlainObject.js' + +/** + * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, + * `SyntaxError`, `TypeError`, or `URIError` object. + * + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @example + * + * isError(new Error) + * // => true + * + * isError(Error) + * // => false + */ +function isError(value) { + if (!isObjectLike(value)) { + return false + } + const tag = getTag(value) + return tag == '[object Error]' || tag == '[object DOMException]' || + (typeof value.message === 'string' && typeof value.name === 'string' && !isPlainObject(value)) +} + +export default isError diff --git a/libs/lodash/isFunction.js b/libs/lodash/isFunction.js new file mode 100644 index 0000000..be3f2f8 --- /dev/null +++ b/libs/lodash/isFunction.js @@ -0,0 +1,32 @@ +/** + * Checks if `value` is classified as a `Function` object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * isFunction(class Any{}) + * // => true + * + * isFunction(() => {}) + * // => true + * + * isFunction(async () => {}) + * // => true + * + * isFunction(function * Any() {}) + * // => true + * + * isFunction(Math.round) + * // => true + * + * isFunction(/abc/) + * // => false + */ +function isFunction(value) { + return typeof value === 'function' +} + +export default isFunction diff --git a/libs/lodash/isLength.js b/libs/lodash/isLength.js new file mode 100644 index 0000000..193f254 --- /dev/null +++ b/libs/lodash/isLength.js @@ -0,0 +1,33 @@ +/** Used as references for various `Number` constants. */ +const MAX_SAFE_INTEGER = 9007199254740991 + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * isLength(3) + * // => true + * + * isLength(Number.MIN_VALUE) + * // => false + * + * isLength(Infinity) + * // => false + * + * isLength('3') + * // => false + */ +function isLength(value) { + return typeof value === 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER +} + +export default isLength diff --git a/libs/lodash/isMap.js b/libs/lodash/isMap.js new file mode 100644 index 0000000..1b59892 --- /dev/null +++ b/libs/lodash/isMap.js @@ -0,0 +1,27 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' +import nodeTypes from './.internal/nodeTypes.js' + +/* Node.js helper references. */ +const nodeIsMap = nodeTypes && nodeTypes.isMap + +/** + * Checks if `value` is classified as a `Map` object. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + * @example + * + * isMap(new Map) + * // => true + * + * isMap(new WeakMap) + * // => false + */ +const isMap = nodeIsMap + ? (value) => nodeIsMap(value) + : (value) => isObjectLike(value) && getTag(value) == '[object Map]' + +export default isMap diff --git a/libs/lodash/isMatch.js b/libs/lodash/isMatch.js new file mode 100644 index 0000000..a9c46ad --- /dev/null +++ b/libs/lodash/isMatch.js @@ -0,0 +1,34 @@ +import baseIsMatch from './.internal/baseIsMatch.js' +import getMatchData from './.internal/getMatchData.js' + +/** + * Performs a partial deep comparison between `object` and `source` to + * determine if `object` contains equivalent property values. + * + * **Note:** This method is equivalent to `matches` when `source` is + * partially applied. + * + * Partial comparisons will match empty array and empty object `source` + * values against any array or object value, respectively. See `isEqual` + * for a list of supported value comparisons. + * + * @since 3.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * const object = { 'a': 1, 'b': 2 } + * + * isMatch(object, { 'b': 2 }) + * // => true + * + * isMatch(object, { 'b': 1 }) + * // => false + */ +function isMatch(object, source) { + return object === source || baseIsMatch(object, source, getMatchData(source)) +} + +export default isMatch diff --git a/libs/lodash/isMatchWith.js b/libs/lodash/isMatchWith.js new file mode 100644 index 0000000..79ef07a --- /dev/null +++ b/libs/lodash/isMatchWith.js @@ -0,0 +1,39 @@ +import baseIsMatch from './.internal/baseIsMatch.js' +import getMatchData from './.internal/getMatchData.js' + +/** + * This method is like `isMatch` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with five + * arguments: (objValue, srcValue, index|key, object, source). + * + * @since 4.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value) + * } + * + * function customizer(objValue, srcValue) { + * if (isGreeting(objValue) && isGreeting(srcValue)) { + * return true + * } + * } + * + * const object = { 'greeting': 'hello' } + * const source = { 'greeting': 'hi' } + * + * isMatchWith(object, source, customizer) + * // => true + */ +function isMatchWith(object, source, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + return baseIsMatch(object, source, getMatchData(source), customizer) +} + +export default isMatchWith diff --git a/libs/lodash/isNative.js b/libs/lodash/isNative.js new file mode 100644 index 0000000..2bcd268 --- /dev/null +++ b/libs/lodash/isNative.js @@ -0,0 +1,36 @@ +import isObject from './isObject.js' + +/** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ +const reRegExpChar = /[\\^$.*+?()[\]{}|]/g + +/** Used to detect if a method is native. */ +const reIsNative = RegExp(`^${ + Function.prototype.toString.call(Object.prototype.hasOwnProperty) + .replace(reRegExpChar, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') +}$`) + +/** + * Checks if `value` is a pristine native function. + * + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + * @example + * + * isNative(Array.prototype.push) + * // => true + * + * isNative(isDate) + * // => false + */ +function isNative(value) { + return isObject(value) && reIsNative.test(value) +} + +export default isNative diff --git a/libs/lodash/isNil.js b/libs/lodash/isNil.js new file mode 100644 index 0000000..4a70c9a --- /dev/null +++ b/libs/lodash/isNil.js @@ -0,0 +1,23 @@ +/** + * Checks if `value` is `null` or `undefined`. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is nullish, else `false`. + * @example + * + * isNil(null) + * // => true + * + * isNil(void 0) + * // => true + * + * isNil(NaN) + * // => false + */ +function isNil(value) { + return value == null +} + +export default isNil diff --git a/libs/lodash/isNull.js b/libs/lodash/isNull.js new file mode 100644 index 0000000..1627b3c --- /dev/null +++ b/libs/lodash/isNull.js @@ -0,0 +1,20 @@ +/** + * Checks if `value` is `null`. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `null`, else `false`. + * @example + * + * isNull(null) + * // => true + * + * isNull(void 0) + * // => false + */ +function isNull(value) { + return value === null +} + +export default isNull diff --git a/libs/lodash/isNumber.js b/libs/lodash/isNumber.js new file mode 100644 index 0000000..bb808a2 --- /dev/null +++ b/libs/lodash/isNumber.js @@ -0,0 +1,34 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is classified as a `Number` primitive or object. + * + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are + * classified as numbers, use the `Number.isFinite` method. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a number, else `false`. + * @see isInteger, toInteger, toNumber + * @example + * + * isNumber(3) + * // => true + * + * isNumber(Number.MIN_VALUE) + * // => true + * + * isNumber(Infinity) + * // => true + * + * isNumber('3') + * // => false + */ +function isNumber(value) { + return typeof value === 'number' || + (isObjectLike(value) && getTag(value) == '[object Number]') +} + +export default isNumber diff --git a/libs/lodash/isObject.js b/libs/lodash/isObject.js new file mode 100644 index 0000000..e9e81bf --- /dev/null +++ b/libs/lodash/isObject.js @@ -0,0 +1,29 @@ +/** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * isObject({}) + * // => true + * + * isObject([1, 2, 3]) + * // => true + * + * isObject(Function) + * // => true + * + * isObject(null) + * // => false + */ +function isObject(value) { + const type = typeof value + return value != null && (type === 'object' || type === 'function') +} + +export default isObject diff --git a/libs/lodash/isObjectLike.js b/libs/lodash/isObjectLike.js new file mode 100644 index 0000000..7175076 --- /dev/null +++ b/libs/lodash/isObjectLike.js @@ -0,0 +1,27 @@ +/** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * isObjectLike({}) + * // => true + * + * isObjectLike([1, 2, 3]) + * // => true + * + * isObjectLike(Function) + * // => false + * + * isObjectLike(null) + * // => false + */ +function isObjectLike(value) { + return typeof value === 'object' && value !== null +} + +export default isObjectLike diff --git a/libs/lodash/isPlainObject.js b/libs/lodash/isPlainObject.js new file mode 100644 index 0000000..896d457 --- /dev/null +++ b/libs/lodash/isPlainObject.js @@ -0,0 +1,44 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is a plain object, that is, an object created by the + * `Object` constructor or one with a `[[Prototype]]` of `null`. + * + * @since 0.8.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Foo() { + * this.a = 1 + * } + * + * isPlainObject(new Foo) + * // => false + * + * isPlainObject([1, 2, 3]) + * // => false + * + * isPlainObject({ 'x': 0, 'y': 0 }) + * // => true + * + * isPlainObject(Object.create(null)) + * // => true + */ +function isPlainObject(value) { + if (!isObjectLike(value) || getTag(value) != '[object Object]') { + return false + } + if (Object.getPrototypeOf(value) === null) { + return true + } + let proto = value + while (Object.getPrototypeOf(proto) !== null) { + proto = Object.getPrototypeOf(proto) + } + return Object.getPrototypeOf(value) === proto +} + +export default isPlainObject diff --git a/libs/lodash/isRegExp.js b/libs/lodash/isRegExp.js new file mode 100644 index 0000000..42d567d --- /dev/null +++ b/libs/lodash/isRegExp.js @@ -0,0 +1,27 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' +import nodeTypes from './.internal/nodeTypes.js' + +/* Node.js helper references. */ +const nodeIsRegExp = nodeTypes && nodeTypes.isRegExp + +/** + * Checks if `value` is classified as a `RegExp` object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + * @example + * + * isRegExp(/abc/) + * // => true + * + * isRegExp('/abc/') + * // => false + */ +const isRegExp = nodeIsRegExp + ? (value) => nodeIsRegExp(value) + : (value) => isObjectLike(value) && getTag(value) == '[object RegExp]' + +export default isRegExp diff --git a/libs/lodash/isSet.js b/libs/lodash/isSet.js new file mode 100644 index 0000000..51195ab --- /dev/null +++ b/libs/lodash/isSet.js @@ -0,0 +1,27 @@ +import getTag from './.internal/getTag.js' +import nodeTypes from './.internal/nodeTypes.js' +import isObjectLike from './isObjectLike.js' + +/* Node.js helper references. */ +const nodeIsSet = nodeTypes && nodeTypes.isSet + +/** + * Checks if `value` is classified as a `Set` object. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + * @example + * + * isSet(new Set) + * // => true + * + * isSet(new WeakSet) + * // => false + */ +const isSet = nodeIsSet + ? (value) => nodeIsSet(value) + : (value) => isObjectLike(value) && getTag(value) == '[object Set]' + +export default isSet diff --git a/libs/lodash/isString.js b/libs/lodash/isString.js new file mode 100644 index 0000000..b5470a9 --- /dev/null +++ b/libs/lodash/isString.js @@ -0,0 +1,23 @@ +import getTag from './.internal/getTag.js' + +/** + * Checks if `value` is classified as a `String` primitive or object. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. + * @example + * + * isString('abc') + * // => true + * + * isString(1) + * // => false + */ +function isString(value) { + const type = typeof value + return type === 'string' || (type === 'object' && value != null && !Array.isArray(value) && getTag(value) == '[object String]') +} + +export default isString diff --git a/libs/lodash/isSymbol.js b/libs/lodash/isSymbol.js new file mode 100644 index 0000000..0cf4c70 --- /dev/null +++ b/libs/lodash/isSymbol.js @@ -0,0 +1,23 @@ +import getTag from './.internal/getTag.js' + +/** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * isSymbol(Symbol.iterator) + * // => true + * + * isSymbol('abc') + * // => false + */ +function isSymbol(value) { + const type = typeof value + return type == 'symbol' || (type === 'object' && value != null && getTag(value) == '[object Symbol]') +} + +export default isSymbol diff --git a/libs/lodash/isTypedArray.js b/libs/lodash/isTypedArray.js new file mode 100644 index 0000000..184bbe4 --- /dev/null +++ b/libs/lodash/isTypedArray.js @@ -0,0 +1,30 @@ +import getTag from './.internal/getTag.js' +import nodeTypes from './.internal/nodeTypes.js' +import isObjectLike from './isObjectLike.js' + +/** Used to match `toStringTag` values of typed arrays. */ +const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)Array\]$/ + +/* Node.js helper references. */ +const nodeIsTypedArray = nodeTypes && nodeTypes.isTypedArray + +/** + * Checks if `value` is classified as a typed array. + * + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + * @example + * + * isTypedArray(new Uint8Array) + * // => true + * + * isTypedArray([]) + * // => false + */ +const isTypedArray = nodeIsTypedArray + ? (value) => nodeIsTypedArray(value) + : (value) => isObjectLike(value) && reTypedTag.test(getTag(value)) + +export default isTypedArray diff --git a/libs/lodash/isUndefined.js b/libs/lodash/isUndefined.js new file mode 100644 index 0000000..e92c558 --- /dev/null +++ b/libs/lodash/isUndefined.js @@ -0,0 +1,20 @@ +/** + * Checks if `value` is `undefined`. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * isUndefined(void 0) + * // => true + * + * isUndefined(null) + * // => false + */ +function isUndefined(value) { + return value === undefined +} + +export default isUndefined diff --git a/libs/lodash/isWeakMap.js b/libs/lodash/isWeakMap.js new file mode 100644 index 0000000..0271dca --- /dev/null +++ b/libs/lodash/isWeakMap.js @@ -0,0 +1,23 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is classified as a `WeakMap` object. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. + * @example + * + * isWeakMap(new WeakMap) + * // => true + * + * isWeakMap(new Map) + * // => false + */ +function isWeakMap(value) { + return isObjectLike(value) && getTag(value) == '[object WeakMap]' +} + +export default isWeakMap diff --git a/libs/lodash/isWeakSet.js b/libs/lodash/isWeakSet.js new file mode 100644 index 0000000..a14b579 --- /dev/null +++ b/libs/lodash/isWeakSet.js @@ -0,0 +1,23 @@ +import getTag from './.internal/getTag.js' +import isObjectLike from './isObjectLike.js' + +/** + * Checks if `value` is classified as a `WeakSet` object. + * + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. + * @example + * + * isWeakSet(new WeakSet) + * // => true + * + * isWeakSet(new Set) + * // => false + */ +function isWeakSet(value) { + return isObjectLike(value) && getTag(value) == '[object WeakSet]' +} + +export default isWeakSet diff --git a/libs/lodash/kebabCase.js b/libs/lodash/kebabCase.js new file mode 100644 index 0000000..bc436b9 --- /dev/null +++ b/libs/lodash/kebabCase.js @@ -0,0 +1,30 @@ +import words from './words.js' +import toString from './toString.js' + +/** + * Converts `string` to + * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the kebab cased string. + * @see camelCase, lowerCase, snakeCase, startCase, upperCase, upperFirst + * @example + * + * kebabCase('Foo Bar') + * // => 'foo-bar' + * + * kebabCase('fooBar') + * // => 'foo-bar' + * + * kebabCase('__FOO_BAR__') + * // => 'foo-bar' + */ +const kebabCase = (string) => ( + words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? '-' : '') + word.toLowerCase() + ), '') +) + +export default kebabCase diff --git a/libs/lodash/keyBy.js b/libs/lodash/keyBy.js new file mode 100644 index 0000000..2297565 --- /dev/null +++ b/libs/lodash/keyBy.js @@ -0,0 +1,32 @@ +import baseAssignValue from './.internal/baseAssignValue.js' +import reduce from './reduce.js' + +/** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the last element responsible for generating the key. The + * iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @see groupBy, partition + * @example + * + * const array = [ + * { 'dir': 'left', 'code': 97 }, + * { 'dir': 'right', 'code': 100 } + * ] + * + * keyBy(array, ({ code }) => String.fromCharCode(code)) + * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } + */ +function keyBy(collection, iteratee) { + return reduce(collection, (result, value, key) => ( + baseAssignValue(result, iteratee(value), value), result + ), {}) +} + +export default keyBy diff --git a/libs/lodash/keys.js b/libs/lodash/keys.js new file mode 100644 index 0000000..43b241c --- /dev/null +++ b/libs/lodash/keys.js @@ -0,0 +1,37 @@ +import arrayLikeKeys from './.internal/arrayLikeKeys.js' +import isArrayLike from './isArrayLike.js' + +/** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * for more details. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @see values, valuesIn + * @example + * + * function Foo() { + * this.a = 1 + * this.b = 2 + * } + * + * Foo.prototype.c = 3 + * + * keys(new Foo) + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * keys('hi') + * // => ['0', '1'] + */ +function keys(object) { + return isArrayLike(object) + ? arrayLikeKeys(object) + : Object.keys(Object(object)) +} + +export default keys diff --git a/libs/lodash/keysIn.js b/libs/lodash/keysIn.js new file mode 100644 index 0000000..b426b3d --- /dev/null +++ b/libs/lodash/keysIn.js @@ -0,0 +1,32 @@ +/** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keysIn(new Foo); + * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + */ +function keysIn(object) { + const result = [] + for (const key in object) { + result.push(key) + } + return result +} + +export default keysIn + diff --git a/libs/lodash/last.js b/libs/lodash/last.js new file mode 100644 index 0000000..3bb7dfd --- /dev/null +++ b/libs/lodash/last.js @@ -0,0 +1,18 @@ +/** + * Gets the last element of `array`. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the last element of `array`. + * @example + * + * last([1, 2, 3]) + * // => 3 + */ +function last(array) { + const length = array == null ? 0 : array.length + return length ? array[length - 1] : undefined +} + +export default last diff --git a/libs/lodash/lastIndexOf.js b/libs/lodash/lastIndexOf.js new file mode 100644 index 0000000..23f3a76 --- /dev/null +++ b/libs/lodash/lastIndexOf.js @@ -0,0 +1,40 @@ +import baseFindIndex from './.internal/baseFindIndex.js' +import baseIsNaN from './.internal/baseIsNaN.js' +import strictLastIndexOf from './.internal/strictLastIndexOf.js' +import toInteger from './toInteger.js' + +/** + * This method is like `indexOf` except that it iterates over elements of + * `array` from right to left. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * lastIndexOf([1, 2, 1, 2], 2) + * // => 3 + * + * // Search from the `fromIndex`. + * lastIndexOf([1, 2, 1, 2], 2, 2) + * // => 1 + */ +function lastIndexOf(array, value, fromIndex) { + const length = array == null ? 0 : array.length + if (!length) { + return -1 + } + let index = length + if (fromIndex !== undefined) { + index = toInteger(fromIndex) + index = index < 0 ? Math.max(length + index, 0) : Math.min(index, length - 1) + } + return value === value + ? strictLastIndexOf(array, value, index) + : baseFindIndex(array, baseIsNaN, index, true) +} + +export default lastIndexOf diff --git a/libs/lodash/lowerCase.js b/libs/lodash/lowerCase.js new file mode 100644 index 0000000..3da8966 --- /dev/null +++ b/libs/lodash/lowerCase.js @@ -0,0 +1,31 @@ +import words from './words.js' +import toString from './toString.js' + +const reQuotes = /['\u2019]/g + +/** + * Converts `string`, as space separated words, to lower case. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the lower cased string. + * @see camelCase, kebabCase, snakeCase, startCase, upperCase, upperFirst + * @example + * + * lowerCase('--Foo-Bar--') + * // => 'foo bar' + * + * lowerCase('fooBar') + * // => 'foo bar' + * + * lowerCase('__FOO_BAR__') + * // => 'foo bar' + */ +const lowerCase = (string) => ( + words(toString(string).replace(reQuotes, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + word.toLowerCase() + ), '') +) + +export default lowerCase diff --git a/libs/lodash/lowerFirst.js b/libs/lodash/lowerFirst.js new file mode 100644 index 0000000..f569521 --- /dev/null +++ b/libs/lodash/lowerFirst.js @@ -0,0 +1,20 @@ +import createCaseFirst from './.internal/createCaseFirst.js' + +/** + * Converts the first character of `string` to lower case. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the converted string. + * @example + * + * lowerFirst('Fred') + * // => 'fred' + * + * lowerFirst('FRED') + * // => 'fRED' + */ +const lowerFirst = createCaseFirst('toLowerCase') + +export default lowerFirst diff --git a/libs/lodash/lt.js b/libs/lodash/lt.js new file mode 100644 index 0000000..f2acbcd --- /dev/null +++ b/libs/lodash/lt.js @@ -0,0 +1,30 @@ +/** + * Checks if `value` is less than `other`. + * + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + * @see gt, gte, lte + * @example + * + * lt(1, 3) + * // => true + * + * lt(3, 3) + * // => false + * + * lt(3, 1) + * // => false + */ +function lt(value, other) { + if (!(typeof value === 'string' && typeof other === 'string')) { + value = +value + other = +other + } + return value < other +} + +export default lt diff --git a/libs/lodash/lte.js b/libs/lodash/lte.js new file mode 100644 index 0000000..ef7ef45 --- /dev/null +++ b/libs/lodash/lte.js @@ -0,0 +1,30 @@ +/** + * Checks if `value` is less than or equal to `other`. + * + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than or equal to + * `other`, else `false`. + * @see gt, gte, lt + * @example + * + * lte(1, 3) + * // => true + * + * lte(3, 3) + * // => true + * + * lte(3, 1) + * // => false + */ +function lte(value, other) { + if (!(typeof value === 'string' && typeof other === 'string')) { + value = +value + other = +other + } + return value <= other +} + +export default lte diff --git a/libs/lodash/map.js b/libs/lodash/map.js new file mode 100644 index 0000000..3711d2b --- /dev/null +++ b/libs/lodash/map.js @@ -0,0 +1,30 @@ +/** + * Creates an array of values by running each element of `array` thru `iteratee`. + * The iteratee is invoked with three arguments: (value, index, array). + * + * @since 5.0.0 + * @category Array + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + * @example + * + * function square(n) { + * return n * n + * } + * + * map([4, 8], square) + * // => [16, 64] + */ +function map(array, iteratee) { + let index = -1 + const length = array == null ? 0 : array.length + const result = new Array(length) + + while (++index < length) { + result[index] = iteratee(array[index], index, array) + } + return result +} + +export default map diff --git a/libs/lodash/mapKey.js b/libs/lodash/mapKey.js new file mode 100644 index 0000000..a69e5b2 --- /dev/null +++ b/libs/lodash/mapKey.js @@ -0,0 +1,31 @@ +/** + * The opposite of `mapValue` this method creates an object with the + * same values as `object` and keys generated by running each own enumerable + * string keyed property of `object` thru `iteratee`. The iteratee is invoked + * with three arguments: (value, key, object). + * + * @since 3.8.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see mapValue + * @example + * + * mapKey({ 'a': 1, 'b': 2 }, function(value, key) { + * return key + value + * }) + * // => { 'a1': 1, 'b2': 2 } + */ +function mapKey(object, iteratee) { + object = Object(object) + const result = {} + + Object.keys(object).forEach((key) => { + const value = object[key] + result[iteratee(value, key, object)] = value + }) + return result +} + +export default mapKey diff --git a/libs/lodash/mapObject.js b/libs/lodash/mapObject.js new file mode 100644 index 0000000..a817ca7 --- /dev/null +++ b/libs/lodash/mapObject.js @@ -0,0 +1,29 @@ +/** + * Creates an array of values by running each property of `object` thru + * `iteratee`. The iteratee is invoked with three arguments: (value, key, object). + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + * @example + * + * function square(n) { + * return n * n + * } + * + * map({ 'a': 4, 'b': 8 }, square) + * // => [16, 64] (iteration order is not guaranteed) + */ +function mapObject(object, iteratee) { + const props = Object.keys(object) + const result = new Array(props.length) + + props.forEach((key, index) => { + result[index] = iteratee(object[key], key, object) + }) + return result +} + +export default mapObject diff --git a/libs/lodash/mapValue.js b/libs/lodash/mapValue.js new file mode 100644 index 0000000..d8d9aa7 --- /dev/null +++ b/libs/lodash/mapValue.js @@ -0,0 +1,33 @@ +/** + * Creates an object with the same keys as `object` and values generated + * by running each own enumerable string keyed property of `object` thru + * `iteratee`. The iteratee is invoked with three arguments: + * (value, key, object). + * + * @since 2.4.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see mapKeys + * @example + * + * const users = { + * 'fred': { 'user': 'fred', 'age': 40 }, + * 'pebbles': { 'user': 'pebbles', 'age': 1 } + * } + * + * mapValue(users, ({ age }) => age) + * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) + */ +function mapValue(object, iteratee) { + object = Object(object) + const result = {} + + Object.keys(object).forEach((key) => { + result[key] = iteratee(object[key], key, object) + }) + return result +} + +export default mapValue diff --git a/libs/lodash/matches.js b/libs/lodash/matches.js new file mode 100644 index 0000000..a0ae76a --- /dev/null +++ b/libs/lodash/matches.js @@ -0,0 +1,37 @@ +import baseClone from './.internal/baseClone.js' +import baseMatches from './.internal/baseMatches.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 + +/** + * Creates a function that performs a partial deep comparison between a given + * object and `source`, returning `true` if the given object has equivalent + * property values, else `false`. + * + * **Note:** The created function is equivalent to `isMatch` with `source` + * partially applied. + * + * Partial comparisons will match empty array and empty object `source` + * values against any array or object value, respectively. See `isEqual` + * for a list of supported value comparisons. + * + * @since 3.0.0 + * @category Util + * @param {Object} source The object of property values to match. + * @returns {Function} Returns the new spec function. + * @example + * + * const objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } + * ] + * + * filter(objects, matches({ 'a': 4, 'c': 6 })) + * // => [{ 'a': 4, 'b': 5, 'c': 6 }] + */ +function matches(source) { + return baseMatches(baseClone(source, CLONE_DEEP_FLAG)) +} + +export default matches diff --git a/libs/lodash/matchesProperty.js b/libs/lodash/matchesProperty.js new file mode 100644 index 0000000..cf6122e --- /dev/null +++ b/libs/lodash/matchesProperty.js @@ -0,0 +1,35 @@ +import baseClone from './.internal/baseClone.js' +import baseMatchesProperty from './.internal/baseMatchesProperty.js' + +/** Used to compose bitmasks for cloning. */ +const CLONE_DEEP_FLAG = 1 + +/** + * Creates a function that performs a partial deep comparison between the + * value at `path` of a given object to `srcValue`, returning `true` if the + * object value is equivalent, else `false`. + * + * **Note:** Partial comparisons will match empty array and empty object + * `srcValue` values against any array or object value, respectively. See + * `isEqual` for a list of supported value comparisons. + * + * @since 3.2.0 + * @category Util + * @param {Array|string} path The path of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + * @example + * + * const objects = [ + * { 'a': 1, 'b': 2, 'c': 3 }, + * { 'a': 4, 'b': 5, 'c': 6 } + * ] + * + * find(objects, matchesProperty('a', 4)) + * // => { 'a': 4, 'b': 5, 'c': 6 } + */ +function matchesProperty(path, srcValue) { + return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG)) +} + +export default matchesProperty diff --git a/libs/lodash/maxBy.js b/libs/lodash/maxBy.js new file mode 100644 index 0000000..d8d9d59 --- /dev/null +++ b/libs/lodash/maxBy.js @@ -0,0 +1,40 @@ +import isSymbol from './isSymbol.js' + +/** + * This method is like `max` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * the value is ranked. The iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {*} Returns the maximum value. + * @example + * + * const objects = [{ 'n': 1 }, { 'n': 2 }] + * + * maxBy(objects, ({ n }) => n) + * // => { 'n': 2 } + */ +function maxBy(array, iteratee) { + let result + if (array == null) { + return result + } + let computed + for (const value of array) { + const current = iteratee(value) + + if (current != null && (computed === undefined + ? (current === current && !isSymbol(current)) + : (current > computed) + )) { + computed = current + result = value + } + } + return result +} + +export default maxBy diff --git a/libs/lodash/mean.js b/libs/lodash/mean.js new file mode 100644 index 0000000..8f6d317 --- /dev/null +++ b/libs/lodash/mean.js @@ -0,0 +1,19 @@ +import baseMean from './meanBy.js' + +/** + * Computes the mean of the values in `array`. + * + * @since 4.0.0 + * @category Math + * @param {Array} array The array to iterate over. + * @returns {number} Returns the mean. + * @example + * + * mean([4, 2, 8, 6]) + * // => 5 + */ +function mean(array) { + return baseMean(array, (value) => value) +} + +export default mean diff --git a/libs/lodash/meanBy.js b/libs/lodash/meanBy.js new file mode 100644 index 0000000..d365c89 --- /dev/null +++ b/libs/lodash/meanBy.js @@ -0,0 +1,28 @@ +import baseSum from './.internal/baseSum.js' + +/** Used as references for various `Number` constants. */ +const NAN = 0 / 0 + +/** + * This method is like `mean` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the value to be averaged. + * The iteratee is invoked with one argument: (value). + * + * @since 4.7.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {number} Returns the mean. + * @example + * + * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }] + * + * meanBy(objects, ({ n }) => n) + * // => 5 + */ +function meanBy(array, iteratee) { + const length = array == null ? 0 : array.length + return length ? (baseSum(array, iteratee) / length) : NAN +} + +export default meanBy diff --git a/libs/lodash/memoize.js b/libs/lodash/memoize.js new file mode 100644 index 0000000..8e41558 --- /dev/null +++ b/libs/lodash/memoize.js @@ -0,0 +1,64 @@ +/** + * Creates a function that memoizes the result of `func`. If `resolver` is + * provided, it determines the cache key for storing the result based on the + * arguments provided to the memoized function. By default, the first argument + * provided to the memoized function is used as the map cache key. The `func` + * is invoked with the `this` binding of the memoized function. + * + * **Note:** The cache is exposed as the `cache` property on the memoized + * function. Its creation may be customized by replacing the `memoize.Cache` + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) + * method interface of `clear`, `delete`, `get`, `has`, and `set`. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to have its output memoized. + * @param {Function} [resolver] The function to resolve the cache key. + * @returns {Function} Returns the new memoized function. + * @example + * + * const object = { 'a': 1, 'b': 2 } + * const other = { 'c': 3, 'd': 4 } + * + * const values = memoize(values) + * values(object) + * // => [1, 2] + * + * values(other) + * // => [3, 4] + * + * object.a = 2 + * values(object) + * // => [1, 2] + * + * // Modify the result cache. + * values.cache.set(object, ['a', 'b']) + * values(object) + * // => ['a', 'b'] + * + * // Replace `memoize.Cache`. + * memoize.Cache = WeakMap + */ +function memoize(func, resolver) { + if (typeof func !== 'function' || (resolver != null && typeof resolver !== 'function')) { + throw new TypeError('Expected a function') + } + const memoized = function(...args) { + const key = resolver ? resolver.apply(this, args) : args[0] + const cache = memoized.cache + + if (cache.has(key)) { + return cache.get(key) + } + const result = func.apply(this, args) + memoized.cache = cache.set(key, result) || cache + return result + } + memoized.cache = new (memoize.Cache || Map) + return memoized +} + +memoize.Cache = Map + +export default memoize diff --git a/libs/lodash/merge.js b/libs/lodash/merge.js new file mode 100644 index 0000000..730b296 --- /dev/null +++ b/libs/lodash/merge.js @@ -0,0 +1,37 @@ +import baseMerge from './.internal/baseMerge.js' +import createAssigner from './.internal/createAssigner.js' + +/** + * This method is like `assign` except that it recursively merges own and + * inherited enumerable string keyed properties of source objects into the + * destination object. Source properties that resolve to `undefined` are + * skipped if a destination value exists. Array and plain object properties + * are merged recursively. Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. + * + * **Note:** This method mutates `object`. + * + * @since 0.5.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @example + * + * const object = { + * 'a': [{ 'b': 2 }, { 'd': 4 }] + * } + * + * const other = { + * 'a': [{ 'c': 3 }, { 'e': 5 }] + * } + * + * merge(object, other) + * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } + */ +const merge = createAssigner((object, source, srcIndex) => { + baseMerge(object, source, srcIndex) +}) + +export default merge diff --git a/libs/lodash/mergeWith.js b/libs/lodash/mergeWith.js new file mode 100644 index 0000000..dc930be --- /dev/null +++ b/libs/lodash/mergeWith.js @@ -0,0 +1,37 @@ +import baseMerge from './.internal/baseMerge.js' +import createAssigner from './.internal/createAssigner.js' + +/** + * This method is like `merge` except that it accepts `customizer` which + * is invoked to produce the merged values of the destination and source + * properties. If `customizer` returns `undefined`, merging is handled by the + * method instead. The `customizer` is invoked with six arguments: + * (objValue, srcValue, key, object, source, stack). + * + * **Note:** This method mutates `object`. + * + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * function customizer(objValue, srcValue) { + * if (Array.isArray(objValue)) { + * return objValue.concat(srcValue) + * } + * } + * + * const object = { 'a': [1], 'b': [2] } + * const other = { 'a': [3], 'b': [4] } + * + * mergeWith(object, other, customizer) + * // => { 'a': [1, 3], 'b': [2, 4] } + */ +const mergeWith = createAssigner((object, source, srcIndex, customizer) => { + baseMerge(object, source, srcIndex, customizer) +}) + +export default mergeWith diff --git a/libs/lodash/method.js b/libs/lodash/method.js new file mode 100644 index 0000000..3405e69 --- /dev/null +++ b/libs/lodash/method.js @@ -0,0 +1,29 @@ +import invoke from './invoke.js' + +/** + * Creates a function that invokes the method at `path` of a given object. + * Any additional arguments are provided to the invoked method. + * + * @since 3.7.0 + * @category Util + * @param {Array|string} path The path of the method to invoke. + * @param {Array} [args] The arguments to invoke the method with. + * @returns {Function} Returns the new invoker function. + * @example + * + * const objects = [ + * { 'a': { 'b': () => 2 } }, + * { 'a': { 'b': () => 1 } } + * ] + * + * map(objects, method('a.b')) + * // => [2, 1] + * + * map(objects, method(['a', 'b'])) + * // => [2, 1] + */ +function method(path, args) { + return (object) => invoke(object, path, args) +} + +export default method diff --git a/libs/lodash/methodOf.js b/libs/lodash/methodOf.js new file mode 100644 index 0000000..ff39385 --- /dev/null +++ b/libs/lodash/methodOf.js @@ -0,0 +1,28 @@ +import invoke from './invoke.js' + +/** + * The opposite of `method` this method creates a function that invokes + * the method at a given path of `object`. Any additional arguments are + * provided to the invoked method. + * + * @since 3.7.0 + * @category Util + * @param {Object} object The object to query. + * @param {Array} [args] The arguments to invoke the method with. + * @returns {Function} Returns the new invoker function. + * @example + * + * const array = times(3, i => () => i) + * const object = { 'a': array, 'b': array, 'c': array } + * + * map(['a[2]', 'c[0]'], methodOf(object)) + * // => [2, 0] + * + * map([['a', '2'], ['c', '0']], methodOf(object)) + * // => [2, 0]f + */ +function methodOf(object, args) { + return (path) => invoke(object, path, args) +} + +export default methodOf diff --git a/libs/lodash/minBy.js b/libs/lodash/minBy.js new file mode 100644 index 0000000..cb0fe82 --- /dev/null +++ b/libs/lodash/minBy.js @@ -0,0 +1,40 @@ +import isSymbol from './isSymbol.js' + +/** + * This method is like `min` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * the value is ranked. The iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {*} Returns the minimum value. + * @example + * + * const objects = [{ 'n': 1 }, { 'n': 2 }] + * + * minBy(objects, ({ n }) => n) + * // => { 'n': 1 } + */ +function minBy(array, iteratee) { + let result + if (array == null) { + return result + } + let computed + for (const value of array) { + const current = iteratee(value) + + if (current != null && (computed === undefined + ? (current === current && !isSymbol(current)) + : (current < computed) + )) { + computed = current + result = value + } + } + return result +} + +export default minBy diff --git a/libs/lodash/multiply.js b/libs/lodash/multiply.js new file mode 100644 index 0000000..8ccba14 --- /dev/null +++ b/libs/lodash/multiply.js @@ -0,0 +1,18 @@ +import createMathOperation from './.internal/createMathOperation.js' + +/** + * Multiply two numbers. + * + * @since 4.7.0 + * @category Math + * @param {number} multiplier The first number in a multiplication. + * @param {number} multiplicand The second number in a multiplication. + * @returns {number} Returns the product. + * @example + * + * multiply(6, 4) + * // => 24 + */ +const multiply = createMathOperation((multiplier, multiplicand) => multiplier * multiplicand, 1) + +export default multiply diff --git a/libs/lodash/negate.js b/libs/lodash/negate.js new file mode 100644 index 0000000..2e2f863 --- /dev/null +++ b/libs/lodash/negate.js @@ -0,0 +1,28 @@ +/** + * Creates a function that negates the result of the predicate `func`. The + * `func` predicate is invoked with the `this` binding and arguments of the + * created function. + * + * @since 3.0.0 + * @category Function + * @param {Function} predicate The predicate to negate. + * @returns {Function} Returns the new negated function. + * @example + * + * function isEven(n) { + * return n % 2 == 0 + * } + * + * filter([1, 2, 3, 4, 5, 6], negate(isEven)) + * // => [1, 3, 5] + */ +function negate(predicate) { + if (typeof predicate !== 'function') { + throw new TypeError('Expected a function') + } + return function(...args) { + return !predicate.apply(this, args) + } +} + +export default negate diff --git a/libs/lodash/nth.js b/libs/lodash/nth.js new file mode 100644 index 0000000..b2425a7 --- /dev/null +++ b/libs/lodash/nth.js @@ -0,0 +1,31 @@ +import isIndex from './.internal/isIndex.js' + +/** + * Gets the element at index `n` of `array`. If `n` is negative, the nth + * element from the end is returned. + * + * @since 4.11.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=0] The index of the element to return. + * @returns {*} Returns the nth element of `array`. + * @example + * + * const array = ['a', 'b', 'c', 'd'] + * + * nth(array, 1) + * // => 'b' + * + * nth(array, -2) + * // => 'c' + */ +function nth(array, n) { + const length = array == null ? 0 : array.length + if (!length) { + return + } + n += n < 0 ? length : 0 + return isIndex(n, length) ? array[n] : undefined +} + +export default nth diff --git a/libs/lodash/nthArg.js b/libs/lodash/nthArg.js new file mode 100644 index 0000000..f5da0cf --- /dev/null +++ b/libs/lodash/nthArg.js @@ -0,0 +1,25 @@ +import nth from './nth.js' + +/** + * Creates a function that gets the argument at index `n`. If `n` is negative, + * the nth argument from the end is returned. + * + * @since 4.0.0 + * @category Util + * @param {number} [n=0] The index of the argument to return. + * @returns {Function} Returns the new pass-thru function. + * @example + * + * const func = nthArg(1) + * func('a', 'b', 'c', 'd') + * // => 'b' + * + * const func = nthArg(-2) + * func('a', 'b', 'c', 'd') + * // => 'c' + */ +function nthArg(n) { + return (...args) => nth(args, n) +} + +export default nthArg diff --git a/libs/lodash/once.js b/libs/lodash/once.js new file mode 100644 index 0000000..653000b --- /dev/null +++ b/libs/lodash/once.js @@ -0,0 +1,23 @@ +import before from './before.js' + +/** + * Creates a function that is restricted to invoking `func` once. Repeat calls + * to the function return the value of the first invocation. The `func` is + * invoked with the `this` binding and arguments of the created function. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * const initialize = once(createApplication) + * initialize() + * initialize() + * // => `createApplication` is invoked once + */ +function once(func) { + return before(2, func) +} + +export default once diff --git a/libs/lodash/orderBy.js b/libs/lodash/orderBy.js new file mode 100644 index 0000000..4bb2112 --- /dev/null +++ b/libs/lodash/orderBy.js @@ -0,0 +1,51 @@ +import baseOrderBy from './.internal/baseOrderBy.js' + +/** + * This method is like `sortBy` except that it allows specifying the sort + * orders of the iteratees to sort by. If `orders` is unspecified, all values + * are sorted in ascending order. Otherwise, specify an order of "desc" for + * descending or "asc" for ascending sort order of corresponding values. + * You may also specify a compare function for an order. + * + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[identity]] + * The iteratees to sort by. + * @param {(string|function)[]} [orders] The sort orders of `iteratees`. + * @returns {Array} Returns the new sorted array. + * @see reverse + * @example + * + * const users = [ + * { 'user': 'fred', 'age': 48 }, + * { 'user': 'barney', 'age': 34 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'barney', 'age': 36 } + * ] + * + * // Sort by `user` in ascending order and by `age` in descending order. + * orderBy(users, ['user', 'age'], ['asc', 'desc']) + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] + * + * // Sort by `user` then by `age` using custom compare functions for each + * orderBy(users, ['user', 'age'], [ + * (a, b) => a.localeCompare(b, 'de', { sensitivity: 'base' }), + * (a, b) => a - b, + * ]) + * + */ +function orderBy(collection, iteratees, orders) { + if (collection == null) { + return [] + } + if (!Array.isArray(iteratees)) { + iteratees = iteratees == null ? [] : [iteratees] + } + if (!Array.isArray(orders)) { + orders = orders == null ? [] : [orders] + } + return baseOrderBy(collection, iteratees, orders) +} + +export default orderBy diff --git a/libs/lodash/over.js b/libs/lodash/over.js new file mode 100644 index 0000000..d4e41da --- /dev/null +++ b/libs/lodash/over.js @@ -0,0 +1,25 @@ +import map from './map.js' + +/** + * Creates a function that invokes `iteratees` with the arguments it receives + * and returns their results. + * + * @since 4.0.0 + * @category Util + * @param {Function[]} [iteratees=[identity]] + * The iteratees to invoke. + * @returns {Function} Returns the new function. + * @example + * + * const func = over([Math.max, Math.min]) + * + * func(1, 2, 3, 4) + * // => [4, 1] + */ +function over(iteratees) { + return function(...args) { + return map(iteratees, (iteratee) => iteratee.apply(this, args)) + } +} + +export default over diff --git a/libs/lodash/overArgs.js b/libs/lodash/overArgs.js new file mode 100644 index 0000000..7a1479e --- /dev/null +++ b/libs/lodash/overArgs.js @@ -0,0 +1,41 @@ + +/** + * Creates a function that invokes `func` with its arguments transformed. + * + * @since 4.0.0 + * @category Function + * @param {Function} func The function to wrap. + * @param {Function[]} [transforms=[identity]] + * The argument transforms. + * @returns {Function} Returns the new function. + * @example + * + * function doubled(n) { + * return n * 2 + * } + * + * function square(n) { + * return n * n + * } + * + * const func = overArgs((x, y) => [x, y], [square, doubled]) + * + * func(9, 3) + * // => [81, 6] + * + * func(10, 5) + * // => [100, 10] + */ +function overArgs(func, transforms) { + const funcsLength = transforms.length + return function(...args) { + let index = -1 + const length = Math.min(args.length, funcsLength) + while (++index < length) { + args[index] = transforms[index].call(this, args[index]) + } + return func.apply(this, args) + } +} + +export default overArgs diff --git a/libs/lodash/overEvery.js b/libs/lodash/overEvery.js new file mode 100644 index 0000000..4f22a99 --- /dev/null +++ b/libs/lodash/overEvery.js @@ -0,0 +1,31 @@ +import every from './every.js' + +/** + * Creates a function that checks if **all** of the `predicates` return + * truthy when invoked with the arguments it receives. + * + * @since 4.0.0 + * @category Util + * @param {Function[]} [predicates=[identity]] + * The predicates to check. + * @returns {Function} Returns the new function. + * @example + * + * const func = overEvery([Boolean, isFinite]) + * + * func('1') + * // => true + * + * func(null) + * // => false + * + * func(NaN) + * // => false + */ +function overEvery(iteratees) { + return function(...args) { + return every(iteratees, (iteratee) => iteratee.apply(this, args)) + } +} + +export default overEvery diff --git a/libs/lodash/overSome.js b/libs/lodash/overSome.js new file mode 100644 index 0000000..6b2c0dc --- /dev/null +++ b/libs/lodash/overSome.js @@ -0,0 +1,31 @@ +import some from './some.js' + +/** + * Creates a function that checks if **any** of the `predicates` return + * truthy when invoked with the arguments it receives. + * + * @since 4.0.0 + * @category Util + * @param {Function[]} [predicates=[identity]] + * The predicates to check. + * @returns {Function} Returns the new function. + * @example + * + * const func = overSome([Boolean, isFinite]) + * + * func('1') + * // => true + * + * func(null) + * // => true + * + * func(NaN) + * // => false + */ +function overSome(iteratees) { + return function(...args) { + return some(iteratees, (iteratee) => iteratee.apply(this, args)) + } +} + +export default overSome diff --git a/libs/lodash/pad.js b/libs/lodash/pad.js new file mode 100644 index 0000000..3cfd913 --- /dev/null +++ b/libs/lodash/pad.js @@ -0,0 +1,38 @@ +import createPadding from './.internal/createPadding.js' +import stringSize from './.internal/stringSize.js' + +/** + * Pads `string` on the left and right sides if it's shorter than `length`. + * Padding characters are truncated if they can't be evenly divided by `length`. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * pad('abc', 8) + * // => ' abc ' + * + * pad('abc', 8, '_-') + * // => '_-abc_-_' + * + * pad('abc', 2) + * // => 'abc' + */ +function pad(string, length, chars) { + const strLength = length ? stringSize(string) : 0 + if (!length || strLength >= length) { + return (string || '') + } + const mid = (length - strLength) / 2 + return ( + createPadding(Math.floor(mid), chars) + + string + + createPadding(Math.ceil(mid), chars) + ) +} + +export default pad diff --git a/libs/lodash/padEnd.js b/libs/lodash/padEnd.js new file mode 100644 index 0000000..0fe4ab1 --- /dev/null +++ b/libs/lodash/padEnd.js @@ -0,0 +1,32 @@ +import createPadding from './.internal/createPadding.js' +import stringSize from './.internal/stringSize.js' + +/** + * Pads `string` on the right side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * padEnd('abc', 6) + * // => 'abc ' + * + * padEnd('abc', 6, '_-') + * // => 'abc_-_' + * + * padEnd('abc', 2) + * // => 'abc' + */ +function padEnd(string, length, chars) { + const strLength = length ? stringSize(string) : 0 + return (length && strLength < length) + ? (string + createPadding(length - strLength, chars)) + : (string || '') +} + +export default padEnd diff --git a/libs/lodash/padStart.js b/libs/lodash/padStart.js new file mode 100644 index 0000000..0257083 --- /dev/null +++ b/libs/lodash/padStart.js @@ -0,0 +1,32 @@ +import createPadding from './.internal/createPadding.js' +import stringSize from './.internal/stringSize.js' + +/** + * Pads `string` on the left side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * padStart('abc', 6) + * // => ' abc' + * + * padStart('abc', 6, '_-') + * // => '_-_abc' + * + * padStart('abc', 2) + * // => 'abc' + */ +function padStart(string, length, chars) { + const strLength = length ? stringSize(string) : 0 + return (length && strLength < length) + ? (createPadding(length - strLength, chars) + string) + : (string || '') +} + +export default padStart diff --git a/libs/lodash/parseInt.js b/libs/lodash/parseInt.js new file mode 100644 index 0000000..b8975cc --- /dev/null +++ b/libs/lodash/parseInt.js @@ -0,0 +1,36 @@ +import root from './.internal/root.js' + +/** Used to match leading and trailing whitespace. */ +const reTrimStart = /^\s+/ + +/* Built-in method references for those with the same name as other `lodash` methods. */ +const nativeParseInt = root.parseInt + +/** + * Converts `string` to an integer of the specified radix. If `radix` is + * `undefined` or `0`, a `radix` of `10` is used unless `string` is a + * hexadecimal, in which case a `radix` of `16` is used. + * + * **Note:** This method aligns with the + * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. + * + * @since 1.1.0 + * @category String + * @param {string} string The string to convert. + * @param {number} [radix=10] The radix to interpret `string` by. + * @returns {number} Returns the converted integer. + * @example + * + * parseInt('08') + * // => 8 + */ +function parseInt(string, radix) { + if (radix == null) { + radix = 0 + } else if (radix) { + radix = +radix + } + return nativeParseInt(`${string}`.replace(reTrimStart, ''), radix || 0) +} + +export default parseInt diff --git a/libs/lodash/partition.js b/libs/lodash/partition.js new file mode 100644 index 0000000..f7f9376 --- /dev/null +++ b/libs/lodash/partition.js @@ -0,0 +1,32 @@ +import reduce from './reduce.js' + +/** + * Creates an array of elements split into two groups, the first of which + * contains elements `predicate` returns truthy for, the second of which + * contains elements `predicate` returns falsey for. The predicate is + * invoked with one argument: (value). + * + * @since 3.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the array of grouped elements. + * @see groupBy, keyBy + * @example + * + * const users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true }, + * { 'user': 'pebbles', 'age': 1, 'active': false } + * ] + * + * partition(users, ({ active }) => active) + * // => objects for [['fred'], ['barney', 'pebbles']] + */ +function partition(collection, predicate) { + return reduce(collection, (result, value, key) => ( + result[predicate(value) ? 0 : 1].push(value), result + ), [[], []]) +} + +export default partition diff --git a/libs/lodash/pick.js b/libs/lodash/pick.js new file mode 100644 index 0000000..8878cb0 --- /dev/null +++ b/libs/lodash/pick.js @@ -0,0 +1,22 @@ +import basePick from './.internal/basePick.js' + +/** + * Creates an object composed of the picked `object` properties. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Object} Returns the new object. + * @example + * + * const object = { 'a': 1, 'b': '2', 'c': 3 } + * + * pick(object, ['a', 'c']) + * // => { 'a': 1, 'c': 3 } + */ +function pick(object, ...paths) { + return object == null ? {} : basePick(object, paths) +} + +export default pick diff --git a/libs/lodash/pickBy.js b/libs/lodash/pickBy.js new file mode 100644 index 0000000..2b8b4db --- /dev/null +++ b/libs/lodash/pickBy.js @@ -0,0 +1,29 @@ +import map from './map.js' +import basePickBy from './.internal/basePickBy.js' +import getAllKeysIn from './.internal/getAllKeysIn.js' + +/** + * Creates an object composed of the `object` properties `predicate` returns + * truthy for. The predicate is invoked with two arguments: (value, key). + * + * @since 4.0.0 + * @category Object + * @param {Object} object The source object. + * @param {Function} predicate The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * const object = { 'a': 1, 'b': '2', 'c': 3 } + * + * pickBy(object, isNumber) + * // => { 'a': 1, 'c': 3 } + */ +function pickBy(object, predicate) { + if (object == null) { + return {} + } + const props = map(getAllKeysIn(object), (prop) => [prop]) + return basePickBy(object, props, (value, path) => predicate(value, path[0])) +} + +export default pickBy diff --git a/libs/lodash/property.js b/libs/lodash/property.js new file mode 100644 index 0000000..20520c3 --- /dev/null +++ b/libs/lodash/property.js @@ -0,0 +1,30 @@ +import baseProperty from './.internal/baseProperty.js' +import basePropertyDeep from './.internal/basePropertyDeep.js' +import isKey from './.internal/isKey.js' +import toKey from './.internal/toKey.js' + +/** + * Creates a function that returns the value at `path` of a given object. + * + * @since 2.4.0 + * @category Util + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new accessor function. + * @example + * + * const objects = [ + * { 'a': { 'b': 2 } }, + * { 'a': { 'b': 1 } } + * ] + * + * map(objects, property('a.b')) + * // => [2, 1] + * + * map(sortBy(objects, property(['a', 'b'])), 'a.b') + * // => [1, 2] + */ +function property(path) { + return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path) +} + +export default property diff --git a/libs/lodash/propertyOf.js b/libs/lodash/propertyOf.js new file mode 100644 index 0000000..ed6daac --- /dev/null +++ b/libs/lodash/propertyOf.js @@ -0,0 +1,26 @@ +import baseGet from './.internal/baseGet.js' + +/** + * The opposite of `property`s method creates a function that returns + * the value at a given path of `object`. + * + * @since 3.0.0 + * @category Util + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + * @example + * + * const array = [0, 1, 2] + * const object = { 'a': array, 'b': array, 'c': array } + * + * map(['a[2]', 'c[0]'], propertyOf(object)) + * // => [2, 0] + * + * map([['a', '2'], ['c', '0']], propertyOf(object)) + * // => [2, 0] + */ +function propertyOf(object) { + return (path) => object == null ? undefined : baseGet(object, path) +} + +export default propertyOf diff --git a/libs/lodash/pull.js b/libs/lodash/pull.js new file mode 100644 index 0000000..8c4c3d7 --- /dev/null +++ b/libs/lodash/pull.js @@ -0,0 +1,29 @@ +import pullAll from './pullAll.js' + +/** + * Removes all given values from `array` using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `without`, this method mutates `array`. Use `remove` + * to remove elements from an array by predicate. + * + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...*} [values] The values to remove. + * @returns {Array} Returns `array`. + * @see pullAll, pullAllBy, pullAllWith, pullAt, remove, reject + * @example + * + * const array = ['a', 'b', 'c', 'a', 'b', 'c'] + * + * pull(array, 'a', 'c') + * console.log(array) + * // => ['b', 'b'] + */ +function pull(array, ...values) { + return pullAll(array, values) +} + +export default pull diff --git a/libs/lodash/pullAll.js b/libs/lodash/pullAll.js new file mode 100644 index 0000000..1f32020 --- /dev/null +++ b/libs/lodash/pullAll.js @@ -0,0 +1,28 @@ +import basePullAll from './.internal/basePullAll.js' + +/** + * This method is like `pull` except that it accepts an array of values to remove. + * + * **Note:** Unlike `difference`, this method mutates `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @returns {Array} Returns `array`. + * @see pull, pullAllBy, pullAllWith, pullAt, remove, reject + * @example + * + * const array = ['a', 'b', 'c', 'a', 'b', 'c'] + * + * pullAll(array, ['a', 'c']) + * console.log(array) + * // => ['b', 'b'] + */ +function pullAll(array, values) { + return (array != null && array.length && values != null && values.length) + ? basePullAll(array, values) + : array +} + +export default pullAll diff --git a/libs/lodash/pullAllBy.js b/libs/lodash/pullAllBy.js new file mode 100644 index 0000000..863628d --- /dev/null +++ b/libs/lodash/pullAllBy.js @@ -0,0 +1,31 @@ +import basePullAll from './.internal/basePullAll.js' + +/** + * This method is like `pullAll` except that it accepts `iteratee` which is + * invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The iteratee is invoked with one argument: (value). + * + * **Note:** Unlike `differenceBy`, this method mutates `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns `array`. + * @see pull, pullAll, pullAllWith, pullAt, remove, reject + * @example + * + * const array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }] + * + * pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x') + * console.log(array) + * // => [{ 'x': 2 }] + */ +function pullAllBy(array, values, iteratee) { + return (array != null && array.length && values != null && values.length) + ? basePullAll(array, values, iteratee) + : array +} + +export default pullAllBy diff --git a/libs/lodash/pullAllWith.js b/libs/lodash/pullAllWith.js new file mode 100644 index 0000000..bd77c58 --- /dev/null +++ b/libs/lodash/pullAllWith.js @@ -0,0 +1,31 @@ +import basePullAll from './.internal/basePullAll.js' + +/** + * This method is like `pullAll` except that it accepts `comparator` which + * is invoked to compare elements of `array` to `values`. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `differenceWith`, this method mutates `array`. + * + * @since 4.6.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + * @see pull, pullAll, pullAllBy, pullAt, remove, reject + * @example + * + * const array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }] + * + * pullAllWith(array, [{ 'x': 3, 'y': 4 }], isEqual) + * console.log(array) + * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] + */ +function pullAllWith(array, values, comparator) { + return (array != null && array.length && values != null && values.length) + ? basePullAll(array, values, undefined, comparator) + : array +} + +export default pullAllWith diff --git a/libs/lodash/pullAt.js b/libs/lodash/pullAt.js new file mode 100644 index 0000000..86a2270 --- /dev/null +++ b/libs/lodash/pullAt.js @@ -0,0 +1,38 @@ +import map from './map.js' +import baseAt from './.internal/baseAt.js' +import basePullAt from './.internal/basePullAt.js' +import compareAscending from './.internal/compareAscending.js' +import isIndex from './.internal/isIndex.js' + +/** + * Removes elements from `array` corresponding to `indexes` and returns an + * array of removed elements. + * + * **Note:** Unlike `at`, this method mutates `array`. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...(number|number[])} [indexes] The indexes of elements to remove. + * @returns {Array} Returns the new array of removed elements. + * @see pull, pullAll, pullAllBy, pullAllWith, remove, reject + * @example + * + * const array = ['a', 'b', 'c', 'd'] + * const pulled = pullAt(array, [1, 3]) + * + * console.log(array) + * // => ['a', 'c'] + * + * console.log(pulled) + * // => ['b', 'd'] + */ +function pullAt(array, ...indexes) { + const length = array == null ? 0 : array.length + const result = baseAt(array, indexes) + + basePullAt(array, map(indexes, (index) => isIndex(index, length) ? +index : index).sort(compareAscending)) + return result +} + +export default pullAt diff --git a/libs/lodash/random.js b/libs/lodash/random.js new file mode 100644 index 0000000..7f2acc6 --- /dev/null +++ b/libs/lodash/random.js @@ -0,0 +1,73 @@ +import toFinite from './toFinite.js' + +/** Built-in method references without a dependency on `root`. */ +const freeParseFloat = parseFloat + +/** + * Produces a random number between the inclusive `lower` and `upper` bounds. + * If only one argument is provided a number between `0` and the given number + * is returned. If `floating` is `true`, or either `lower` or `upper` are + * floats, a floating-point number is returned instead of an integer. + * + * **Note:** JavaScript follows the IEEE-754 standard for resolving + * floating-point values which can produce unexpected results. + * + * @since 0.7.0 + * @category Number + * @param {number} [lower=0] The lower bound. + * @param {number} [upper=1] The upper bound. + * @param {boolean} [floating] Specify returning a floating-point number. + * @returns {number} Returns the random number. + * @see uniqueId + * @example + * + * random(0, 5) + * // => an integer between 0 and 5 + * + * random(5) + * // => also an integer between 0 and 5 + * + * random(5, true) + * // => a floating-point number between 0 and 5 + * + * random(1.2, 5.2) + * // => a floating-point number between 1.2 and 5.2 + */ +function random(lower, upper, floating) { + if (floating === undefined) { + if (typeof upper === 'boolean') { + floating = upper + upper = undefined + } + else if (typeof lower === 'boolean') { + floating = lower + lower = undefined + } + } + if (lower === undefined && upper === undefined) { + lower = 0 + upper = 1 + } + else { + lower = toFinite(lower) + if (upper === undefined) { + upper = lower + lower = 0 + } else { + upper = toFinite(upper) + } + } + if (lower > upper) { + const temp = lower + lower = upper + upper = temp + } + if (floating || lower % 1 || upper % 1) { + const rand = Math.random() + const randLength = `${rand}`.length - 1 + return Math.min(lower + (rand * (upper - lower + freeParseFloat(`1e-${randLength}`))), upper) + } + return lower + Math.floor(Math.random() * (upper - lower + 1)) +} + +export default random diff --git a/libs/lodash/range.js b/libs/lodash/range.js new file mode 100644 index 0000000..8925c3d --- /dev/null +++ b/libs/lodash/range.js @@ -0,0 +1,44 @@ +import createRange from './.internal/createRange.js' + +/** + * Creates an array of numbers (positive and/or negative) progressing from + * `start` up to, but not including, `end`. A step of `-1` is used if a negative + * `start` is specified without an `end` or `step`. If `end` is not specified, + * it's set to `start`, and `start` is then set to `0`. + * + * **Note:** JavaScript follows the IEEE-754 standard for resolving + * floating-point values which can produce unexpected results. + * + * @since 0.1.0 + * @category Util + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @param {number} [step=1] The value to increment or decrement by. + * @returns {Array} Returns the range of numbers. + * @see inRange, rangeRight + * @example + * + * range(4) + * // => [0, 1, 2, 3] + * + * range(-4) + * // => [0, -1, -2, -3] + * + * range(1, 5) + * // => [1, 2, 3, 4] + * + * range(0, 20, 5) + * // => [0, 5, 10, 15] + * + * range(0, -4, -1) + * // => [0, -1, -2, -3] + * + * range(1, 4, 0) + * // => [1, 1, 1] + * + * range(0) + * // => [] + */ +const range = createRange() + +export default range diff --git a/libs/lodash/rangeRight.js b/libs/lodash/rangeRight.js new file mode 100644 index 0000000..139f14c --- /dev/null +++ b/libs/lodash/rangeRight.js @@ -0,0 +1,39 @@ +import createRange from './.internal/createRange.js' + +/** + * This method is like `range` except that it populates values in + * descending order. + * + * @since 4.0.0 + * @category Util + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @param {number} [step=1] The value to increment or decrement by. + * @returns {Array} Returns the range of numbers. + * @see inRange, range + * @example + * + * rangeRight(4) + * // => [3, 2, 1, 0] + * + * rangeRight(-4) + * // => [-3, -2, -1, 0] + * + * rangeRight(1, 5) + * // => [4, 3, 2, 1] + * + * rangeRight(0, 20, 5) + * // => [15, 10, 5, 0] + * + * rangeRight(0, -4, -1) + * // => [-3, -2, -1, 0] + * + * rangeRight(1, 4, 0) + * // => [1, 1, 1] + * + * rangeRight(0) + * // => [] + */ +const rangeRight = createRange(true) + +export default rangeRight diff --git a/libs/lodash/reduce.js b/libs/lodash/reduce.js new file mode 100644 index 0000000..0ad5dfe --- /dev/null +++ b/libs/lodash/reduce.js @@ -0,0 +1,44 @@ +import arrayReduce from './.internal/arrayReduce.js' +import baseEach from './.internal/baseEach.js' +import baseReduce from './.internal/baseReduce.js' + +/** + * Reduces `collection` to a value which is the accumulated result of running + * each element in `collection` thru `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not given, the first element of `collection` is used as the initial + * value. The iteratee is invoked with four arguments: + * (accumulator, value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `reduce`, `reduceRight`, and `transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, + * and `sortBy` + * + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see reduceRight, transform + * @example + * + * reduce([1, 2], (sum, n) => sum + n, 0) + * // => 3 + * + * reduce({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => { + * (result[value] || (result[value] = [])).push(key) + * return result + * }, {}) + * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) + */ +function reduce(collection, iteratee, accumulator) { + const func = Array.isArray(collection) ? arrayReduce : baseReduce + const initAccum = arguments.length < 3 + return func(collection, iteratee, accumulator, initAccum, baseEach) +} + +export default reduce diff --git a/libs/lodash/reduceRight.js b/libs/lodash/reduceRight.js new file mode 100644 index 0000000..810c96d --- /dev/null +++ b/libs/lodash/reduceRight.js @@ -0,0 +1,29 @@ +import arrayReduceRight from './.internal/arrayReduceRight.js' +import baseEachRight from './.internal/baseEachRight.js' +import baseReduce from './.internal/baseReduce.js' + +/** + * This method is like `reduce` except that it iterates over elements of + * `collection` from right to left. + * + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see reduce + * @example + * + * const array = [[0, 1], [2, 3], [4, 5]] + * + * reduceRight(array, (flattened, other) => flattened.concat(other), []) + * // => [4, 5, 2, 3, 0, 1] + */ +function reduceRight(collection, iteratee, accumulator) { + const func = Array.isArray(collection) ? arrayReduceRight : baseReduce + const initAccum = arguments.length < 3 + return func(collection, iteratee, accumulator, initAccum, baseEachRight) +} + +export default reduceRight diff --git a/libs/lodash/reject.js b/libs/lodash/reject.js new file mode 100644 index 0000000..726d975 --- /dev/null +++ b/libs/lodash/reject.js @@ -0,0 +1,30 @@ +import filter from './filter.js' +import filterObject from './filterObject.js' +import negate from './negate.js' + +/** + * The opposite of `filter` this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, remove, filter + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ] + * + * reject(users, ({ active }) => active) + * // => objects for ['fred'] + */ +function reject(collection, predicate) { + const func = Array.isArray(collection) ? filter : filterObject + return func(collection, negate(predicate)) +} + +export default reject diff --git a/libs/lodash/remove.js b/libs/lodash/remove.js new file mode 100644 index 0000000..e09cd9e --- /dev/null +++ b/libs/lodash/remove.js @@ -0,0 +1,48 @@ +import basePullAt from './.internal/basePullAt.js' + +/** + * Removes all elements from `array` that `predicate` returns truthy for + * and returns an array of the removed elements. The predicate is invoked + * with three arguments: (value, index, array). + * + * **Note:** Unlike `filter`, this method mutates `array`. Use `pull` + * to pull elements from an array by value. + * + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new array of removed elements. + * @see pull, pullAll, pullAllBy, pullAllWith, pullAt, reject, filter + * @example + * + * const array = [1, 2, 3, 4] + * const evens = remove(array, n => n % 2 == 0) + * + * console.log(array) + * // => [1, 3] + * + * console.log(evens) + * // => [2, 4] + */ +function remove(array, predicate) { + const result = [] + if (!(array != null && array.length)) { + return result + } + let index = -1 + const indexes = [] + const { length } = array + + while (++index < length) { + const value = array[index] + if (predicate(value, index, array)) { + result.push(value) + indexes.push(index) + } + } + basePullAt(array, indexes) + return result +} + +export default remove diff --git a/libs/lodash/repeat.js b/libs/lodash/repeat.js new file mode 100644 index 0000000..89d8403 --- /dev/null +++ b/libs/lodash/repeat.js @@ -0,0 +1,40 @@ +/** + * Repeats the given string `n` times. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to repeat. + * @param {number} [n=1] The number of times to repeat the string. + * @returns {string} Returns the repeated string. + * @example + * + * repeat('*', 3) + * // => '***' + * + * repeat('abc', 2) + * // => 'abcabc' + * + * repeat('abc', 0) + * // => '' + */ +function repeat(string, n) { + let result = '' + if (!string || n < 1 || n > Number.MAX_SAFE_INTEGER) { + return result + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string + } + n = Math.floor(n / 2) + if (n) { + string += string + } + } while (n) + + return result +} + +export default repeat diff --git a/libs/lodash/replace.js b/libs/lodash/replace.js new file mode 100644 index 0000000..d53d0fd --- /dev/null +++ b/libs/lodash/replace.js @@ -0,0 +1,24 @@ +/** + * Replaces matches for `pattern` in `string` with `replacement`. + * + * **Note:** This method is based on + * [`String#replace`](https://mdn.io/String/replace). + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to modify. + * @param {RegExp|string} pattern The pattern to replace. + * @param {Function|string} replacement The match replacement. + * @returns {string} Returns the modified string. + * @see truncate, trim + * @example + * + * replace('Hi Fred', 'Fred', 'Barney') + * // => 'Hi Barney' + */ +function replace(...args) { + const string = `${args[0]}` + return args.length < 3 ? string : string.replace(args[1], args[2]) +} + +export default replace diff --git a/libs/lodash/result.js b/libs/lodash/result.js new file mode 100644 index 0000000..e121780 --- /dev/null +++ b/libs/lodash/result.js @@ -0,0 +1,53 @@ +import castPath from './.internal/castPath.js' +import toKey from './.internal/toKey.js' + +/** + * This method is like `get` except that if the resolved value is a + * function it's invoked with the `this` binding of its parent object and + * its result is returned. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to resolve. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * const object = { 'a': [{ 'b': { 'c1': 3, 'c2': () => 4 } }] } + * + * result(object, 'a[0].b.c1') + * // => 3 + * + * result(object, 'a[0].b.c2') + * // => 4 + * + * result(object, 'a[0].b.c3', 'default') + * // => 'default' + * + * result(object, 'a[0].b.c3', () => 'default') + * // => 'default' + */ +function result(object, path, defaultValue) { + path = castPath(path, object) + + let index = -1 + let length = path.length + + // Ensure the loop is entered when path is empty. + if (!length) { + length = 1 + object = undefined + } + while (++index < length) { + let value = object == null ? undefined : object[toKey(path[index])] + if (value === undefined) { + index = length + value = defaultValue + } + object = typeof value === 'function' ? value.call(object) : value + } + return object +} + +export default result diff --git a/libs/lodash/round.js b/libs/lodash/round.js new file mode 100644 index 0000000..b8be056 --- /dev/null +++ b/libs/lodash/round.js @@ -0,0 +1,24 @@ +import createRound from './.internal/createRound.js' + +/** + * Computes `number` rounded to `precision`. + * + * @since 3.10.0 + * @category Math + * @param {number} number The number to round. + * @param {number} [precision=0] The precision to round to. + * @returns {number} Returns the rounded number. + * @example + * + * round(4.006) + * // => 4 + * + * round(4.006, 2) + * // => 4.01 + * + * round(4060, -2) + * // => 4100 + */ +const round = createRound('round') + +export default round diff --git a/libs/lodash/sample.js b/libs/lodash/sample.js new file mode 100644 index 0000000..60e2d89 --- /dev/null +++ b/libs/lodash/sample.js @@ -0,0 +1,18 @@ +/** + * Gets a random element from `array`. + * + * @since 2.0.0 + * @category Array + * @param {Array} array The array to sample. + * @returns {*} Returns the random element. + * @example + * + * sample([1, 2, 3, 4]) + * // => 2 + */ +function sample(array) { + const length = array == null ? 0 : array.length + return length ? array[Math.floor(Math.random() * length)] : undefined +} + +export default sample diff --git a/libs/lodash/sampleSize.js b/libs/lodash/sampleSize.js new file mode 100644 index 0000000..265713c --- /dev/null +++ b/libs/lodash/sampleSize.js @@ -0,0 +1,40 @@ +import copyArray from './.internal/copyArray.js' +import slice from './slice.js' + +/** + * Gets `n` random elements at unique keys from `array` up to the + * size of `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to sample. + * @param {number} [n=1] The number of elements to sample. + * @returns {Array} Returns the random elements. + * @example + * + * sampleSize([1, 2, 3], 2) + * // => [3, 1] + * + * sampleSize([1, 2, 3], 4) + * // => [2, 3, 1] + */ +function sampleSize(array, n) { + n = n == null ? 1 : n + const length = array == null ? 0 : array.length + if (!length || n < 1) { + return [] + } + n = n > length ? length : n + let index = -1 + const lastIndex = length - 1 + const result = copyArray(array) + while (++index < n) { + const rand = index + Math.floor(Math.random() * (lastIndex - index + 1)) + const value = result[rand] + result[rand] = result[index] + result[index] = value + } + return slice(result, 0, n) +} + +export default sampleSize diff --git a/libs/lodash/set.js b/libs/lodash/set.js new file mode 100644 index 0000000..3004ec5 --- /dev/null +++ b/libs/lodash/set.js @@ -0,0 +1,34 @@ +import baseSet from './.internal/baseSet.js' + +/** + * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, + * it's created. Arrays are created for missing index properties while objects + * are created for all other missing properties. Use `setWith` to customize + * `path` creation. + * + * **Note:** This method mutates `object`. + * + * @since 3.7.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @returns {Object} Returns `object`. + * @see has, hasIn, get, unset + * @example + * + * const object = { 'a': [{ 'b': { 'c': 3 } }] } + * + * set(object, 'a[0].b.c', 4) + * console.log(object.a[0].b.c) + * // => 4 + * + * set(object, ['x', '0', 'y', 'z'], 5) + * console.log(object.x[0].y.z) + * // => 5 + */ +function set(object, path, value) { + return object == null ? object : baseSet(object, path, value) +} + +export default set diff --git a/libs/lodash/setWith.js b/libs/lodash/setWith.js new file mode 100644 index 0000000..b070940 --- /dev/null +++ b/libs/lodash/setWith.js @@ -0,0 +1,30 @@ +import baseSet from './.internal/baseSet.js' + +/** + * This method is like `set` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * const object = {} + * + * setWith(object, '[0][1]', 'a', Object) + * // => { '0': { '1': 'a' } } + */ +function setWith(object, path, value, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + return object == null ? object : baseSet(object, path, value, customizer) +} + +export default setWith diff --git a/libs/lodash/shuffle.js b/libs/lodash/shuffle.js new file mode 100644 index 0000000..dc45d12 --- /dev/null +++ b/libs/lodash/shuffle.js @@ -0,0 +1,33 @@ +import copyArray from './.internal/copyArray.js' + +/** + * Creates an array of shuffled values, using a version of the + * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to shuffle. + * @returns {Array} Returns the new shuffled array. + * @example + * + * shuffle([1, 2, 3, 4]) + * // => [4, 1, 3, 2] + */ +function shuffle(array) { + const length = array == null ? 0 : array.length + if (!length) { + return [] + } + let index = -1 + const lastIndex = length - 1 + const result = copyArray(array) + while (++index < length) { + const rand = index + Math.floor(Math.random() * (lastIndex - index + 1)) + const value = result[rand] + result[rand] = result[index] + result[index] = value + } + return result +} + +export default shuffle diff --git a/libs/lodash/size.js b/libs/lodash/size.js new file mode 100644 index 0000000..831011e --- /dev/null +++ b/libs/lodash/size.js @@ -0,0 +1,43 @@ +import getTag from './.internal/getTag.js' +import isArrayLike from './isArrayLike.js' +import isString from './isString.js' +import stringSize from './.internal/stringSize.js' + +/** `Object#toString` result references. */ +const mapTag = '[object Map]' +const setTag = '[object Set]' + +/** + * Gets the size of `collection` by returning its length for array-like + * values or the number of own enumerable string keyed properties for objects. + * + * @since 0.1.0 + * @category Collection + * @param {Array|Object|string} collection The collection to inspect. + * @returns {number} Returns the collection size. + * @example + * + * size([1, 2, 3]) + * // => 3 + * + * size({ 'a': 1, 'b': 2 }) + * // => 2 + * + * size('pebbles') + * // => 7 + */ +function size(collection) { + if (collection == null) { + return 0 + } + if (isArrayLike(collection)) { + return isString(collection) ? stringSize(collection) : collection.length + } + const tag = getTag(collection) + if (tag == mapTag || tag == setTag) { + return collection.size + } + return Object.keys(collection).length +} + +export default size diff --git a/libs/lodash/slice.js b/libs/lodash/slice.js new file mode 100644 index 0000000..9c24d4d --- /dev/null +++ b/libs/lodash/slice.js @@ -0,0 +1,47 @@ +/** + * Creates a slice of `array` from `start` up to, but not including, `end`. + * + * **Note:** This method is used instead of + * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are + * returned. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. A negative index will be treated as an offset from the end. + * @param {number} [end=array.length] The end position. A negative index will be treated as an offset from the end. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var array = [1, 2, 3, 4] + * + * _.slice(array, 2) + * // => [3, 4] + */ +function slice(array, start, end) { + let length = array == null ? 0 : array.length + if (!length) { + return [] + } + start = start == null ? 0 : start + end = end === undefined ? length : end + + if (start < 0) { + start = -start > length ? 0 : (length + start) + } + end = end > length ? length : end + if (end < 0) { + end += length + } + length = start > end ? 0 : ((end - start) >>> 0) + start >>>= 0 + + let index = -1 + const result = new Array(length) + while (++index < length) { + result[index] = array[index + start] + } + return result +} + +export default slice diff --git a/libs/lodash/snakeCase.js b/libs/lodash/snakeCase.js new file mode 100644 index 0000000..8ddde6e --- /dev/null +++ b/libs/lodash/snakeCase.js @@ -0,0 +1,33 @@ +import words from './words.js' +import toString from './toString.js' + +/** + * Converts `string` to + * [snake case](https://en.wikipedia.org/wiki/Snake_case). + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the snake cased string. + * @see camelCase, lowerCase, kebabCase, startCase, upperCase, upperFirst + * @example + * + * snakeCase('Foo Bar') + * // => 'foo_bar' + * + * snakeCase('fooBar') + * // => 'foo_bar' + * + * snakeCase('--FOO-BAR--') + * // => 'foo_bar' + * + * snakeCase('foo2bar') + * // => 'foo_2_bar' + */ +const snakeCase = (string) => ( + words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? '_' : '') + word.toLowerCase() + ), '') +) + +export default snakeCase diff --git a/libs/lodash/some.js b/libs/lodash/some.js new file mode 100644 index 0000000..6f8eebc --- /dev/null +++ b/libs/lodash/some.js @@ -0,0 +1,29 @@ +/** + * Checks if `predicate` returns truthy for **any** element of `array`. + * Iteration is stopped once `predicate` returns truthy. The predicate is + * invoked with three arguments: (value, index, array). + * + * @since 5.0.0 + * @category Array + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + * @example + * + * some([null, 0, 'yes', false], Boolean) + * // => true + */ +function some(array, predicate) { + let index = -1 + const length = array == null ? 0 : array.length + + while (++index < length) { + if (predicate(array[index], index, array)) { + return true + } + } + return false +} + +export default some diff --git a/libs/lodash/someValue.js b/libs/lodash/someValue.js new file mode 100644 index 0000000..a85f002 --- /dev/null +++ b/libs/lodash/someValue.js @@ -0,0 +1,29 @@ +/** + * Checks if `predicate` returns truthy for **any** element of `object`. + * Iteration is stopped once `predicate` returns truthy. The predicate is + * invoked with three arguments: (value, key, object). + * + * @since 5.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + * @example + * + * someValues({ 'a': 0, 'b': 'yes', 'c': false }, Boolean) + * // => true + */ +function someValues(object, predicate) { + object = Object(object) + const props = Object.keys(object) + + for (const key of props) { + if (predicate(object[key], key, object)) { + return true + } + } + return false +} + +export default someValues diff --git a/libs/lodash/sortedIndex.js b/libs/lodash/sortedIndex.js new file mode 100644 index 0000000..fa84fe9 --- /dev/null +++ b/libs/lodash/sortedIndex.js @@ -0,0 +1,22 @@ +import baseSortedIndex from './.internal/baseSortedIndex.js' + +/** + * Uses a binary search to determine the lowest index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * sortedIndex([30, 50], 40) + * // => 1 + */ +function sortedIndex(array, value) { + return baseSortedIndex(array, value) +} + +export default sortedIndex diff --git a/libs/lodash/sortedIndexBy.js b/libs/lodash/sortedIndexBy.js new file mode 100644 index 0000000..61c1c6f --- /dev/null +++ b/libs/lodash/sortedIndexBy.js @@ -0,0 +1,26 @@ +import baseSortedIndexBy from './.internal/baseSortedIndexBy.js' + +/** + * This method is like `sortedIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * const objects = [{ 'n': 4 }, { 'n': 5 }] + * + * sortedIndexBy(objects, { 'n': 4 }, ({ n }) => n) + * // => 0 + */ +function sortedIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, iteratee) +} + +export default sortedIndexBy diff --git a/libs/lodash/sortedIndexOf.js b/libs/lodash/sortedIndexOf.js new file mode 100644 index 0000000..d303240 --- /dev/null +++ b/libs/lodash/sortedIndexOf.js @@ -0,0 +1,29 @@ +import baseSortedIndex from './.internal/baseSortedIndex.js' +import eq from './eq.js' + +/** + * This method is like `indexOf` except that it performs a binary + * search on a sorted `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * sortedIndexOf([4, 5, 5, 5, 6], 5) + * // => 1 + */ +function sortedIndexOf(array, value) { + const length = array == null ? 0 : array.length + if (length) { + const index = baseSortedIndex(array, value) + if (index < length && eq(array[index], value)) { + return index + } + } + return -1 +} + +export default sortedIndexOf diff --git a/libs/lodash/sortedLastIndex.js b/libs/lodash/sortedLastIndex.js new file mode 100644 index 0000000..aee639f --- /dev/null +++ b/libs/lodash/sortedLastIndex.js @@ -0,0 +1,23 @@ +import baseSortedIndex from './.internal/baseSortedIndex.js' + +/** + * This method is like `sortedIndex` except that it returns the highest + * index at which `value` should be inserted into `array` in order to + * maintain its sort order. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * sortedLastIndex([4, 5, 5, 5, 6], 5) + * // => 4 + */ +function sortedLastIndex(array, value) { + return baseSortedIndex(array, value, true) +} + +export default sortedLastIndex diff --git a/libs/lodash/sortedLastIndexBy.js b/libs/lodash/sortedLastIndexBy.js new file mode 100644 index 0000000..a2a14dd --- /dev/null +++ b/libs/lodash/sortedLastIndexBy.js @@ -0,0 +1,26 @@ +import baseSortedIndexBy from './.internal/baseSortedIndexBy.js' + +/** + * This method is like `sortedLastIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * const objects = [{ 'n': 4 }, { 'n': 5 }] + * + * sortedLastIndexBy(objects, { 'n': 4 }, ({ n }) => n) + * // => 1 + */ +function sortedLastIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, iteratee, true) +} + +export default sortedLastIndexBy diff --git a/libs/lodash/sortedLastIndexOf.js b/libs/lodash/sortedLastIndexOf.js new file mode 100644 index 0000000..f4d4ea3 --- /dev/null +++ b/libs/lodash/sortedLastIndexOf.js @@ -0,0 +1,29 @@ +import baseSortedIndex from './.internal/baseSortedIndex.js' +import eq from './eq.js' + +/** + * This method is like `lastIndexOf` except that it performs a binary + * search on a sorted `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * sortedLastIndexOf([4, 5, 5, 5, 6], 5) + * // => 3 + */ +function sortedLastIndexOf(array, value) { + const length = array == null ? 0 : array.length + if (length) { + const index = baseSortedIndex(array, value, true) - 1 + if (eq(array[index], value)) { + return index + } + } + return -1 +} + +export default sortedLastIndexOf diff --git a/libs/lodash/sortedUniq.js b/libs/lodash/sortedUniq.js new file mode 100644 index 0000000..31d1e94 --- /dev/null +++ b/libs/lodash/sortedUniq.js @@ -0,0 +1,24 @@ +import baseSortedUniq from './.internal/baseSortedUniq.js' + +/** + * This method is like `uniq` except that it only works + * for sorted arrays. + * If the input array is known to be sorted `sortedUniq` is + * faster than `uniq`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * sortedUniq([1, 1, 2]) + * // => [1, 2] + */ +function sortedUniq(array) { + return (array != null && array.length) + ? baseSortedUniq(array) + : [] +} + +export default sortedUniq diff --git a/libs/lodash/sortedUniqBy.js b/libs/lodash/sortedUniqBy.js new file mode 100644 index 0000000..32ca129 --- /dev/null +++ b/libs/lodash/sortedUniqBy.js @@ -0,0 +1,23 @@ +import baseSortedUniq from './.internal/baseSortedUniq.js' + +/** + * This method is like `uniqBy` except that it's designed and optimized + * for sorted arrays. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor) + * // => [1.1, 2.3] + */ +function sortedUniqBy(array, iteratee) { + return (array != null && array.length) + ? baseSortedUniq(array, iteratee) + : [] +} + +export default sortedUniqBy diff --git a/libs/lodash/split.js b/libs/lodash/split.js new file mode 100644 index 0000000..e997c4a --- /dev/null +++ b/libs/lodash/split.js @@ -0,0 +1,42 @@ +import castSlice from './.internal/castSlice.js' +import hasUnicode from './.internal/hasUnicode.js' +import isRegExp from './isRegExp.js' +import stringToArray from './.internal/stringToArray.js' + +/** Used as references for the maximum length and index of an array. */ +const MAX_ARRAY_LENGTH = 4294967295 + +/** + * Splits `string` by `separator`. + * + * **Note:** This method is based on + * [`String#split`](https://mdn.io/String/split). + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to split. + * @param {RegExp|string} separator The separator pattern to split by. + * @param {number} [limit] The length to truncate results to. + * @returns {Array} Returns the string segments. + * @example + * + * split('a-b-c', '-', 2) + * // => ['a', 'b'] + */ +function split(string, separator, limit) { + limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0 + if (!limit) { + return [] + } + if (string && ( + typeof separator === 'string' || + (separator != null && !isRegExp(separator)) + )) { + if (!separator && hasUnicode(string)) { + return castSlice(stringToArray(string), 0, limit) + } + } + return string.split(separator, limit) +} + +export default split diff --git a/libs/lodash/startCase.js b/libs/lodash/startCase.js new file mode 100644 index 0000000..77190ff --- /dev/null +++ b/libs/lodash/startCase.js @@ -0,0 +1,30 @@ +import upperFirst from './upperFirst.js' +import words from './words.js' + +/** + * Converts `string` to + * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). + * + * @since 3.1.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the start cased string. + * @see camelCase, lowerCase, kebabCase, snakeCase, upperCase, upperFirst + * @example + * + * startCase('--foo-bar--') + * // => 'Foo Bar' + * + * startCase('fooBar') + * // => 'Foo Bar' + * + * startCase('__FOO_BAR__') + * // => 'FOO BAR' + */ +const startCase = (string) => ( + words(`${string}`.replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + upperFirst(word) + ), '') +) + +export default startCase diff --git a/libs/lodash/startsWith.js b/libs/lodash/startsWith.js new file mode 100644 index 0000000..dfdbf55 --- /dev/null +++ b/libs/lodash/startsWith.js @@ -0,0 +1,36 @@ +/** + * Checks if `string` starts with the given target string. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=0] The position to search from. + * @returns {boolean} Returns `true` if `string` starts with `target`, + * else `false`. + * @see endsWith, includes + * @example + * + * startsWith('abc', 'a') + * // => true + * + * startsWith('abc', 'b') + * // => false + * + * startsWith('abc', 'b', 1) + * // => true + */ +function startsWith(string, target, position) { + const { length } = string + position = position == null ? 0 : position + if (position < 0) { + position = 0 + } + else if (position > length) { + position = length + } + target = `${target}` + return string.slice(position, position + target.length) == target +} + +export default startsWith diff --git a/libs/lodash/subtract.js b/libs/lodash/subtract.js new file mode 100644 index 0000000..bf8ca6d --- /dev/null +++ b/libs/lodash/subtract.js @@ -0,0 +1,18 @@ +import createMathOperation from './.internal/createMathOperation.js' + +/** + * Subtract two numbers. + * + * @since 4.0.0 + * @category Math + * @param {number} minuend The first number in a subtraction. + * @param {number} subtrahend The second number in a subtraction. + * @returns {number} Returns the difference. + * @example + * + * subtract(6, 4) + * // => 2 + */ +const subtract = createMathOperation((minuend, subtrahend) => minuend - subtrahend, 0) + +export default subtract diff --git a/libs/lodash/sum.js b/libs/lodash/sum.js new file mode 100644 index 0000000..c9c0c27 --- /dev/null +++ b/libs/lodash/sum.js @@ -0,0 +1,21 @@ +import baseSum from './.internal/baseSum.js' + +/** + * Computes the sum of the values in `array`. + * + * @since 3.4.0 + * @category Math + * @param {Array} array The array to iterate over. + * @returns {number} Returns the sum. + * @example + * + * sum([4, 2, 8, 6]) + * // => 20 + */ +function sum(array) { + return (array != null && array.length) + ? baseSum(array, (value) => value) + : 0 +} + +export default sum diff --git a/libs/lodash/sumBy.js b/libs/lodash/sumBy.js new file mode 100644 index 0000000..5775bf5 --- /dev/null +++ b/libs/lodash/sumBy.js @@ -0,0 +1,26 @@ +import baseSum from './.internal/baseSum.js' + +/** + * This method is like `sum` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the value to be summed. + * The iteratee is invoked with one argument: (value). + * + * @since 4.0.0 + * @category Math + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {number} Returns the sum. + * @example + * + * const objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }] + * + * sumBy(objects, ({ n }) => n) + * // => 20 + */ +function sumBy(array, iteratee) { + return (array != null && array.length) + ? baseSum(array, iteratee) + : 0 +} + +export default sumBy diff --git a/libs/lodash/tail.js b/libs/lodash/tail.js new file mode 100644 index 0000000..ef837d4 --- /dev/null +++ b/libs/lodash/tail.js @@ -0,0 +1,22 @@ +/** + * Gets all but the first element of `array`. + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * tail([1, 2, 3]) + * // => [2, 3] + */ +function tail(array) { + const length = array == null ? 0 : array.length + if (!length) { + return [] + } + const [, ...result] = array + return result +} + +export default tail diff --git a/libs/lodash/take.js b/libs/lodash/take.js new file mode 100644 index 0000000..890118b --- /dev/null +++ b/libs/lodash/take.js @@ -0,0 +1,32 @@ +import slice from './slice.js' + +/** + * Creates a slice of `array` with `n` elements taken from the beginning. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @returns {Array} Returns the slice of `array`. + * @example + * + * take([1, 2, 3]) + * // => [1] + * + * take([1, 2, 3], 2) + * // => [1, 2] + * + * take([1, 2, 3], 5) + * // => [1, 2, 3] + * + * take([1, 2, 3], 0) + * // => [] + */ +function take(array, n=1) { + if (!(array != null && array.length)) { + return [] + } + return slice(array, 0, n < 0 ? 0 : n) +} + +export default take diff --git a/libs/lodash/takeRight.js b/libs/lodash/takeRight.js new file mode 100644 index 0000000..3ad2a57 --- /dev/null +++ b/libs/lodash/takeRight.js @@ -0,0 +1,34 @@ +import slice from './slice.js' + +/** + * Creates a slice of `array` with `n` elements taken from the end. + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @returns {Array} Returns the slice of `array`. + * @example + * + * takeRight([1, 2, 3]) + * // => [3] + * + * takeRight([1, 2, 3], 2) + * // => [2, 3] + * + * takeRight([1, 2, 3], 5) + * // => [1, 2, 3] + * + * takeRight([1, 2, 3], 0) + * // => [] + */ +function takeRight(array, n=1) { + const length = array == null ? 0 : array.length + if (!length) { + return [] + } + n = length - n + return slice(array, n < 0 ? 0 : n, length) +} + +export default takeRight diff --git a/libs/lodash/takeRightWhile.js b/libs/lodash/takeRightWhile.js new file mode 100644 index 0000000..01cccbe --- /dev/null +++ b/libs/lodash/takeRightWhile.js @@ -0,0 +1,30 @@ +import baseWhile from './.internal/baseWhile.js' + +/** + * Creates a slice of `array` with elements taken from the end. Elements are + * taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': true }, + * { 'user': 'pebbles', 'active': true } + * ] + * + * takeRightWhile(users, ({ active }) => active) + * // => objects for ['fred', 'pebbles'] + */ +function takeRightWhile(array, predicate) { + return (array != null && array.length) + ? baseWhile(array, predicate, false, true) + : [] +} + +export default takeRightWhile diff --git a/libs/lodash/takeWhile.js b/libs/lodash/takeWhile.js new file mode 100644 index 0000000..ec24da5 --- /dev/null +++ b/libs/lodash/takeWhile.js @@ -0,0 +1,30 @@ +import baseWhile from './.internal/baseWhile.js' + +/** + * Creates a slice of `array` with elements taken from the beginning. Elements + * are taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * const users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': true }, + * { 'user': 'pebbles', 'active': false } + * ] + * + * takeWhile(users, ({ active }) => active) + * // => objects for ['barney', 'fred'] + */ +function takeWhile(array, predicate) { + return (array != null && array.length) + ? baseWhile(array, predicate) + : [] +} + +export default takeWhile diff --git a/libs/lodash/throttle.js b/libs/lodash/throttle.js new file mode 100644 index 0000000..6fa0ba8 --- /dev/null +++ b/libs/lodash/throttle.js @@ -0,0 +1,70 @@ +import debounce from './debounce.js' +import isObject from './isObject.js' + +/** + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds (or once per browser frame). The throttled function + * comes with a `cancel` method to cancel delayed `func` invocations and a + * `flush` method to immediately invoke them. Provide `options` to indicate + * whether `func` should be invoked on the leading and/or trailing edge of the + * `wait` timeout. The `func` is invoked with the last arguments provided to the + * throttled function. Subsequent calls to the throttled function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until the next tick, similar to `setTimeout` with a timeout of `0`. + * + * If `wait` is omitted in an environment with `requestAnimationFrame`, `func` + * invocation will be deferred until the next frame is drawn (typically about + * 16ms). + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `throttle` and `debounce`. + * + * @since 0.1.0 + * @category Function + * @param {Function} func The function to throttle. + * @param {number} [wait=0] + * The number of milliseconds to throttle invocations to; if omitted, + * `requestAnimationFrame` is used (if available). + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new throttled function. + * @example + * + * // Avoid excessively updating the position while scrolling. + * jQuery(window).on('scroll', throttle(updatePosition, 100)) + * + * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. + * const throttled = throttle(renewToken, 300000, { 'trailing': false }) + * jQuery(element).on('click', throttled) + * + * // Cancel the trailing throttled invocation. + * jQuery(window).on('popstate', throttled.cancel) + */ +function throttle(func, wait, options) { + let leading = true + let trailing = true + + if (typeof func !== 'function') { + throw new TypeError('Expected a function') + } + if (isObject(options)) { + leading = 'leading' in options ? !!options.leading : leading + trailing = 'trailing' in options ? !!options.trailing : trailing + } + return debounce(func, wait, { + leading, + trailing, + 'maxWait': wait + }) +} + +export default throttle diff --git a/libs/lodash/times.js b/libs/lodash/times.js new file mode 100644 index 0000000..4780462 --- /dev/null +++ b/libs/lodash/times.js @@ -0,0 +1,42 @@ +/** Used as references for various `Number` constants. */ +const MAX_SAFE_INTEGER = 9007199254740991 + +/** Used as references for the maximum length and index of an array. */ +const MAX_ARRAY_LENGTH = 4294967295 + +/** + * Invokes the iteratee `n` times, returning an array of the results of + * each invocation. The iteratee is invoked with one argument: (index). + * + * @since 0.1.0 + * @category Util + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + * @example + * + * times(3, String) + * // => ['0', '1', '2'] + * + * times(4, () => 0) + * // => [0, 0, 0, 0] + */ +function times(n, iteratee) { + if (n < 1 || n > MAX_SAFE_INTEGER) { + return [] + } + let index = -1 + const length = Math.min(n, MAX_ARRAY_LENGTH) + const result = new Array(length) + while (++index < length) { + result[index] = iteratee(index) + } + index = MAX_ARRAY_LENGTH + n -= MAX_ARRAY_LENGTH + while (++index < n) { + iteratee(index) + } + return result +} + +export default times diff --git a/libs/lodash/toArray.js b/libs/lodash/toArray.js new file mode 100644 index 0000000..48c132b --- /dev/null +++ b/libs/lodash/toArray.js @@ -0,0 +1,55 @@ +import copyArray from './.internal/copyArray.js' +import getTag from './.internal/getTag.js' +import isArrayLike from './isArrayLike.js' +import isString from './isString.js' +import iteratorToArray from './.internal/iteratorToArray.js' +import mapToArray from './.internal/mapToArray.js' +import setToArray from './.internal/setToArray.js' +import stringToArray from './.internal/stringToArray.js' +import values from './values.js' + +/** `Object#toString` result references. */ +const mapTag = '[object Map]' +const setTag = '[object Set]' + +/** Built-in value references. */ +const symIterator = Symbol.iterator + +/** + * Converts `value` to an array. + * + * @since 0.1.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {Array} Returns the converted array. + * @example + * + * toArray({ 'a': 1, 'b': 2 }) + * // => [1, 2] + * + * toArray('abc') + * // => ['a', 'b', 'c'] + * + * toArray(1) + * // => [] + * + * toArray(null) + * // => [] + */ +function toArray(value) { + if (!value) { + return [] + } + if (isArrayLike(value)) { + return isString(value) ? stringToArray(value) : copyArray(value) + } + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()) + } + const tag = getTag(value) + const func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values) + + return func(value) +} + +export default toArray diff --git a/libs/lodash/toFinite.js b/libs/lodash/toFinite.js new file mode 100644 index 0000000..7718142 --- /dev/null +++ b/libs/lodash/toFinite.js @@ -0,0 +1,40 @@ +import toNumber from './toNumber.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 +const MAX_INTEGER = 1.7976931348623157e+308 + +/** + * Converts `value` to a finite number. + * + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * toFinite(3.2) + * // => 3.2 + * + * toFinite(Number.MIN_VALUE) + * // => 5e-324 + * + * toFinite(Infinity) + * // => 1.7976931348623157e+308 + * + * toFinite('3.2') + * // => 3.2 + */ +function toFinite(value) { + if (!value) { + return value === 0 ? value : 0 + } + value = toNumber(value) + if (value === INFINITY || value === -INFINITY) { + const sign = (value < 0 ? -1 : 1) + return sign * MAX_INTEGER + } + return value === value ? value : 0 +} + +export default toFinite diff --git a/libs/lodash/toInteger.js b/libs/lodash/toInteger.js new file mode 100644 index 0000000..b09a8b9 --- /dev/null +++ b/libs/lodash/toInteger.js @@ -0,0 +1,35 @@ +import toFinite from './toFinite.js' + +/** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @see isInteger, isNumber, toNumber + * @example + * + * toInteger(3.2) + * // => 3 + * + * toInteger(Number.MIN_VALUE) + * // => 0 + * + * toInteger(Infinity) + * // => 1.7976931348623157e+308 + * + * toInteger('3.2') + * // => 3 + */ +function toInteger(value) { + const result = toFinite(value) + const remainder = result % 1 + + return remainder ? result - remainder : result +} + +export default toInteger diff --git a/libs/lodash/toLength.js b/libs/lodash/toLength.js new file mode 100644 index 0000000..4425c10 --- /dev/null +++ b/libs/lodash/toLength.js @@ -0,0 +1,45 @@ +import toInteger from './toInteger.js' + +/** Used as references for the maximum length and index of an array. */ +const MAX_ARRAY_LENGTH = 4294967295 + +/** + * Converts `value` to an integer suitable for use as the length of an + * array-like object. + * + * **Note:** This method is based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * toLength(3.2) + * // => 3 + * + * toLength(Number.MIN_VALUE) + * // => 0 + * + * toLength(Infinity) + * // => 4294967295 + * + * toLength('3.2') + * // => 3 + */ +function toLength(value) { + if (!value) { + return 0 + } + value = toInteger(value) + if (value < 0) { + return 0 + } + if (value > MAX_ARRAY_LENGTH) { + return MAX_ARRAY_LENGTH + } + return value +} + +export default toLength diff --git a/libs/lodash/toNumber.js b/libs/lodash/toNumber.js new file mode 100644 index 0000000..d4bbca4 --- /dev/null +++ b/libs/lodash/toNumber.js @@ -0,0 +1,65 @@ +import isObject from './isObject.js' +import isSymbol from './isSymbol.js' + +/** Used as references for various `Number` constants. */ +const NAN = 0 / 0 + +/** Used to match leading and trailing whitespace. */ +const reTrim = /^\s+|\s+$/g + +/** Used to detect bad signed hexadecimal string values. */ +const reIsBadHex = /^[-+]0x[0-9a-f]+$/i + +/** Used to detect binary string values. */ +const reIsBinary = /^0b[01]+$/i + +/** Used to detect octal string values. */ +const reIsOctal = /^0o[0-7]+$/i + +/** Built-in method references without a dependency on `root`. */ +const freeParseInt = parseInt + +/** + * Converts `value` to a number. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @see isInteger, toInteger, isNumber + * @example + * + * toNumber(3.2) + * // => 3.2 + * + * toNumber(Number.MIN_VALUE) + * // => 5e-324 + * + * toNumber(Infinity) + * // => Infinity + * + * toNumber('3.2') + * // => 3.2 + */ +function toNumber(value) { + if (typeof value === 'number') { + return value + } + if (isSymbol(value)) { + return NAN + } + if (isObject(value)) { + const other = typeof value.valueOf === 'function' ? value.valueOf() : value + value = isObject(other) ? `${other}` : other + } + if (typeof value !== 'string') { + return value === 0 ? value : +value + } + value = value.replace(reTrim, '') + const isBinary = reIsBinary.test(value) + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value) +} + +export default toNumber diff --git a/libs/lodash/toPath.js b/libs/lodash/toPath.js new file mode 100644 index 0000000..1937937 --- /dev/null +++ b/libs/lodash/toPath.js @@ -0,0 +1,29 @@ +import map from './map.js' +import copyArray from './.internal/copyArray.js' +import isSymbol from './isSymbol.js' +import stringToPath from './.internal/stringToPath.js' +import toKey from './.internal/toKey.js' + +/** + * Converts `value` to a property path array. + * + * @since 4.0.0 + * @category Util + * @param {*} value The value to convert. + * @returns {Array} Returns the new property path array. + * @example + * + * toPath('a.b.c') + * // => ['a', 'b', 'c'] + * + * toPath('a[0].b.c') + * // => ['a', '0', 'b', 'c'] + */ +function toPath(value) { + if (Array.isArray(value)) { + return map(value, toKey) + } + return isSymbol(value) ? [value] : copyArray(stringToPath(value)) +} + +export default toPath diff --git a/libs/lodash/toPlainObject.js b/libs/lodash/toPlainObject.js new file mode 100644 index 0000000..b19a251 --- /dev/null +++ b/libs/lodash/toPlainObject.js @@ -0,0 +1,32 @@ +/** + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. + * + * @since 3.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {Object} Returns the converted plain object. + * @example + * + * function Foo() { + * this.b = 2 + * } + * + * Foo.prototype.c = 3 + * + * assign({ 'a': 1 }, new Foo) + * // => { 'a': 1, 'b': 2 } + * + * assign({ 'a': 1 }, toPlainObject(new Foo)) + * // => { 'a': 1, 'b': 2, 'c': 3 } + */ +function toPlainObject(value) { + value = Object(value) + const result = {} + for (const key in value) { + result[key] = value[key] + } + return result +} + +export default toPlainObject diff --git a/libs/lodash/toSafeInteger.js b/libs/lodash/toSafeInteger.js new file mode 100644 index 0000000..2cf3ee9 --- /dev/null +++ b/libs/lodash/toSafeInteger.js @@ -0,0 +1,42 @@ +import toInteger from './toInteger.js' + +/** Used as references for various `Number` constants. */ +const MAX_SAFE_INTEGER = 9007199254740991 + +/** + * Converts `value` to a safe integer. A safe integer can be compared and + * represented correctly. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * toSafeInteger(3.2) + * // => 3 + * + * toSafeInteger(Number.MIN_VALUE) + * // => 0 + * + * toSafeInteger(Infinity) + * // => 9007199254740991 + * + * toSafeInteger('3.2') + * // => 3 + */ +function toSafeInteger(value) { + if (!value) { + return value === 0 ? value : 0 + } + value = toInteger(value) + if (value < -MAX_SAFE_INTEGER) { + return -MAX_SAFE_INTEGER + } + if (value > MAX_SAFE_INTEGER) { + return MAX_SAFE_INTEGER + } + return value +} + +export default toSafeInteger diff --git a/libs/lodash/toString.js b/libs/lodash/toString.js new file mode 100644 index 0000000..6ba6765 --- /dev/null +++ b/libs/lodash/toString.js @@ -0,0 +1,44 @@ +import isSymbol from './isSymbol.js' + +/** Used as references for various `Number` constants. */ +const INFINITY = 1 / 0 + +/** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * toString(null) + * // => '' + * + * toString(-0) + * // => '-0' + * + * toString([1, 2, 3]) + * // => '1,2,3' + */ +function toString(value) { + if (value == null) { + return '' + } + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value === 'string') { + return value + } + if (Array.isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return `${value.map((other) => other == null ? other : toString(other))}` + } + if (isSymbol(value)) { + return value.toString() + } + const result = `${value}` + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result +} + +export default toString diff --git a/libs/lodash/transform.js b/libs/lodash/transform.js new file mode 100644 index 0000000..b421cb9 --- /dev/null +++ b/libs/lodash/transform.js @@ -0,0 +1,59 @@ +import arrayEach from './.internal/arrayEach.js' +import baseForOwn from './.internal/baseForOwn.js' +import isBuffer from './isBuffer.js' +import isObject from './isObject.js' +import isTypedArray from './isTypedArray.js' + +/** + * An alternative to `reduce` this method transforms `object` to a new + * `accumulator` object which is the result of running each of its own + * enumerable string keyed properties thru `iteratee`, with each invocation + * potentially mutating the `accumulator` object. If `accumulator` is not + * provided, a new object with the same `[[Prototype]]` will be used. The + * iteratee is invoked with four arguments: (accumulator, value, key, object). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @since 1.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The custom accumulator value. + * @returns {*} Returns the accumulated value. + * @see reduce, reduceRight + * @example + * + * transform([2, 3, 4], (result, n) => { + * result.push(n *= n) + * return n % 2 == 0 + * }, []) + * // => [4, 9] + * + * transform({ 'a': 1, 'b': 2, 'c': 1 }, (result, value, key) => { + * (result[value] || (result[value] = [])).push(key) + * }, {}) + * // => { '1': ['a', 'c'], '2': ['b'] } + */ +function transform(object, iteratee, accumulator) { + const isArr = Array.isArray(object) + const isArrLike = isArr || isBuffer(object) || isTypedArray(object) + + if (accumulator == null) { + const Ctor = object && object.constructor + if (isArrLike) { + accumulator = isArr ? new Ctor : [] + } + else if (isObject(object)) { + accumulator = typeof Ctor === 'function' + ? Object.create(Object.getPrototypeOf(object)) + : {} + } + else { + accumulator = {} + } + } + (isArrLike ? arrayEach : baseForOwn)(object, (value, index, object) => + iteratee(accumulator, value, index, object)) + return accumulator +} + +export default transform diff --git a/libs/lodash/trim.js b/libs/lodash/trim.js new file mode 100644 index 0000000..b7ac731 --- /dev/null +++ b/libs/lodash/trim.js @@ -0,0 +1,38 @@ +import castSlice from './.internal/castSlice.js' +import charsEndIndex from './.internal/charsEndIndex.js' +import charsStartIndex from './.internal/charsStartIndex.js' +import stringToArray from './.internal/stringToArray.js' + +/** + * Removes leading and trailing whitespace or specified characters from `string`. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @returns {string} Returns the trimmed string. + * @see trimEnd, trimStart + * @example + * + * trim(' abc ') + * // => 'abc' + * + * trim('-_-abc-_-', '_-') + * // => 'abc' + */ +function trim(string, chars) { + if (string && chars === undefined) { + return string.trim() + } + if (!string || !chars) { + return (string || '') + } + const strSymbols = stringToArray(string) + const chrSymbols = stringToArray(chars) + const start = charsStartIndex(strSymbols, chrSymbols) + const end = charsEndIndex(strSymbols, chrSymbols) + 1 + + return castSlice(strSymbols, start, end).join('') +} + +export default trim diff --git a/libs/lodash/trimEnd.js b/libs/lodash/trimEnd.js new file mode 100644 index 0000000..b802521 --- /dev/null +++ b/libs/lodash/trimEnd.js @@ -0,0 +1,36 @@ +import castSlice from './.internal/castSlice.js' +import charsEndIndex from './.internal/charsEndIndex.js' +import stringToArray from './.internal/stringToArray.js' + +const methodName = ''.trimRight ? 'trimRight': 'trimEnd' + +/** + * Removes trailing whitespace or specified characters from `string`. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @returns {string} Returns the trimmed string. + * @see trim, trimStart + * @example + * + * trimEnd(' abc ') + * // => ' abc' + * + * trimEnd('-_-abc-_-', '_-') + * // => '-_-abc' + */ +function trimEnd(string, chars) { + if (string && chars === undefined) { + return string[methodName]() + } + if (!string || !chars) { + return (string || '') + } + const strSymbols = stringToArray(string) + const end = charsEndIndex(strSymbols, stringToArray(chars)) + 1 + return castSlice(strSymbols, 0, end).join('') +} + +export default trimEnd diff --git a/libs/lodash/trimStart.js b/libs/lodash/trimStart.js new file mode 100644 index 0000000..6138a88 --- /dev/null +++ b/libs/lodash/trimStart.js @@ -0,0 +1,36 @@ +import castSlice from './.internal/castSlice.js' +import charsStartIndex from './.internal/charsStartIndex.js' +import stringToArray from './.internal/stringToArray.js' + +const methodName = ''.trimLeft ? 'trimLeft' : 'trimStart' + +/** + * Removes leading whitespace or specified characters from `string`. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to trim. + * @param {string} [chars=whitespace] The characters to trim. + * @returns {string} Returns the trimmed string. + * @see trim, trimEnd + * @example + * + * trimStart(' abc ') + * // => 'abc ' + * + * trimStart('-_-abc-_-', '_-') + * // => 'abc-_-' + */ +function trimStart(string, chars) { + if (string && chars === undefined) { + return string[methodName]() + } + if (!string || !chars) { + return (string || '') + } + const strSymbols = stringToArray(string) + const start = charsStartIndex(strSymbols, stringToArray(chars)) + return castSlice(strSymbols, start).join('') +} + +export default trimStart diff --git a/libs/lodash/truncate.js b/libs/lodash/truncate.js new file mode 100644 index 0000000..f3a928c --- /dev/null +++ b/libs/lodash/truncate.js @@ -0,0 +1,113 @@ +import baseToString from './.internal/baseToString.js' +import castSlice from './.internal/castSlice.js' +import hasUnicode from './.internal/hasUnicode.js' +import isObject from './isObject.js' +import isRegExp from './isRegExp.js' +import stringSize from './.internal/stringSize.js' +import stringToArray from './.internal/stringToArray.js' +import toString from './toString.js' + +/** Used as default options for `truncate`. */ +const DEFAULT_TRUNC_LENGTH = 30 +const DEFAULT_TRUNC_OMISSION = '...' + +/** Used to match `RegExp` flags from their coerced string values. */ +const reFlags = /\w*$/ + +/** + * Truncates `string` if it's longer than the given maximum string length. + * The last characters of the truncated string are replaced with the omission + * string which defaults to "...". + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to truncate. + * @param {Object} [options={}] The options object. + * @param {number} [options.length=30] The maximum string length. + * @param {string} [options.omission='...'] The string to indicate text is omitted. + * @param {RegExp|string} [options.separator] The separator pattern to truncate to. + * @returns {string} Returns the truncated string. + * @see replace + * @example + * + * truncate('hi-diddly-ho there, neighborino') + * // => 'hi-diddly-ho there, neighbo...' + * + * truncate('hi-diddly-ho there, neighborino', { + * 'length': 24, + * 'separator': ' ' + * }) + * // => 'hi-diddly-ho there,...' + * + * truncate('hi-diddly-ho there, neighborino', { + * 'length': 24, + * 'separator': /,? +/ + * }) + * // => 'hi-diddly-ho there...' + * + * truncate('hi-diddly-ho there, neighborino', { + * 'omission': ' [...]' + * }) + * // => 'hi-diddly-ho there, neig [...]' + */ +function truncate(string, options) { + let separator + let length = DEFAULT_TRUNC_LENGTH + let omission = DEFAULT_TRUNC_OMISSION + + if (isObject(options)) { + separator = 'separator' in options ? options.separator : separator + length = 'length' in options ? options.length : length + omission = 'omission' in options ? baseToString(options.omission) : omission + } + + string = toString(string) + + let strSymbols + let strLength = string.length + if (hasUnicode(string)) { + strSymbols = stringToArray(string) + strLength = strSymbols.length + } + if (length >= strLength) { + return string + } + let end = length - stringSize(omission) + if (end < 1) { + return omission + } + let result = strSymbols + ? castSlice(strSymbols, 0, end).join('') + : string.slice(0, end) + + if (separator === undefined) { + return result + omission + } + if (strSymbols) { + end += (result.length - end) + } + if (isRegExp(separator)) { + if (string.slice(end).search(separator)) { + let match + let newEnd + const substring = result + + if (!separator.global) { + separator = RegExp(separator.source, `${reFlags.exec(separator) || ''}g`) + } + separator.lastIndex = 0 + while ((match = separator.exec(substring))) { + newEnd = match.index + } + result = result.slice(0, newEnd === undefined ? end : newEnd) + } + } else if (string.indexOf(baseToString(separator), end) != end) { + const index = result.lastIndexOf(separator) + if (index > -1) { + result = result.slice(0, index) + } + } + return result + omission +} + +export default truncate diff --git a/libs/lodash/unescape.js b/libs/lodash/unescape.js new file mode 100644 index 0000000..f28d0b3 --- /dev/null +++ b/libs/lodash/unescape.js @@ -0,0 +1,38 @@ +/** Used to map HTML entities to characters. */ +const htmlUnescapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'" +} + +/** Used to match HTML entities and HTML characters. */ +const reEscapedHtml = /&(?:amp|lt|gt|quot|#(0+)?39);/g +const reHasEscapedHtml = RegExp(reEscapedHtml.source) + +/** + * The inverse of `escape`this method converts the HTML entities + * `&`, `<`, `>`, `"` and `'` in `string` to + * their corresponding characters. + * + * **Note:** No other HTML entities are unescaped. To unescape additional + * HTML entities use a third-party library like [_he_](https://mths.be/he). + * + * @since 0.6.0 + * @category String + * @param {string} [string=''] The string to unescape. + * @returns {string} Returns the unescaped string. + * @see escape, escapeRegExp + * @example + * + * unescape('fred, barney, & pebbles') + * // => 'fred, barney, & pebbles' + */ +function unescape(string) { + return (string && reHasEscapedHtml.test(string)) + ? string.replace(reEscapedHtml, (entity) => (htmlUnescapes[entity] || "'")) + : (string || '') +} + +export default unescape diff --git a/libs/lodash/union.js b/libs/lodash/union.js new file mode 100644 index 0000000..77b3b6b --- /dev/null +++ b/libs/lodash/union.js @@ -0,0 +1,24 @@ +import baseFlatten from './.internal/baseFlatten.js' +import baseUniq from './.internal/baseUniq.js' +import isArrayLikeObject from './isArrayLikeObject.js' + +/** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @see difference, unionBy, unionWith, without, xor, xorBy + * @example + * + * union([2, 3], [1, 2]) + * // => [2, 3, 1] + */ +function union(...arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)) +} + +export default union diff --git a/libs/lodash/unionBy.js b/libs/lodash/unionBy.js new file mode 100644 index 0000000..8934339 --- /dev/null +++ b/libs/lodash/unionBy.js @@ -0,0 +1,32 @@ +import baseFlatten from './.internal/baseFlatten.js' +import baseUniq from './.internal/baseUniq.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `union` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: + * (value). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new array of combined values. + * @see difference, union, unionWith, without, xor, xorBy + * @example + * + * unionBy([2.1], [1.2, 2.3], Math.floor) + * // => [2.1, 1.2] + */ +function unionBy(...arrays) { + let iteratee = last(arrays) + if (isArrayLikeObject(iteratee)) { + iteratee = undefined + } + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), iteratee) +} + +export default unionBy diff --git a/libs/lodash/unionWith.js b/libs/lodash/unionWith.js new file mode 100644 index 0000000..c5c3be9 --- /dev/null +++ b/libs/lodash/unionWith.js @@ -0,0 +1,32 @@ +import baseFlatten from './.internal/baseFlatten.js' +import baseUniq from './.internal/baseUniq.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `union` except that it accepts `comparator` which + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of combined values. + * @see difference, union, unionBy, without, xor, xorBy + * @example + * + * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + * const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }] + * + * unionWith(objects, others, isEqual) + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ +function unionWith(...arrays) { + let comparator = last(arrays) + comparator = typeof comparator === 'function' ? comparator : undefined + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator) +} + +export default unionWith diff --git a/libs/lodash/uniq.js b/libs/lodash/uniq.js new file mode 100644 index 0000000..68be2d0 --- /dev/null +++ b/libs/lodash/uniq.js @@ -0,0 +1,26 @@ +import baseUniq from './.internal/baseUniq.js' + +/** + * Creates a duplicate-free version of an array, using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons, in which only the first occurrence of each element + * is kept. The order of result values is determined by the order they occur + * in the array. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @see uniqBy, uniqWith + * @example + * + * uniq([2, 1, 2]) + * // => [2, 1] + */ +function uniq(array) { + return (array != null && array.length) + ? baseUniq(array) + : [] +} + +export default uniq diff --git a/libs/lodash/uniqBy.js b/libs/lodash/uniqBy.js new file mode 100644 index 0000000..dc24a7c --- /dev/null +++ b/libs/lodash/uniqBy.js @@ -0,0 +1,27 @@ +import baseUniq from './.internal/baseUniq.js' + +/** + * This method is like `uniq` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * uniqueness is computed. The order of result values is determined by the + * order they occur in the array. The iteratee is invoked with one argument: + * (value). + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @see uniq, uniqWith + * @example + * + * uniqBy([2.1, 1.2, 2.3], Math.floor) + * // => [2.1, 1.2] + */ +function uniqBy(array, iteratee) { + return (array != null && array.length) + ? baseUniq(array, iteratee) + : [] +} + +export default uniqBy diff --git a/libs/lodash/uniqWith.js b/libs/lodash/uniqWith.js new file mode 100644 index 0000000..77feac1 --- /dev/null +++ b/libs/lodash/uniqWith.js @@ -0,0 +1,29 @@ +import baseUniq from './.internal/baseUniq.js' + +/** + * This method is like `uniq` except that it accepts `comparator` which + * is invoked to compare elements of `array`. The order of result values is + * determined by the order they occur in the array. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @see uniq, uniqBy + * @example + * + * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }] + * + * uniqWith(objects, isEqual) + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + */ +function uniqWith(array, comparator) { + comparator = typeof comparator === 'function' ? comparator : undefined + return (array != null && array.length) + ? baseUniq(array, undefined, comparator) + : [] +} + +export default uniqWith diff --git a/libs/lodash/uniqueId.js b/libs/lodash/uniqueId.js new file mode 100644 index 0000000..934ece2 --- /dev/null +++ b/libs/lodash/uniqueId.js @@ -0,0 +1,33 @@ +/** Used to generate unique IDs. */ +const idCounter = {} + +/** + * Generates a unique ID. If `prefix` is given, the ID is appended to it. + * + * @since 0.1.0 + * @category Util + * @param {string} [prefix=''] The value to prefix the ID with. + * @returns {string} Returns the unique ID. + * @see random + * @example + * + * uniqueId('contact_') + * // => 'contact_104' + * + * uniqueId() + * // => '105' + */ +function uniqueId(prefix='$lodash$') { + if (!idCounter[prefix]) { + idCounter[prefix] = 0 + } + + const id =++idCounter[prefix] + if (prefix === '$lodash$') { + return `${id}` + } + + return `${prefix}${id}` +} + +export default uniqueId diff --git a/libs/lodash/unset.js b/libs/lodash/unset.js new file mode 100644 index 0000000..15ddd56 --- /dev/null +++ b/libs/lodash/unset.js @@ -0,0 +1,33 @@ +import baseUnset from './.internal/baseUnset.js' + +/** + * Removes the property at `path` of `object`. + * + * **Note:** This method mutates `object`. + * + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + * @see get, has, set + * @example + * + * const object = { 'a': [{ 'b': { 'c': 7 } }] } + * unset(object, 'a[0].b.c') + * // => true + * + * console.log(object) + * // => { 'a': [{ 'b': {} }] } + * + * unset(object, ['a', '0', 'b', 'c']) + * // => true + * + * console.log(object) + * // => { 'a': [{ 'b': {} }] } + */ +function unset(object, path) { + return object == null ? true : baseUnset(object, path) +} + +export default unset diff --git a/libs/lodash/unzip.js b/libs/lodash/unzip.js new file mode 100644 index 0000000..a49220b --- /dev/null +++ b/libs/lodash/unzip.js @@ -0,0 +1,43 @@ +import filter from './filter.js' +import map from './map.js' +import baseProperty from './.internal/baseProperty.js' +import isArrayLikeObject from './isArrayLikeObject.js' + +/** + * This method is like `zip` except that it accepts an array of grouped + * elements and creates an array regrouping the elements to their pre-zip + * configuration. + * + * @since 1.2.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @returns {Array} Returns the new array of regrouped elements. + * @see unzipWith, zip, zipObject, zipObjectDeep, zipWith + * @example + * + * const zipped = zip(['a', 'b'], [1, 2], [true, false]) + * // => [['a', 1, true], ['b', 2, false]] + * + * unzip(zipped) + * // => [['a', 'b'], [1, 2], [true, false]] + */ +function unzip(array) { + if (!(array != null && array.length)) { + return [] + } + let length = 0 + array = filter(array, (group) => { + if (isArrayLikeObject(group)) { + length = Math.max(group.length, length) + return true + } + }) + let index = -1 + const result = new Array(length) + while (++index < length) { + result[index] = map(array, baseProperty(index)) + } + return result +} + +export default unzip diff --git a/libs/lodash/unzipWith.js b/libs/lodash/unzipWith.js new file mode 100644 index 0000000..7c2aeef --- /dev/null +++ b/libs/lodash/unzipWith.js @@ -0,0 +1,31 @@ +import map from './map.js' +import unzip from './unzip.js' + +/** + * This method is like `unzip` except that it accepts `iteratee` to specify + * how regrouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @since 3.8.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @param {Function} iteratee The function to combine + * regrouped values. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * const zipped = zip([1, 2], [10, 20], [100, 200]) + * // => [[1, 10, 100], [2, 20, 200]] + * + * unzipWith(zipped, add) + * // => [3, 30, 300] + */ +function unzipWith(array, iteratee) { + if (!(array != null && array.length)) { + return [] + } + const result = unzip(array) + return map(result, (group) => iteratee.apply(undefined, group)) +} + +export default unzipWith diff --git a/libs/lodash/update.js b/libs/lodash/update.js new file mode 100644 index 0000000..75d3a94 --- /dev/null +++ b/libs/lodash/update.js @@ -0,0 +1,32 @@ +import baseUpdate from './.internal/baseUpdate.js' + +/** + * This method is like `set` except that it accepts `updater` to produce the + * value to set. Use `updateWith` to customize `path` creation. The `updater` + * is invoked with one argument: (value). + * + * **Note:** This method mutates `object`. + * + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @returns {Object} Returns `object`. + * @example + * + * const object = { 'a': [{ 'b': { 'c': 3 } }] } + * + * update(object, 'a[0].b.c', n => n * n) + * console.log(object.a[0].b.c) + * // => 9 + * + * update(object, 'x[0].y.z', n => n ? n + 1 : 0) + * console.log(object.x[0].y.z) + * // => 0 + */ +function update(object, path, updater) { + return object == null ? object : baseUpdate(object, path, updater) +} + +export default update diff --git a/libs/lodash/updateWith.js b/libs/lodash/updateWith.js new file mode 100644 index 0000000..60a37e1 --- /dev/null +++ b/libs/lodash/updateWith.js @@ -0,0 +1,30 @@ +import baseUpdate from './.internal/baseUpdate.js' + +/** + * This method is like `update` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * const object = {} + * + * updateWith(object, '[0][1]', () => 'a', Object) + * // => { '0': { '1': 'a' } } + */ +function updateWith(object, path, updater, customizer) { + customizer = typeof customizer === 'function' ? customizer : undefined + return object == null ? object : baseUpdate(object, path, updater, customizer) +} + +export default updateWith diff --git a/libs/lodash/upperCase.js b/libs/lodash/upperCase.js new file mode 100644 index 0000000..db14da8 --- /dev/null +++ b/libs/lodash/upperCase.js @@ -0,0 +1,29 @@ +import words from './words.js' +import toString from './toString.js' + +/** + * Converts `string`, as space separated words, to upper case. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the upper cased string. + * @see camelCase, kebabCase, lowerCase, snakeCase, startCase, upperFirst + * @example + * + * upperCase('--foo-bar') + * // => 'FOO BAR' + * + * upperCase('fooBar') + * // => 'FOO BAR' + * + * upperCase('__foo_bar__') + * // => 'FOO BAR' + */ +const upperCase = (string) => ( + words(toString(string).replace(/['\u2019]/g, '')).reduce((result, word, index) => ( + result + (index ? ' ' : '') + word.toUpperCase() + ), '') +) + +export default upperCase diff --git a/libs/lodash/upperFirst.js b/libs/lodash/upperFirst.js new file mode 100644 index 0000000..2c07717 --- /dev/null +++ b/libs/lodash/upperFirst.js @@ -0,0 +1,21 @@ +import createCaseFirst from './.internal/createCaseFirst.js' + +/** + * Converts the first character of `string` to upper case. + * + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the converted string. + * @see camelCase, kebabCase, lowerCase, snakeCase, startCase, upperCase + * @example + * + * upperFirst('fred') + * // => 'Fred' + * + * upperFirst('FRED') + * // => 'FRED' + */ +const upperFirst = createCaseFirst('toUpperCase') + +export default upperFirst diff --git a/libs/lodash/values.js b/libs/lodash/values.js new file mode 100644 index 0000000..8d11180 --- /dev/null +++ b/libs/lodash/values.js @@ -0,0 +1,33 @@ +import baseValues from './.internal/baseValues.js' +import keys from './keys.js' + +/** + * Creates an array of the own enumerable string keyed property values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @since 0.1.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @see keys, valuesIn + * @example + * + * function Foo() { + * this.a = 1 + * this.b = 2 + * } + * + * Foo.prototype.c = 3 + * + * values(new Foo) + * // => [1, 2] (iteration order is not guaranteed) + * + * values('hi') + * // => ['h', 'i'] + */ +function values(object) { + return object == null ? [] : baseValues(object, keys(object)) +} + +export default values diff --git a/libs/lodash/without.js b/libs/lodash/without.js new file mode 100644 index 0000000..60d506b --- /dev/null +++ b/libs/lodash/without.js @@ -0,0 +1,26 @@ +import baseDifference from './.internal/baseDifference.js' +import isArrayLikeObject from './isArrayLikeObject.js' + +/** + * Creates an array excluding all given values using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `pull`, this method returns a new array. + * + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...*} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see difference, union, unionBy, unionWith, xor, xorBy, xorWith + * @example + * + * without([2, 1, 2, 3], 1, 2) + * // => [3] + */ +function without(array, ...values) { + return isArrayLikeObject(array) ? baseDifference(array, values) : [] +} + +export default without diff --git a/libs/lodash/words.js b/libs/lodash/words.js new file mode 100644 index 0000000..fef05f8 --- /dev/null +++ b/libs/lodash/words.js @@ -0,0 +1,38 @@ +import unicodeWords from './.internal/unicodeWords.js' + +const hasUnicodeWord = RegExp.prototype.test.bind( + /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/ +) + +/** Used to match words composed of alphanumeric characters. */ +const reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g + +function asciiWords(string) { + return string.match(reAsciiWord) +} + +/** + * Splits `string` into an array of its words. + * + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {RegExp|string} [pattern] The pattern to match words. + * @returns {Array} Returns the words of `string`. + * @example + * + * words('fred, barney, & pebbles') + * // => ['fred', 'barney', 'pebbles'] + * + * words('fred, barney, & pebbles', /[^, ]+/g) + * // => ['fred', 'barney', '&', 'pebbles'] + */ +function words(string, pattern) { + if (pattern === undefined) { + const result = hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string) + return result || [] + } + return string.match(pattern) || [] +} + +export default words diff --git a/libs/lodash/xor.js b/libs/lodash/xor.js new file mode 100644 index 0000000..8b5e868 --- /dev/null +++ b/libs/lodash/xor.js @@ -0,0 +1,24 @@ +import baseXor from './.internal/baseXor.js' +import isArrayLikeObject from './isArrayLikeObject.js' + +/** + * Creates an array of unique values that is the + * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) + * of the given arrays. The order of result values is determined by the order + * they occur in the arrays. + * + * @since 2.4.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of filtered values. + * @see difference, union, unionBy, unionWith, without, xorBy, xorWith + * @example + * + * xor([2, 1], [2, 3]) + * // => [1, 3] + */ +function xor(...arrays) { + return baseXor(arrays.filter(isArrayLikeObject)) +} + +export default xor diff --git a/libs/lodash/xorBy.js b/libs/lodash/xorBy.js new file mode 100644 index 0000000..87b75a3 --- /dev/null +++ b/libs/lodash/xorBy.js @@ -0,0 +1,31 @@ +import baseXor from './.internal/baseXor.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `xor` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which they're compared. The order of result values is determined + * by the order they occur in the arrays. The iteratee is invoked with one + * argument: (value). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} iteratee The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @see difference, union, unionBy, unionWith, without, xor, xorWith + * @example + * + * xorBy([2.1, 1.2], [2.3, 3.4], Math.floor) + * // => [1.2, 3.4] + */ +function xorBy(...arrays) { + let iteratee = last(arrays) + if (isArrayLikeObject(iteratee)) { + iteratee = undefined + } + return baseXor(arrays.filter(isArrayLikeObject), iteratee) +} + +export default xorBy diff --git a/libs/lodash/xorWith.js b/libs/lodash/xorWith.js new file mode 100644 index 0000000..97775d7 --- /dev/null +++ b/libs/lodash/xorWith.js @@ -0,0 +1,31 @@ +import baseXor from './.internal/baseXor.js' +import isArrayLikeObject from './isArrayLikeObject.js' +import last from './last.js' + +/** + * This method is like `xor` except that it accepts `comparator` which is + * invoked to compare elements of `arrays`. The order of result values is + * determined by the order they occur in the arrays. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @see difference, union, unionBy, unionWith, without, xor, xorBy + * @example + * + * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + * const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }] + * + * xorWith(objects, others, isEqual) + * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ +function xorWith(...arrays) { + let comparator = last(arrays) + comparator = typeof comparator === 'function' ? comparator : undefined + return baseXor(arrays.filter(isArrayLikeObject), undefined, comparator) +} + +export default xorWith diff --git a/libs/lodash/zip.js b/libs/lodash/zip.js new file mode 100644 index 0000000..905c82c --- /dev/null +++ b/libs/lodash/zip.js @@ -0,0 +1,22 @@ +import unzip from './unzip.js' + +/** + * Creates an array of grouped elements, the first of which contains the + * first elements of the given arrays, the second of which contains the + * second elements of the given arrays, and so on. + * + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @returns {Array} Returns the new array of grouped elements. + * @see unzip, unzipWith, zipObject, zipObjectDeep, zipWith + * @example + * + * zip(['a', 'b'], [1, 2], [true, false]) + * // => [['a', 1, true], ['b', 2, false]] + */ +function zip(...arrays) { + return unzip(arrays) +} + +export default zip diff --git a/libs/lodash/zipObject.js b/libs/lodash/zipObject.js new file mode 100644 index 0000000..309da74 --- /dev/null +++ b/libs/lodash/zipObject.js @@ -0,0 +1,23 @@ +import assignValue from './.internal/assignValue.js' +import baseZipObject from './.internal/baseZipObject.js' + +/** + * This method is like `fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @see unzip, unzipWith, zip, zipObjectDeep, zipWith + * @example + * + * zipObject(['a', 'b'], [1, 2]) + * // => { 'a': 1, 'b': 2 } + */ +function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue) +} + +export default zipObject diff --git a/libs/lodash/zipObjectDeep.js b/libs/lodash/zipObjectDeep.js new file mode 100644 index 0000000..07eec2c --- /dev/null +++ b/libs/lodash/zipObjectDeep.js @@ -0,0 +1,22 @@ +import baseSet from './.internal/baseSet.js' +import baseZipObject from './.internal/baseZipObject.js' + +/** + * This method is like `zipObject` except that it supports property paths. + * + * @since 4.1.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @see unzip, unzipWith, zip, zipObject, zipWith + * @example + * + * zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]) + * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } + */ +function zipObjectDeep(props, values) { + return baseZipObject(props || [], values || [], baseSet) +} + +export default zipObjectDeep diff --git a/libs/lodash/zipWith.js b/libs/lodash/zipWith.js new file mode 100644 index 0000000..30989ac --- /dev/null +++ b/libs/lodash/zipWith.js @@ -0,0 +1,27 @@ +import unzipWith from './unzipWith.js' + +/** + * This method is like `zip` except that it accepts `iteratee` to specify + * how grouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @since 3.8.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @param {Function} iteratee The function to combine + * grouped values. + * @returns {Array} Returns the new array of grouped elements. + * @see unzip, unzipWith, zip, zipObject, zipObjectDeep, zipWith + * @example + * + * zipWith([1, 2], [10, 20], [100, 200], (a, b, c) => a + b + c) + * // => [111, 222] + */ +function zipWith(...arrays) { + const length = arrays.length + let iteratee = length > 1 ? arrays[length - 1] : undefined + iteratee = typeof iteratee === 'function' ? (arrays.pop(), iteratee) : undefined + return unzipWith(arrays, iteratee) +} + +export default zipWith diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..377f036 --- /dev/null +++ b/manifest.json @@ -0,0 +1,61 @@ +{ + "manifest_version": 3, + "version": "1.0", + "name": "APAC: Remove background trigger", + "background": { + "service_worker": "background.js", + "type": "module" + }, + "web_accessible_resources": [ + { + "resources": [ + "contents/remove_bg.js", + "contents/image_editor.js" + ], + "matches": [ "https://*/*" ] + } + ], + "permissions": [ + "tabs", + "notifications", + "scripting", + "activeTab", + "webNavigation", + "storage", + "windows", + "topSites" + ], + "icons": { + "32": "icon/32.png", + "48": "icon/48.png", + "128": "icon/128.png" + }, + "action": { + "default_icon": "icon/128.png", + "default_popup": "popup.html" + }, + "content_scripts": [ + { + "matches": [ + "https://stage-editor.danielvu.com/*", + "http://localhost:8000/*", + "http://127.0.0.1:8000/*" + ], + "js": [ + "contents/image_editor.js" + ], + "all_frames": true, + "run_at": "document_start" + }, + { + "matches": [ + "https://www.remove.bg/*" + ], + "js": [ + "contents/remove_bg.js" + ], + "all_frames": true, + "run_at": "document_end" + } + ] +} diff --git a/popup.css b/popup.css new file mode 100644 index 0000000..97b1eb4 --- /dev/null +++ b/popup.css @@ -0,0 +1,130 @@ + +button, [type="submit"] { + appearance: none; + background-color: #2ea44f; + border: 1px solid rgba(27, 31, 35, .15); + box-shadow: rgba(27, 31, 35, .1) 0 1px 0; + box-sizing: border-box; + color: #fff; + cursor: pointer; + display: inline-block; + font-family: -apple-system, system-ui, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"; + font-size: 14px; + font-weight: 600; + line-height: 20px; + padding: 6px 16px; + position: relative; + text-align: center; + text-decoration: none; + user-select: none; + -webkit-user-select: none; + touch-action: manipulation; + vertical-align: middle; + white-space: nowrap; +} + +select { + width: 50%; +} + +.operation { + position: fixed; + top: 0; + left: 0; + height: 30px; + display: inline; +} + +.operation .group { + display: flex; + justify-content: left; + align-items: center; +} + +table { + min-width: 400px; + border: 1px solid #ccc; + border-collapse: collapse; + margin: 0; + padding: 0; + width: 100%; + table-layout: fixed; +} + +table caption { + font-size: 1.5em; + margin: .5em 0 .75em; +} + +table tr { + background-color: #f8f8f8; + border: 1px solid #ddd; + padding: .35em; +} + +table th, +table td { + padding: .625em; + text-align: center; +} + +table th { + font-size: .85em; + letter-spacing: .1em; + text-transform: uppercase; +} + +@media screen and (max-width: 600px) { + table { + border: 0; + } + + table caption { + font-size: 1.3em; + } + + table thead { + border: none; + clip: rect(0 0 0 0); + height: 1px; + margin: -1px; + overflow: hidden; + padding: 0; + position: absolute; + width: 1px; + } + + table tr { + border-bottom: 3px solid #ddd; + display: block; + margin-bottom: .625em; + } + + table td { + border-bottom: 1px solid #ddd; + display: block; + font-size: .8em; + text-align: right; + } + + table td::before { + /* +* aria-label has no advantage, it won't be read inside a table +content: attr(aria-label); +*/ + content: attr(data-label); + float: left; + font-weight: bold; + text-transform: uppercase; + } + + table td:last-child { + border-bottom: 0; + } +} + +/* general styling */ +body { + font-family: "Open Sans", sans-serif; + line-height: 1.25; +} diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..b77887a --- /dev/null +++ b/popup.html @@ -0,0 +1 @@ +

remove.bg extension

diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..e69de29