es-toolkit 1.23.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +1 -1
- package/dist/_chunk/{isWeakSet-BAMm2l.js → isWeakSet-Bd6nry.js} +59 -46
- package/dist/_chunk/{range-BXlMmn.js → sumBy-BkErWJ.js} +25 -5
- package/dist/_chunk/{isObjectLike-aywuSF.js → toMerged-DDLv0D.js} +88 -86
- package/dist/_chunk/{flowRight-Dv8J0U.js → unary-BZ5Ixo.js} +27 -64
- package/dist/_chunk/{zipWith-EOU_KZ.js → zipWith-wpjySR.js} +8 -17
- package/dist/array/dropRightWhile.d.mts +2 -2
- package/dist/array/dropRightWhile.d.ts +2 -2
- package/dist/array/dropRightWhile.mjs +1 -1
- package/dist/array/dropWhile.d.mts +1 -1
- package/dist/array/dropWhile.d.ts +1 -1
- package/dist/array/index.js +1 -1
- package/dist/array/unionBy.mjs +3 -10
- package/dist/browser.global.js +1 -1
- package/dist/browser.global.js.map +1 -1
- package/dist/compat/_internal/MAX_ARRAY_LENGTH.mjs +3 -0
- package/dist/compat/_internal/isIterateeCall.mjs +17 -0
- package/dist/compat/array/difference.d.mts +9 -3
- package/dist/compat/array/difference.d.ts +9 -3
- package/dist/compat/array/difference.mjs +12 -3
- package/dist/compat/array/dropRightWhile.d.mts +60 -0
- package/dist/compat/array/dropRightWhile.d.ts +60 -0
- package/dist/compat/array/dropRightWhile.mjs +27 -0
- package/dist/compat/array/every.mjs +4 -5
- package/dist/compat/array/filter.mjs +4 -5
- package/dist/compat/array/find.mjs +4 -5
- package/dist/compat/array/includes.mjs +2 -1
- package/dist/compat/array/slice.d.mts +18 -0
- package/dist/compat/array/slice.d.ts +18 -0
- package/dist/compat/array/slice.mjs +38 -0
- package/dist/compat/array/take.d.mts +25 -0
- package/dist/compat/array/take.d.ts +25 -0
- package/dist/compat/array/take.mjs +10 -0
- package/dist/compat/function/before.d.mts +26 -0
- package/dist/compat/function/before.d.ts +26 -0
- package/dist/compat/function/before.mjs +20 -0
- package/dist/compat/function/curryRight.d.mts +50 -0
- package/dist/compat/function/curryRight.d.ts +50 -0
- package/dist/compat/function/curryRight.mjs +64 -0
- package/dist/compat/index.d.mts +86 -75
- package/dist/compat/index.d.ts +86 -75
- package/dist/compat/index.js +779 -496
- package/dist/compat/index.mjs +86 -75
- package/dist/compat/object/defaults.d.mts +120 -0
- package/dist/compat/object/defaults.d.ts +120 -0
- package/dist/compat/object/defaults.mjs +21 -0
- package/dist/compat/object/invertBy.d.mts +27 -0
- package/dist/compat/object/invertBy.d.ts +27 -0
- package/dist/compat/object/invertBy.mjs +27 -0
- package/dist/compat/object/omit.d.mts +1 -1
- package/dist/compat/object/omit.d.ts +1 -1
- package/dist/compat/object/pick.d.mts +1 -1
- package/dist/compat/object/pick.d.ts +1 -1
- package/dist/compat/object/toDefaulted.d.mts +122 -0
- package/dist/compat/object/toDefaulted.d.ts +122 -0
- package/dist/compat/object/toDefaulted.mjs +9 -0
- package/dist/compat/predicate/isArrayBuffer.d.mts +20 -0
- package/dist/compat/predicate/isArrayBuffer.d.ts +20 -0
- package/dist/compat/predicate/isArrayBuffer.mjs +7 -0
- package/dist/compat/predicate/isDate.d.mts +16 -0
- package/dist/compat/predicate/isDate.d.ts +16 -0
- package/dist/compat/predicate/isDate.mjs +7 -0
- package/dist/compat/predicate/isEqualWith.d.mts +38 -0
- package/dist/compat/predicate/isEqualWith.d.ts +38 -0
- package/dist/compat/predicate/isEqualWith.mjs +23 -0
- package/dist/compat/predicate/isMap.d.mts +20 -0
- package/dist/compat/predicate/isMap.d.ts +20 -0
- package/dist/compat/predicate/isMap.mjs +7 -0
- package/dist/compat/predicate/isMatch.mjs +2 -1
- package/dist/compat/predicate/isSet.d.mts +20 -0
- package/dist/compat/predicate/isSet.d.ts +20 -0
- package/dist/compat/predicate/isSet.mjs +7 -0
- package/dist/compat/string/upperCase.mjs +0 -1
- package/dist/compat/util/constant.d.mts +16 -0
- package/dist/compat/util/constant.d.ts +16 -0
- package/dist/compat/util/constant.mjs +5 -0
- package/dist/compat/util/defaultTo.d.mts +17 -0
- package/dist/compat/util/defaultTo.d.ts +17 -0
- package/dist/compat/util/defaultTo.mjs +8 -0
- package/dist/compat/util/eq.d.mts +16 -0
- package/dist/compat/util/eq.d.ts +16 -0
- package/dist/compat/util/eq.mjs +5 -0
- package/dist/compat/util/times.d.mts +14 -0
- package/dist/compat/util/times.d.ts +14 -0
- package/dist/compat/util/times.mjs +15 -0
- package/dist/compat/util/toLength.d.mts +18 -0
- package/dist/compat/util/toLength.d.ts +18 -0
- package/dist/compat/util/toLength.mjs +12 -0
- package/dist/function/before.d.mts +2 -2
- package/dist/function/before.d.ts +2 -2
- package/dist/function/before.mjs +2 -2
- package/dist/function/index.d.mts +10 -10
- package/dist/function/index.d.ts +10 -10
- package/dist/function/index.js +65 -32
- package/dist/function/index.mjs +10 -10
- package/dist/function/once.d.mts +16 -1
- package/dist/function/once.d.ts +16 -1
- package/dist/function/once.mjs +5 -7
- package/dist/index.d.mts +43 -41
- package/dist/index.d.ts +43 -41
- package/dist/index.js +59 -57
- package/dist/index.mjs +43 -41
- package/dist/math/index.d.mts +2 -1
- package/dist/math/index.d.ts +2 -1
- package/dist/math/index.js +9 -8
- package/dist/math/index.mjs +2 -1
- package/dist/math/rangeRight.d.mts +38 -0
- package/dist/math/rangeRight.d.ts +38 -0
- package/dist/math/rangeRight.mjs +20 -0
- package/dist/object/index.d.mts +7 -7
- package/dist/object/index.d.ts +7 -7
- package/dist/object/index.js +32 -32
- package/dist/object/index.mjs +7 -7
- package/dist/object/omitBy.d.mts +1 -1
- package/dist/object/omitBy.d.ts +1 -1
- package/dist/object/omitBy.mjs +4 -3
- package/dist/object/pickBy.mjs +4 -3
- package/dist/predicate/index.d.mts +11 -10
- package/dist/predicate/index.d.ts +11 -10
- package/dist/predicate/index.js +8 -7
- package/dist/predicate/index.mjs +11 -10
- package/dist/predicate/isBlob.d.mts +19 -0
- package/dist/predicate/isBlob.d.ts +19 -0
- package/dist/predicate/isBlob.mjs +8 -0
- package/dist/predicate/isEqualWith.mjs +2 -1
- package/dist/promise/index.d.mts +1 -1
- package/dist/promise/index.d.ts +1 -1
- package/dist/promise/index.mjs +1 -1
- package/dist/string/index.d.mts +12 -12
- package/dist/string/index.d.ts +12 -12
- package/dist/string/index.js +20 -20
- package/dist/string/index.mjs +12 -12
- package/package.json +10 -6
- package/dist/_chunk/{pad-BWiShN.js → upperFirst-BUECmK.js} +84 -84
package/dist/compat/index.mjs
CHANGED
|
@@ -4,7 +4,6 @@ export { countBy } from '../array/countBy.mjs';
|
|
|
4
4
|
export { differenceBy } from '../array/differenceBy.mjs';
|
|
5
5
|
export { differenceWith } from '../array/differenceWith.mjs';
|
|
6
6
|
export { dropRight } from '../array/dropRight.mjs';
|
|
7
|
-
export { dropRightWhile } from '../array/dropRightWhile.mjs';
|
|
8
7
|
export { flatMap } from '../array/flatMap.mjs';
|
|
9
8
|
export { flatMapDeep } from '../array/flatMapDeep.mjs';
|
|
10
9
|
export { forEachRight } from '../array/forEachRight.mjs';
|
|
@@ -25,7 +24,6 @@ export { sample } from '../array/sample.mjs';
|
|
|
25
24
|
export { sampleSize } from '../array/sampleSize.mjs';
|
|
26
25
|
export { shuffle } from '../array/shuffle.mjs';
|
|
27
26
|
export { tail } from '../array/tail.mjs';
|
|
28
|
-
export { take } from '../array/take.mjs';
|
|
29
27
|
export { takeRight } from '../array/takeRight.mjs';
|
|
30
28
|
export { takeRightWhile } from '../array/takeRightWhile.mjs';
|
|
31
29
|
export { takeWhile } from '../array/takeWhile.mjs';
|
|
@@ -47,64 +45,62 @@ export { zipObject } from '../array/zipObject.mjs';
|
|
|
47
45
|
export { zipWith } from '../array/zipWith.mjs';
|
|
48
46
|
export { AbortError } from '../error/AbortError.mjs';
|
|
49
47
|
export { TimeoutError } from '../error/TimeoutError.mjs';
|
|
50
|
-
export { before } from '../function/before.mjs';
|
|
51
48
|
export { after } from '../function/after.mjs';
|
|
49
|
+
export { memoize } from '../function/memoize.mjs';
|
|
50
|
+
export { negate } from '../function/negate.mjs';
|
|
52
51
|
export { noop } from '../function/noop.mjs';
|
|
53
52
|
export { once } from '../function/once.mjs';
|
|
54
|
-
export { negate } from '../function/negate.mjs';
|
|
55
|
-
export { memoize } from '../function/memoize.mjs';
|
|
56
|
-
export { unary } from '../function/unary.mjs';
|
|
57
53
|
export { partial } from '../function/partial.mjs';
|
|
58
54
|
export { partialRight } from '../function/partialRight.mjs';
|
|
59
|
-
export {
|
|
55
|
+
export { unary } from '../function/unary.mjs';
|
|
60
56
|
export { mean } from '../math/mean.mjs';
|
|
61
57
|
export { meanBy } from '../math/meanBy.mjs';
|
|
62
58
|
export { randomInt } from '../math/randomInt.mjs';
|
|
59
|
+
export { range } from '../math/range.mjs';
|
|
60
|
+
export { rangeRight } from '../math/rangeRight.mjs';
|
|
63
61
|
export { sum } from '../math/sum.mjs';
|
|
64
62
|
export { sumBy } from '../math/sumBy.mjs';
|
|
65
|
-
export { range } from '../math/range.mjs';
|
|
66
|
-
export { omitBy } from '../object/omitBy.mjs';
|
|
67
|
-
export { pickBy } from '../object/pickBy.mjs';
|
|
68
|
-
export { invert } from '../object/invert.mjs';
|
|
69
63
|
export { clone } from '../object/clone.mjs';
|
|
70
|
-
export { flattenObject } from '../object/flattenObject.mjs';
|
|
71
64
|
export { isPrimitive } from '../predicate/isPrimitive.mjs';
|
|
72
|
-
export {
|
|
65
|
+
export { flattenObject } from '../object/flattenObject.mjs';
|
|
66
|
+
export { invert } from '../object/invert.mjs';
|
|
73
67
|
export { isObjectLike } from './predicate/isObjectLike.mjs';
|
|
74
|
-
export {
|
|
75
|
-
export {
|
|
68
|
+
export { omitBy } from '../object/omitBy.mjs';
|
|
69
|
+
export { pickBy } from '../object/pickBy.mjs';
|
|
70
|
+
export { toMerged } from '../object/toMerged.mjs';
|
|
71
|
+
export { isBlob } from '../predicate/isBlob.mjs';
|
|
76
72
|
export { isEqual } from '../predicate/isEqual.mjs';
|
|
77
|
-
export {
|
|
78
|
-
export { isMap } from '../predicate/isMap.mjs';
|
|
79
|
-
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
80
|
-
export { isNull } from '../predicate/isNull.mjs';
|
|
81
|
-
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
82
|
-
export { isLength } from '../predicate/isLength.mjs';
|
|
73
|
+
export { eq } from './util/eq.mjs';
|
|
83
74
|
export { isFunction } from '../predicate/isFunction.mjs';
|
|
75
|
+
export { isJSONArray } from '../predicate/isJSONArray.mjs';
|
|
84
76
|
export { isJSONObject } from '../predicate/isJSONObject.mjs';
|
|
85
77
|
export { isJSONValue } from '../predicate/isJSONValue.mjs';
|
|
86
|
-
export {
|
|
87
|
-
export {
|
|
78
|
+
export { isLength } from '../predicate/isLength.mjs';
|
|
79
|
+
export { isNotNil } from '../predicate/isNotNil.mjs';
|
|
80
|
+
export { isNull } from '../predicate/isNull.mjs';
|
|
81
|
+
export { isUndefined } from '../predicate/isUndefined.mjs';
|
|
88
82
|
export { delay } from '../promise/delay.mjs';
|
|
89
|
-
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
90
83
|
export { timeout } from '../promise/timeout.mjs';
|
|
84
|
+
export { withTimeout } from '../promise/withTimeout.mjs';
|
|
91
85
|
export { capitalize } from '../string/capitalize.mjs';
|
|
92
|
-
export { pascalCase } from '../string/pascalCase.mjs';
|
|
93
86
|
export { constantCase } from '../string/constantCase.mjs';
|
|
94
|
-
export { upperFirst } from '../string/upperFirst.mjs';
|
|
95
|
-
export { lowerFirst } from '../string/lowerFirst.mjs';
|
|
96
87
|
export { deburr } from '../string/deburr.mjs';
|
|
97
88
|
export { escape } from '../string/escape.mjs';
|
|
98
89
|
export { escapeRegExp } from '../string/escapeRegExp.mjs';
|
|
90
|
+
export { lowerFirst } from '../string/lowerFirst.mjs';
|
|
91
|
+
export { pascalCase } from '../string/pascalCase.mjs';
|
|
99
92
|
export { unescape } from '../string/unescape.mjs';
|
|
93
|
+
export { upperFirst } from '../string/upperFirst.mjs';
|
|
100
94
|
export { castArray } from './array/castArray.mjs';
|
|
101
95
|
export { chunk } from './array/chunk.mjs';
|
|
102
96
|
export { concat } from './array/concat.mjs';
|
|
103
97
|
export { difference } from './array/difference.mjs';
|
|
104
98
|
export { drop } from './array/drop.mjs';
|
|
99
|
+
export { dropRightWhile } from './array/dropRightWhile.mjs';
|
|
105
100
|
export { dropWhile } from './array/dropWhile.mjs';
|
|
106
101
|
export { every } from './array/every.mjs';
|
|
107
102
|
export { fill } from './array/fill.mjs';
|
|
103
|
+
export { filter } from './array/filter.mjs';
|
|
108
104
|
export { find } from './array/find.mjs';
|
|
109
105
|
export { findIndex } from './array/findIndex.mjs';
|
|
110
106
|
export { findLastIndex } from './array/findLastIndex.mjs';
|
|
@@ -115,89 +111,104 @@ export { includes } from './array/includes.mjs';
|
|
|
115
111
|
export { indexOf } from './array/indexOf.mjs';
|
|
116
112
|
export { join } from './array/join.mjs';
|
|
117
113
|
export { orderBy } from './array/orderBy.mjs';
|
|
118
|
-
export { sortBy } from './array/sortBy.mjs';
|
|
119
114
|
export { size } from './array/size.mjs';
|
|
115
|
+
export { slice } from './array/slice.mjs';
|
|
120
116
|
export { some } from './array/some.mjs';
|
|
117
|
+
export { sortBy } from './array/sortBy.mjs';
|
|
118
|
+
export { take } from './array/take.mjs';
|
|
121
119
|
export { zipObjectDeep } from './array/zipObjectDeep.mjs';
|
|
122
|
-
export { filter } from './array/filter.mjs';
|
|
123
120
|
export { ary } from './function/ary.mjs';
|
|
121
|
+
export { attempt } from './function/attempt.mjs';
|
|
122
|
+
export { before } from './function/before.mjs';
|
|
124
123
|
export { bind } from './function/bind.mjs';
|
|
125
124
|
export { bindKey } from './function/bindKey.mjs';
|
|
126
|
-
export { defer } from './function/defer.mjs';
|
|
127
|
-
export { rest } from './function/rest.mjs';
|
|
128
|
-
export { spread } from './function/spread.mjs';
|
|
129
|
-
export { attempt } from './function/attempt.mjs';
|
|
130
|
-
export { rearg } from './function/rearg.mjs';
|
|
131
125
|
export { curry } from './function/curry.mjs';
|
|
126
|
+
export { curryRight } from './function/curryRight.mjs';
|
|
132
127
|
export { debounce } from './function/debounce.mjs';
|
|
133
|
-
export {
|
|
128
|
+
export { defer } from './function/defer.mjs';
|
|
134
129
|
export { flip } from './function/flip.mjs';
|
|
135
130
|
export { flow } from './function/flow.mjs';
|
|
136
131
|
export { flowRight } from './function/flowRight.mjs';
|
|
132
|
+
export { rearg } from './function/rearg.mjs';
|
|
133
|
+
export { rest } from './function/rest.mjs';
|
|
134
|
+
export { spread } from './function/spread.mjs';
|
|
135
|
+
export { throttle } from './function/throttle.mjs';
|
|
136
|
+
export { ceil } from './math/ceil.mjs';
|
|
137
|
+
export { clamp } from './math/clamp.mjs';
|
|
138
|
+
export { floor } from './math/floor.mjs';
|
|
139
|
+
export { inRange } from './math/inRange.mjs';
|
|
140
|
+
export { max } from './math/max.mjs';
|
|
141
|
+
export { min } from './math/min.mjs';
|
|
142
|
+
export { parseInt } from './math/parseInt.mjs';
|
|
143
|
+
export { random } from './math/random.mjs';
|
|
144
|
+
export { round } from './math/round.mjs';
|
|
145
|
+
export { cloneDeep } from './object/cloneDeep.mjs';
|
|
146
|
+
export { defaults } from './object/defaults.mjs';
|
|
147
|
+
export { fromPairs } from './object/fromPairs.mjs';
|
|
137
148
|
export { get } from './object/get.mjs';
|
|
138
|
-
export { set } from './object/set.mjs';
|
|
139
|
-
export { pick } from './object/pick.mjs';
|
|
140
|
-
export { omit } from './object/omit.mjs';
|
|
141
149
|
export { has } from './object/has.mjs';
|
|
142
|
-
export {
|
|
150
|
+
export { invertBy } from './object/invertBy.mjs';
|
|
143
151
|
export { mapKeys } from './object/mapKeys.mjs';
|
|
144
152
|
export { mapValues } from './object/mapValues.mjs';
|
|
145
153
|
export { merge } from './object/merge.mjs';
|
|
146
154
|
export { mergeWith } from './object/mergeWith.mjs';
|
|
147
|
-
export {
|
|
155
|
+
export { omit } from './object/omit.mjs';
|
|
156
|
+
export { pick } from './object/pick.mjs';
|
|
157
|
+
export { property } from './object/property.mjs';
|
|
158
|
+
export { set } from './object/set.mjs';
|
|
159
|
+
export { toDefaulted } from './object/toDefaulted.mjs';
|
|
148
160
|
export { unset } from './object/unset.mjs';
|
|
149
|
-
export {
|
|
150
|
-
export {
|
|
151
|
-
export { isArray } from './predicate/isArray.mjs';
|
|
161
|
+
export { conforms } from './predicate/conforms.mjs';
|
|
162
|
+
export { conformsTo } from './predicate/conformsTo.mjs';
|
|
152
163
|
export { isArguments } from './predicate/isArguments.mjs';
|
|
164
|
+
export { isArray } from './predicate/isArray.mjs';
|
|
165
|
+
export { isArrayBuffer } from './predicate/isArrayBuffer.mjs';
|
|
153
166
|
export { isArrayLike } from './predicate/isArrayLike.mjs';
|
|
154
|
-
export {
|
|
155
|
-
export { isObject } from './predicate/isObject.mjs';
|
|
167
|
+
export { isArrayLikeObject } from './predicate/isArrayLikeObject.mjs';
|
|
156
168
|
export { isBoolean } from './predicate/isBoolean.mjs';
|
|
169
|
+
export { isDate } from './predicate/isDate.mjs';
|
|
170
|
+
export { isEqualWith } from './predicate/isEqualWith.mjs';
|
|
157
171
|
export { isError } from './predicate/isError.mjs';
|
|
158
172
|
export { isFinite } from './predicate/isFinite.mjs';
|
|
159
|
-
export {
|
|
173
|
+
export { isInteger } from './predicate/isInteger.mjs';
|
|
174
|
+
export { isMap } from './predicate/isMap.mjs';
|
|
160
175
|
export { isMatch } from './predicate/isMatch.mjs';
|
|
176
|
+
export { isNaN } from './predicate/isNaN.mjs';
|
|
177
|
+
export { isNil } from './predicate/isNil.mjs';
|
|
178
|
+
export { isNumber } from './predicate/isNumber.mjs';
|
|
179
|
+
export { isObject } from './predicate/isObject.mjs';
|
|
180
|
+
export { isPlainObject } from './predicate/isPlainObject.mjs';
|
|
161
181
|
export { isRegExp } from './predicate/isRegExp.mjs';
|
|
182
|
+
export { isSafeInteger } from './predicate/isSafeInteger.mjs';
|
|
183
|
+
export { isSet } from './predicate/isSet.mjs';
|
|
162
184
|
export { isString } from './predicate/isString.mjs';
|
|
163
|
-
export {
|
|
164
|
-
export {
|
|
185
|
+
export { isSymbol } from './predicate/isSymbol.mjs';
|
|
186
|
+
export { isTypedArray } from './predicate/isTypedArray.mjs';
|
|
165
187
|
export { isWeakMap } from './predicate/isWeakMap.mjs';
|
|
166
188
|
export { isWeakSet } from './predicate/isWeakSet.mjs';
|
|
167
|
-
export {
|
|
168
|
-
export {
|
|
169
|
-
export { isInteger } from './predicate/isInteger.mjs';
|
|
170
|
-
export { isSafeInteger } from './predicate/isSafeInteger.mjs';
|
|
171
|
-
export { isNumber } from './predicate/isNumber.mjs';
|
|
172
|
-
export { isNaN } from './predicate/isNaN.mjs';
|
|
173
|
-
export { isArrayLikeObject } from './predicate/isArrayLikeObject.mjs';
|
|
174
|
-
export { isNil } from './predicate/isNil.mjs';
|
|
189
|
+
export { matches } from './predicate/matches.mjs';
|
|
190
|
+
export { matchesProperty } from './predicate/matchesProperty.mjs';
|
|
175
191
|
export { camelCase } from './string/camelCase.mjs';
|
|
192
|
+
export { endsWith } from './string/endsWith.mjs';
|
|
176
193
|
export { kebabCase } from './string/kebabCase.mjs';
|
|
177
|
-
export { snakeCase } from './string/snakeCase.mjs';
|
|
178
|
-
export { startCase } from './string/startCase.mjs';
|
|
179
194
|
export { lowerCase } from './string/lowerCase.mjs';
|
|
180
|
-
export { upperCase } from './string/upperCase.mjs';
|
|
181
|
-
export { startsWith } from './string/startsWith.mjs';
|
|
182
|
-
export { endsWith } from './string/endsWith.mjs';
|
|
183
195
|
export { pad } from './string/pad.mjs';
|
|
184
|
-
export { padStart } from './string/padStart.mjs';
|
|
185
196
|
export { padEnd } from './string/padEnd.mjs';
|
|
197
|
+
export { padStart } from './string/padStart.mjs';
|
|
186
198
|
export { repeat } from './string/repeat.mjs';
|
|
199
|
+
export { snakeCase } from './string/snakeCase.mjs';
|
|
200
|
+
export { startCase } from './string/startCase.mjs';
|
|
201
|
+
export { startsWith } from './string/startsWith.mjs';
|
|
202
|
+
export { upperCase } from './string/upperCase.mjs';
|
|
187
203
|
export { trim } from './string/trim.mjs';
|
|
188
|
-
export { trimStart } from './string/trimStart.mjs';
|
|
189
204
|
export { trimEnd } from './string/trimEnd.mjs';
|
|
190
|
-
export {
|
|
191
|
-
export {
|
|
192
|
-
export {
|
|
193
|
-
export {
|
|
194
|
-
export {
|
|
195
|
-
export {
|
|
196
|
-
export {
|
|
197
|
-
export {
|
|
198
|
-
export { random } from './math/random.mjs';
|
|
205
|
+
export { trimStart } from './string/trimStart.mjs';
|
|
206
|
+
export { constant } from './util/constant.mjs';
|
|
207
|
+
export { defaultTo } from './util/defaultTo.mjs';
|
|
208
|
+
export { times } from './util/times.mjs';
|
|
209
|
+
export { toFinite } from './util/toFinite.mjs';
|
|
210
|
+
export { toInteger } from './util/toInteger.mjs';
|
|
211
|
+
export { toLength } from './util/toLength.mjs';
|
|
212
|
+
export { toNumber } from './util/toNumber.mjs';
|
|
199
213
|
export { toPath } from './util/toPath.mjs';
|
|
200
214
|
export { toString } from './util/toString.mjs';
|
|
201
|
-
export { toNumber } from './util/toNumber.mjs';
|
|
202
|
-
export { toInteger } from './util/toInteger.mjs';
|
|
203
|
-
export { toFinite } from './util/toFinite.mjs';
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
3
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
4
|
+
*
|
|
5
|
+
* You can pass in multiple objects to define these default values,
|
|
6
|
+
* and they will be applied in order from left to right.
|
|
7
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
8
|
+
*
|
|
9
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the object being processed.
|
|
12
|
+
* @param {T} object - The target object.
|
|
13
|
+
* @returns {T} The object itself.
|
|
14
|
+
*/
|
|
15
|
+
declare function defaults<T extends object>(object: T): NonNullable<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
18
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
19
|
+
*
|
|
20
|
+
* You can pass in multiple objects to define these default values,
|
|
21
|
+
* and they will be applied in order from left to right.
|
|
22
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
23
|
+
*
|
|
24
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of the object being processed.
|
|
27
|
+
* @template S - The type of the object that provides default values.
|
|
28
|
+
* @param {T} object - The target object that will receive default values.
|
|
29
|
+
* @param {S} source - The object that specifies the default values to apply.
|
|
30
|
+
* @returns {NonNullable<T & S>} The `object` that has been updated with default values from `source`, ensuring that all properties are defined and none are left as `undefined`.
|
|
31
|
+
*/
|
|
32
|
+
declare function defaults<T extends object, S extends object>(object: T, source: S): NonNullable<T & S>;
|
|
33
|
+
/**
|
|
34
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
35
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
36
|
+
*
|
|
37
|
+
* You can pass in multiple objects to define these default values,
|
|
38
|
+
* and they will be applied in order from left to right.
|
|
39
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
40
|
+
*
|
|
41
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
42
|
+
*
|
|
43
|
+
* @template T - The type of the object being processed.
|
|
44
|
+
* @template S1 - The type of the first object that provides default values.
|
|
45
|
+
* @template S2 - The type of the second object that provides default values.
|
|
46
|
+
* @param {T} object - The target object that will receive default values.
|
|
47
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
48
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
49
|
+
* @returns {NonNullable<T & S1 & S2>} The `object` that has been updated with default values from `source1` and `source2`, ensuring that all properties are defined and none are left as `undefined`.
|
|
50
|
+
*/
|
|
51
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object>(object: T, source1: S1, source2: S2): NonNullable<T & S1 & S2>;
|
|
52
|
+
/**
|
|
53
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
54
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
55
|
+
*
|
|
56
|
+
* You can pass in multiple objects to define these default values,
|
|
57
|
+
* and they will be applied in order from left to right.
|
|
58
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
59
|
+
*
|
|
60
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
61
|
+
*
|
|
62
|
+
* @template T - The type of the object being processed.
|
|
63
|
+
* @template S1 - The type of the first object that provides default values.
|
|
64
|
+
* @template S2 - The type of the second object that provides default values.
|
|
65
|
+
* @template S3 - The type of the third object that provides default values.
|
|
66
|
+
* @param {T} object - The target object that will receive default values.
|
|
67
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
68
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
69
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
70
|
+
* @returns {NonNullable<T & S1 & S2 & S3>} The `object` that has been updated with default values from `source1`, `source2`, and `source3`, ensuring that all properties are defined and none are left as `undefined`.
|
|
71
|
+
*/
|
|
72
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object, S3 extends object>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<T & S1 & S2 & S3>;
|
|
73
|
+
/**
|
|
74
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
75
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
76
|
+
*
|
|
77
|
+
* You can pass in multiple objects to define these default values,
|
|
78
|
+
* and they will be applied in order from left to right.
|
|
79
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
80
|
+
*
|
|
81
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
82
|
+
*
|
|
83
|
+
* @template T - The type of the object being processed.
|
|
84
|
+
* @template S1 - The type of the first object that provides default values.
|
|
85
|
+
* @template S2 - The type of the second object that provides default values.
|
|
86
|
+
* @template S3 - The type of the third object that provides default values.
|
|
87
|
+
* @template S4 - The type of the fourth object that provides default values.
|
|
88
|
+
* @param {T} object - The target object that will receive default values.
|
|
89
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
90
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
91
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
92
|
+
* @param {S4} source4 - The fourth object that specifies the default values to apply.
|
|
93
|
+
* @returns {NonNullable<T & S1 & S2 & S3 & S4>} The `object` that has been updated with default values from `source1`, `source2`, `source3`, and `source4`, ensuring that all properties are defined and none are left as `undefined`.
|
|
94
|
+
*/
|
|
95
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object, S3 extends object, S4 extends object>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<T & S1 & S2 & S3 & S4>;
|
|
96
|
+
/**
|
|
97
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
98
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
99
|
+
*
|
|
100
|
+
* You can pass in multiple objects to define these default values,
|
|
101
|
+
* and they will be applied in order from left to right.
|
|
102
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
103
|
+
*
|
|
104
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
105
|
+
*
|
|
106
|
+
* @template T - The type of the object being processed.
|
|
107
|
+
* @template S - The type of the objects that provides default values.
|
|
108
|
+
* @param {T} object - The target object that will receive default values.
|
|
109
|
+
* @param {S[]} source - The objects that specifies the default values to apply.
|
|
110
|
+
* @returns {object} The `object` that has been updated with default values from `sources`, ensuring that all properties are defined and none are left as `undefined`.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* defaults({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
114
|
+
* defaults({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
115
|
+
* defaults({ a: null }, { a: 1 }); // { a: null }
|
|
116
|
+
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
|
|
117
|
+
*/
|
|
118
|
+
declare function defaults<T extends object, S extends object>(object: T, ...sources: S[]): object;
|
|
119
|
+
|
|
120
|
+
export { defaults };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
3
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
4
|
+
*
|
|
5
|
+
* You can pass in multiple objects to define these default values,
|
|
6
|
+
* and they will be applied in order from left to right.
|
|
7
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
8
|
+
*
|
|
9
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
10
|
+
*
|
|
11
|
+
* @template T - The type of the object being processed.
|
|
12
|
+
* @param {T} object - The target object.
|
|
13
|
+
* @returns {T} The object itself.
|
|
14
|
+
*/
|
|
15
|
+
declare function defaults<T extends object>(object: T): NonNullable<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
18
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
19
|
+
*
|
|
20
|
+
* You can pass in multiple objects to define these default values,
|
|
21
|
+
* and they will be applied in order from left to right.
|
|
22
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
23
|
+
*
|
|
24
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
25
|
+
*
|
|
26
|
+
* @template T - The type of the object being processed.
|
|
27
|
+
* @template S - The type of the object that provides default values.
|
|
28
|
+
* @param {T} object - The target object that will receive default values.
|
|
29
|
+
* @param {S} source - The object that specifies the default values to apply.
|
|
30
|
+
* @returns {NonNullable<T & S>} The `object` that has been updated with default values from `source`, ensuring that all properties are defined and none are left as `undefined`.
|
|
31
|
+
*/
|
|
32
|
+
declare function defaults<T extends object, S extends object>(object: T, source: S): NonNullable<T & S>;
|
|
33
|
+
/**
|
|
34
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
35
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
36
|
+
*
|
|
37
|
+
* You can pass in multiple objects to define these default values,
|
|
38
|
+
* and they will be applied in order from left to right.
|
|
39
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
40
|
+
*
|
|
41
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
42
|
+
*
|
|
43
|
+
* @template T - The type of the object being processed.
|
|
44
|
+
* @template S1 - The type of the first object that provides default values.
|
|
45
|
+
* @template S2 - The type of the second object that provides default values.
|
|
46
|
+
* @param {T} object - The target object that will receive default values.
|
|
47
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
48
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
49
|
+
* @returns {NonNullable<T & S1 & S2>} The `object` that has been updated with default values from `source1` and `source2`, ensuring that all properties are defined and none are left as `undefined`.
|
|
50
|
+
*/
|
|
51
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object>(object: T, source1: S1, source2: S2): NonNullable<T & S1 & S2>;
|
|
52
|
+
/**
|
|
53
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
54
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
55
|
+
*
|
|
56
|
+
* You can pass in multiple objects to define these default values,
|
|
57
|
+
* and they will be applied in order from left to right.
|
|
58
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
59
|
+
*
|
|
60
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
61
|
+
*
|
|
62
|
+
* @template T - The type of the object being processed.
|
|
63
|
+
* @template S1 - The type of the first object that provides default values.
|
|
64
|
+
* @template S2 - The type of the second object that provides default values.
|
|
65
|
+
* @template S3 - The type of the third object that provides default values.
|
|
66
|
+
* @param {T} object - The target object that will receive default values.
|
|
67
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
68
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
69
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
70
|
+
* @returns {NonNullable<T & S1 & S2 & S3>} The `object` that has been updated with default values from `source1`, `source2`, and `source3`, ensuring that all properties are defined and none are left as `undefined`.
|
|
71
|
+
*/
|
|
72
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object, S3 extends object>(object: T, source1: S1, source2: S2, source3: S3): NonNullable<T & S1 & S2 & S3>;
|
|
73
|
+
/**
|
|
74
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
75
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
76
|
+
*
|
|
77
|
+
* You can pass in multiple objects to define these default values,
|
|
78
|
+
* and they will be applied in order from left to right.
|
|
79
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
80
|
+
*
|
|
81
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
82
|
+
*
|
|
83
|
+
* @template T - The type of the object being processed.
|
|
84
|
+
* @template S1 - The type of the first object that provides default values.
|
|
85
|
+
* @template S2 - The type of the second object that provides default values.
|
|
86
|
+
* @template S3 - The type of the third object that provides default values.
|
|
87
|
+
* @template S4 - The type of the fourth object that provides default values.
|
|
88
|
+
* @param {T} object - The target object that will receive default values.
|
|
89
|
+
* @param {S1} source1 - The first object that specifies the default values to apply.
|
|
90
|
+
* @param {S2} source2 - The second object that specifies the default values to apply.
|
|
91
|
+
* @param {S3} source3 - The third object that specifies the default values to apply.
|
|
92
|
+
* @param {S4} source4 - The fourth object that specifies the default values to apply.
|
|
93
|
+
* @returns {NonNullable<T & S1 & S2 & S3 & S4>} The `object` that has been updated with default values from `source1`, `source2`, `source3`, and `source4`, ensuring that all properties are defined and none are left as `undefined`.
|
|
94
|
+
*/
|
|
95
|
+
declare function defaults<T extends object, S1 extends object, S2 extends object, S3 extends object, S4 extends object>(object: T, source1: S1, source2: S2, source3: S3, source4: S4): NonNullable<T & S1 & S2 & S3 & S4>;
|
|
96
|
+
/**
|
|
97
|
+
* Assigns default values to an `object`, ensuring that certain properties do not remain `undefined`.
|
|
98
|
+
* It sets default values for properties that are either `undefined` or inherited from `Object.prototype`.
|
|
99
|
+
*
|
|
100
|
+
* You can pass in multiple objects to define these default values,
|
|
101
|
+
* and they will be applied in order from left to right.
|
|
102
|
+
* Once a property has been assigned a value, any subsequent values for that property will be ignored.
|
|
103
|
+
*
|
|
104
|
+
* Note: This function modifies the first argument, `object`. If you want to keep `object` unchanged, consider using `toDefaulted` instead.
|
|
105
|
+
*
|
|
106
|
+
* @template T - The type of the object being processed.
|
|
107
|
+
* @template S - The type of the objects that provides default values.
|
|
108
|
+
* @param {T} object - The target object that will receive default values.
|
|
109
|
+
* @param {S[]} source - The objects that specifies the default values to apply.
|
|
110
|
+
* @returns {object} The `object` that has been updated with default values from `sources`, ensuring that all properties are defined and none are left as `undefined`.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* defaults({ a: 1 }, { a: 2, b: 2 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
114
|
+
* defaults({ a: 1, b: 2 }, { b: 3 }, { c: 3 }); // { a: 1, b: 2, c: 3 }
|
|
115
|
+
* defaults({ a: null }, { a: 1 }); // { a: null }
|
|
116
|
+
* defaults({ a: undefined }, { a: 1 }); // { a: 1 }
|
|
117
|
+
*/
|
|
118
|
+
declare function defaults<T extends object, S extends object>(object: T, ...sources: S[]): object;
|
|
119
|
+
|
|
120
|
+
export { defaults };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { eq } from '../util/eq.mjs';
|
|
2
|
+
|
|
3
|
+
function defaults(object, ...sources) {
|
|
4
|
+
object = Object(object);
|
|
5
|
+
const objectProto = Object.prototype;
|
|
6
|
+
for (let i = 0; i < sources.length; i++) {
|
|
7
|
+
const source = sources[i];
|
|
8
|
+
const keys = Object.keys(source);
|
|
9
|
+
for (let j = 0; j < keys.length; j++) {
|
|
10
|
+
const key = keys[j];
|
|
11
|
+
const value = object[key];
|
|
12
|
+
if (value === undefined ||
|
|
13
|
+
(!Object.hasOwn(object, key) && eq(value, objectProto[key]))) {
|
|
14
|
+
object[key] = source[key];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return object;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { defaults };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object that reverses the keys and values of the given object, similar to the invert.
|
|
3
|
+
*
|
|
4
|
+
* The `iteratee` function specifies how the values are reversed into keys. If no `iteratee` function is provided, the values are used as keys as-is.
|
|
5
|
+
*
|
|
6
|
+
* The values of the new object are arrays of keys that correspond to the value returned by the `iteratee` function.
|
|
7
|
+
*
|
|
8
|
+
* @param {Record<K, V>} object - The object to iterate over.
|
|
9
|
+
* @param {(value: V) => string} [iteratee] - Optional. A function that generates a key based on each value in the object.
|
|
10
|
+
* If not provided, the function defaults to using the value as a string.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Record<string, K[]>} An object where the keys are generated by the iteratee, and the values
|
|
13
|
+
* are arrays of property names (keys) from the input object that correspond to those keys.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const obj = { a: 1, b: 2, c: 1 };
|
|
17
|
+
* const result = invertBy(obj);
|
|
18
|
+
* // result => { '1': ['a', 'c'], '2': ['b'] }
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const obj = { a: 1, b: 2, c: 1 };
|
|
22
|
+
* const result = invertBy(obj, value => `group${value}`);
|
|
23
|
+
* // result => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
|
24
|
+
*/
|
|
25
|
+
declare function invertBy<K extends PropertyKey, V>(object: Record<K, V>, iteratee?: (value: V) => string): Record<string, K[]>;
|
|
26
|
+
|
|
27
|
+
export { invertBy };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new object that reverses the keys and values of the given object, similar to the invert.
|
|
3
|
+
*
|
|
4
|
+
* The `iteratee` function specifies how the values are reversed into keys. If no `iteratee` function is provided, the values are used as keys as-is.
|
|
5
|
+
*
|
|
6
|
+
* The values of the new object are arrays of keys that correspond to the value returned by the `iteratee` function.
|
|
7
|
+
*
|
|
8
|
+
* @param {Record<K, V>} object - The object to iterate over.
|
|
9
|
+
* @param {(value: V) => string} [iteratee] - Optional. A function that generates a key based on each value in the object.
|
|
10
|
+
* If not provided, the function defaults to using the value as a string.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Record<string, K[]>} An object where the keys are generated by the iteratee, and the values
|
|
13
|
+
* are arrays of property names (keys) from the input object that correspond to those keys.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const obj = { a: 1, b: 2, c: 1 };
|
|
17
|
+
* const result = invertBy(obj);
|
|
18
|
+
* // result => { '1': ['a', 'c'], '2': ['b'] }
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const obj = { a: 1, b: 2, c: 1 };
|
|
22
|
+
* const result = invertBy(obj, value => `group${value}`);
|
|
23
|
+
* // result => { 'group1': ['a', 'c'], 'group2': ['b'] }
|
|
24
|
+
*/
|
|
25
|
+
declare function invertBy<K extends PropertyKey, V>(object: Record<K, V>, iteratee?: (value: V) => string): Record<string, K[]>;
|
|
26
|
+
|
|
27
|
+
export { invertBy };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isNil } from '../../predicate/isNil.mjs';
|
|
2
|
+
import { identity } from '../_internal/identity.mjs';
|
|
3
|
+
|
|
4
|
+
function invertBy(object, iteratee) {
|
|
5
|
+
const result = {};
|
|
6
|
+
if (isNil(object)) {
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
if (iteratee == null) {
|
|
10
|
+
iteratee = identity;
|
|
11
|
+
}
|
|
12
|
+
const keys = Object.keys(object);
|
|
13
|
+
for (let i = 0; i < keys.length; i++) {
|
|
14
|
+
const key = keys[i];
|
|
15
|
+
const value = object[key];
|
|
16
|
+
const valueStr = iteratee(value);
|
|
17
|
+
if (Array.isArray(result[valueStr])) {
|
|
18
|
+
result[valueStr].push(key);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
result[valueStr] = [key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { invertBy };
|
|
@@ -26,7 +26,7 @@ declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
26
26
|
*
|
|
27
27
|
* @template T - The type of object.
|
|
28
28
|
* @param {T} obj - The object to omit keys from.
|
|
29
|
-
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][])} keys - A variable number of keys to be omitted from the object.
|
|
30
30
|
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
31
|
*/
|
|
32
32
|
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
@@ -26,7 +26,7 @@ declare function omit<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
26
26
|
*
|
|
27
27
|
* @template T - The type of object.
|
|
28
28
|
* @param {T} obj - The object to omit keys from.
|
|
29
|
-
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][]} keys - A variable number of keys to be omitted from the object.
|
|
29
|
+
* @param {...(PropertyKey | PropertyKey[] | PropertyKey[][])} keys - A variable number of keys to be omitted from the object.
|
|
30
30
|
* @returns {Partial<T>} A new object with the specified keys omitted.
|
|
31
31
|
*/
|
|
32
32
|
declare function omit<T extends {}>(obj: T | null | undefined, ...keys: Array<PropertyKey | readonly PropertyKey[] | ReadonlyArray<readonly PropertyKey[]>>): Partial<T>;
|
|
@@ -25,7 +25,7 @@ declare function pick<T extends Record<string, any>, K extends keyof T>(obj: T,
|
|
|
25
25
|
* @template T - The type of object.
|
|
26
26
|
* @param {T | null | undefined} obj - The object to pick keys from.
|
|
27
27
|
* @param {...any} keys
|
|
28
|
-
* @param {PropertyKey | PropertyKey[] |
|
|
28
|
+
* @param {PropertyKey | PropertyKey[] | PropertyKey[][]}} keys - An array of keys to be picked from the object. received keys goes through a flattening process before being used.
|
|
29
29
|
* @returns {Partial<T, K>} A new object with the specified keys picked.
|
|
30
30
|
*
|
|
31
31
|
* @example
|