es-toolkit 1.7.1-dev.153 → 1.7.1-dev.155

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.
Files changed (39) hide show
  1. package/dist/array/index.d.mts +1 -0
  2. package/dist/array/index.d.ts +1 -0
  3. package/dist/array/index.js +27 -0
  4. package/dist/array/index.js.map +1 -1
  5. package/dist/array/index.mjs +51 -47
  6. package/dist/array/orderBy.d.mts +35 -0
  7. package/dist/array/orderBy.d.ts +35 -0
  8. package/dist/array/orderBy.js +53 -0
  9. package/dist/array/orderBy.js.map +1 -0
  10. package/dist/array/orderBy.mjs +8 -0
  11. package/dist/chunk-7B7W36UP.mjs +29 -0
  12. package/dist/chunk-7B7W36UP.mjs.map +1 -0
  13. package/dist/chunk-FLTT2MGF.mjs +14 -0
  14. package/dist/chunk-FLTT2MGF.mjs.map +1 -0
  15. package/dist/chunk-OC7ZNKWX.mjs +1 -0
  16. package/dist/chunk-PMHULJNL.mjs +1 -0
  17. package/dist/chunk-PMHULJNL.mjs.map +1 -0
  18. package/dist/function/index.mjs +3 -3
  19. package/dist/index.d.mts +2 -0
  20. package/dist/index.d.ts +2 -0
  21. package/dist/index.js +39 -0
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +81 -73
  24. package/dist/object/index.d.mts +1 -0
  25. package/dist/object/index.d.ts +1 -0
  26. package/dist/object/index.js +12 -0
  27. package/dist/object/index.js.map +1 -1
  28. package/dist/object/index.mjs +11 -7
  29. package/dist/object/invert.d.mts +24 -0
  30. package/dist/object/invert.d.ts +24 -0
  31. package/dist/object/invert.js +38 -0
  32. package/dist/object/invert.js.map +1 -0
  33. package/dist/object/invert.mjs +8 -0
  34. package/dist/object/invert.mjs.map +1 -0
  35. package/package.json +1 -1
  36. package/dist/chunk-T5JCRGXA.mjs +0 -1
  37. package/dist/chunk-XJR5WV2Z.mjs +0 -1
  38. /package/dist/{chunk-T5JCRGXA.mjs.map → array/orderBy.mjs.map} +0 -0
  39. /package/dist/{chunk-XJR5WV2Z.mjs.map → chunk-OC7ZNKWX.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,3 +1,7 @@
1
+ import "./chunk-ARZ5BDR6.mjs";
2
+ import {
3
+ delay
4
+ } from "./chunk-O64NE2P4.mjs";
1
5
  import "./chunk-MAJSPFA6.mjs";
2
6
  import {
3
7
  isNil
@@ -11,23 +15,22 @@ import {
11
15
  import {
12
16
  isUndefined
13
17
  } from "./chunk-VH2PV426.mjs";
14
- import "./chunk-ARZ5BDR6.mjs";
18
+ import "./chunk-PMHULJNL.mjs";
15
19
  import {
16
- delay
17
- } from "./chunk-O64NE2P4.mjs";
18
- import "./chunk-T5JCRGXA.mjs";
20
+ omitBy
21
+ } from "./chunk-BCTYOXT7.mjs";
22
+ import {
23
+ pick
24
+ } from "./chunk-HPFDYUGP.mjs";
19
25
  import {
20
26
  pickBy
21
27
  } from "./chunk-6CLH5YZ2.mjs";
28
+ import {
29
+ invert
30
+ } from "./chunk-FLTT2MGF.mjs";
22
31
  import {
23
32
  omit
24
33
  } from "./chunk-QZITBKWX.mjs";
25
- import {
26
- omitBy
27
- } from "./chunk-BCTYOXT7.mjs";
28
- import {
29
- pick
30
- } from "./chunk-HPFDYUGP.mjs";
31
34
  import "./chunk-TLVQSNOE.mjs";
32
35
  import {
33
36
  range
@@ -50,22 +53,20 @@ import {
50
53
  import {
51
54
  sum
52
55
  } from "./chunk-NOFHNJ5C.mjs";
53
- import "./chunk-XJR5WV2Z.mjs";
54
- import {
55
- zipObject
56
- } from "./chunk-6GWEY5EL.mjs";
56
+ import "./chunk-N6EM6ETS.mjs";
57
57
  import {
58
- zipWith
59
- } from "./chunk-4KYXHZ4R.mjs";
58
+ noop
59
+ } from "./chunk-LKXCOLNY.mjs";
60
60
  import {
61
- uniqBy
62
- } from "./chunk-OXAZEEGP.mjs";
61
+ once
62
+ } from "./chunk-CMBC4MXG.mjs";
63
63
  import {
64
- unzipWith
65
- } from "./chunk-IFNXROZR.mjs";
64
+ throttle
65
+ } from "./chunk-QOJGMVVR.mjs";
66
66
  import {
67
- without
68
- } from "./chunk-PYEYV7BY.mjs";
67
+ debounce
68
+ } from "./chunk-3IP4JVLL.mjs";
69
+ import "./chunk-OC7ZNKWX.mjs";
69
70
  import {
70
71
  xor
71
72
  } from "./chunk-L7FQX5MN.mjs";
@@ -79,17 +80,11 @@ import {
79
80
  zip
80
81
  } from "./chunk-IDCUZVJL.mjs";
81
82
  import {
82
- take
83
- } from "./chunk-ME352XO7.mjs";
84
- import {
85
- takeRight
86
- } from "./chunk-IQLKIDXF.mjs";
87
- import {
88
- takeRightWhile
89
- } from "./chunk-NTLX2MPV.mjs";
83
+ zipObject
84
+ } from "./chunk-6GWEY5EL.mjs";
90
85
  import {
91
- takeWhile
92
- } from "./chunk-2IXFGSUA.mjs";
86
+ zipWith
87
+ } from "./chunk-4KYXHZ4R.mjs";
93
88
  import {
94
89
  union
95
90
  } from "./chunk-R6QA7PLZ.mjs";
@@ -99,24 +94,21 @@ import {
99
94
  import {
100
95
  unionWith
101
96
  } from "./chunk-2ZCITDMK.mjs";
102
- import {
103
- uniqWith
104
- } from "./chunk-237HGSZS.mjs";
105
97
  import {
106
98
  uniq
107
99
  } from "./chunk-DVK2N4KC.mjs";
108
100
  import {
109
- intersectionWith
110
- } from "./chunk-XI7KRD2C.mjs";
101
+ uniqBy
102
+ } from "./chunk-OXAZEEGP.mjs";
111
103
  import {
112
- keyBy
113
- } from "./chunk-AJKZMN2V.mjs";
104
+ uniqWith
105
+ } from "./chunk-237HGSZS.mjs";
114
106
  import {
115
- maxBy
116
- } from "./chunk-OOKNBU4V.mjs";
107
+ unzipWith
108
+ } from "./chunk-IFNXROZR.mjs";
117
109
  import {
118
- minBy
119
- } from "./chunk-IJD7FE2Z.mjs";
110
+ without
111
+ } from "./chunk-PYEYV7BY.mjs";
120
112
  import {
121
113
  partition
122
114
  } from "./chunk-DN3NOZ3H.mjs";
@@ -136,20 +128,17 @@ import {
136
128
  shuffle
137
129
  } from "./chunk-G7UQ5PUR.mjs";
138
130
  import {
139
- dropRightWhile
140
- } from "./chunk-JE6JKZU3.mjs";
141
- import {
142
- dropWhile
143
- } from "./chunk-LJ2C6MVP.mjs";
131
+ take
132
+ } from "./chunk-ME352XO7.mjs";
144
133
  import {
145
- fill
146
- } from "./chunk-C4WE4GLC.mjs";
134
+ takeRight
135
+ } from "./chunk-IQLKIDXF.mjs";
147
136
  import {
148
- forEachRight
149
- } from "./chunk-IEA53J7P.mjs";
137
+ takeRightWhile
138
+ } from "./chunk-NTLX2MPV.mjs";
150
139
  import {
151
- groupBy
152
- } from "./chunk-E6E4RZLN.mjs";
140
+ takeWhile
141
+ } from "./chunk-2IXFGSUA.mjs";
153
142
  import {
154
143
  intersection
155
144
  } from "./chunk-FVVSE2F2.mjs";
@@ -157,20 +146,20 @@ import {
157
146
  intersectionBy
158
147
  } from "./chunk-O6UXZR3U.mjs";
159
148
  import {
160
- chunk
161
- } from "./chunk-E6C5EZQA.mjs";
149
+ intersectionWith
150
+ } from "./chunk-XI7KRD2C.mjs";
162
151
  import {
163
- compact
164
- } from "./chunk-DTJJIMKJ.mjs";
152
+ keyBy
153
+ } from "./chunk-AJKZMN2V.mjs";
165
154
  import {
166
- countBy
167
- } from "./chunk-CRSKT4WW.mjs";
155
+ maxBy
156
+ } from "./chunk-OOKNBU4V.mjs";
168
157
  import {
169
- difference
170
- } from "./chunk-JPUKH67K.mjs";
158
+ minBy
159
+ } from "./chunk-IJD7FE2Z.mjs";
171
160
  import {
172
- differenceBy
173
- } from "./chunk-LVWX5B43.mjs";
161
+ orderBy
162
+ } from "./chunk-7B7W36UP.mjs";
174
163
  import {
175
164
  differenceWith
176
165
  } from "./chunk-6NVQAHXP.mjs";
@@ -180,23 +169,40 @@ import {
180
169
  import {
181
170
  dropRight
182
171
  } from "./chunk-JEKUA56R.mjs";
172
+ import {
173
+ dropRightWhile
174
+ } from "./chunk-JE6JKZU3.mjs";
175
+ import {
176
+ dropWhile
177
+ } from "./chunk-LJ2C6MVP.mjs";
178
+ import {
179
+ fill
180
+ } from "./chunk-C4WE4GLC.mjs";
181
+ import {
182
+ forEachRight
183
+ } from "./chunk-IEA53J7P.mjs";
184
+ import {
185
+ groupBy
186
+ } from "./chunk-E6E4RZLN.mjs";
183
187
  import "./chunk-FZEZH22H.mjs";
184
188
  import {
185
189
  AbortError
186
190
  } from "./chunk-DXB7EZUQ.mjs";
187
- import "./chunk-N6EM6ETS.mjs";
188
191
  import {
189
- debounce
190
- } from "./chunk-3IP4JVLL.mjs";
192
+ chunk
193
+ } from "./chunk-E6C5EZQA.mjs";
191
194
  import {
192
- noop
193
- } from "./chunk-LKXCOLNY.mjs";
195
+ compact
196
+ } from "./chunk-DTJJIMKJ.mjs";
194
197
  import {
195
- once
196
- } from "./chunk-CMBC4MXG.mjs";
198
+ countBy
199
+ } from "./chunk-CRSKT4WW.mjs";
197
200
  import {
198
- throttle
199
- } from "./chunk-QOJGMVVR.mjs";
201
+ difference
202
+ } from "./chunk-JPUKH67K.mjs";
203
+ import {
204
+ differenceBy
205
+ } from "./chunk-LVWX5B43.mjs";
200
206
  import "./chunk-2MM5EJJX.mjs";
201
207
  export {
202
208
  AbortError,
@@ -220,6 +226,7 @@ export {
220
226
  intersection,
221
227
  intersectionBy,
222
228
  intersectionWith,
229
+ invert,
223
230
  isNil,
224
231
  isNotNil,
225
232
  isNull,
@@ -233,6 +240,7 @@ export {
233
240
  omit,
234
241
  omitBy,
235
242
  once,
243
+ orderBy,
236
244
  partition,
237
245
  pick,
238
246
  pickBy,
@@ -2,3 +2,4 @@ export { omit } from './omit.mjs';
2
2
  export { omitBy } from './omitBy.mjs';
3
3
  export { pick } from './pick.mjs';
4
4
  export { pickBy } from './pickBy.mjs';
5
+ export { invert } from './invert.mjs';
@@ -2,3 +2,4 @@ export { omit } from './omit.js';
2
2
  export { omitBy } from './omitBy.js';
3
3
  export { pick } from './pick.js';
4
4
  export { pickBy } from './pickBy.js';
5
+ export { invert } from './invert.js';
@@ -34,6 +34,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
34
34
  // src/object/index.ts
35
35
  var object_exports = {};
36
36
  __export(object_exports, {
37
+ invert: () => invert,
37
38
  omit: () => omit,
38
39
  omitBy: () => omitBy,
39
40
  pick: () => pick,
@@ -82,8 +83,19 @@ function pickBy(obj, shouldPick) {
82
83
  }
83
84
  return result;
84
85
  }
86
+
87
+ // src/object/invert.ts
88
+ function invert(obj) {
89
+ const result = {};
90
+ for (const key in obj) {
91
+ const value = obj[key];
92
+ result[value] = key;
93
+ }
94
+ return result;
95
+ }
85
96
  // Annotate the CommonJS export names for ESM import in node:
86
97
  0 && (module.exports = {
98
+ invert,
87
99
  omit,
88
100
  omitBy,
89
101
  pick,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../../src/object/index.ts","../../src/object/omit.ts","../../src/object/omitBy.ts","../../src/object/pick.ts","../../src/object/pickBy.ts","../../src/object/invert.ts"],"sourcesContent":["export { omit } from './omit.ts';\nexport { omitBy } from './omitBy.ts';\nexport { pick } from './pick.ts';\nexport { pickBy } from './pickBy.ts';\nexport { invert } from './invert.ts';\n","/**\n * Creates a new object with specified keys omitted.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * excludes the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to omit keys from.\n * @param {K[]} keys - An array of keys to be omitted from the object.\n * @returns {Omit<T, K>} A new object with the specified keys omitted.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = omit(obj, ['b', 'c']);\n * // result will be { a: 1 }\n */\nexport function omit<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K> {\n const result = { ...obj };\n\n for (const key of keys) {\n delete result[key];\n }\n\n return result as Omit<T, K>;\n}\n","/**\n * Creates a new object composed of the properties that do not satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns false.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to omit properties from.\n * @param {(value: T[string], key: keyof T) => boolean} shouldOmit - A predicate function that determines\n * whether a property should be omitted. It takes the property's key and value as arguments and returns `true`\n * if the property should be omitted, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that do not satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'omit', c: 3 };\n * const shouldOmit = (key, value) => typeof value === 'string';\n * const result = omitBy(obj, shouldOmit);\n * // result will be { a: 1, c: 3 }\n */\nexport function omitBy<T extends Record<string, any>>(\n obj: T,\n shouldOmit: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (shouldOmit(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the picked object properties.\n *\n * This function takes an object and an array of keys, and returns a new object that\n * includes only the properties corresponding to the specified keys.\n *\n * @template T - The type of object.\n * @template K - The type of keys in object.\n * @param {T} obj - The object to pick keys from.\n * @param {K[]} keys - An array of keys to be picked from the object.\n * @returns {Pick<T, K>} A new object with the specified keys picked.\n *\n * @example\n * const obj = { a: 1, b: 2, c: 3 };\n * const result = pick(obj, ['a', 'c']);\n * // result will be { a: 1, c: 3 }\n */\nexport function pick<T extends Record<string, any>, K extends keyof T>(obj: T, keys: K[]): Pick<T, K> {\n const result = {} as Pick<T, K>;\n\n for (const key of keys) {\n result[key] = obj[key];\n }\n\n return result;\n}\n","/**\n * Creates a new object composed of the properties that satisfy the predicate function.\n *\n * This function takes an object and a predicate function, and returns a new object that\n * includes only the properties for which the predicate function returns true.\n *\n * @template T - The type of object.\n * @param {T} obj - The object to pick properties from.\n * @param {(value: T[keyof T], key: keyof T) => boolean} shouldPick - A predicate function that determines\n * whether a property should be picked. It takes the property's key and value as arguments and returns `true`\n * if the property should be picked, and `false` otherwise.\n * @returns {Partial<T>} A new object with the properties that satisfy the predicate function.\n *\n * @example\n * const obj = { a: 1, b: 'pick', c: 3 };\n * const shouldPick = (value) => typeof value === 'string';\n * const result = pickBy(obj, shouldPick);\n * // result will be { b: 'pick' }\n */\nexport function pickBy<T extends Record<string, any>>(\n obj: T,\n shouldPick: (value: T[keyof T], key: keyof T) => boolean\n): Partial<T> {\n const result: Partial<T> = {};\n\n for (const [key, value] of Object.entries(obj)) {\n if (!shouldPick(value, key)) {\n continue;\n }\n\n (result as any)[key] = value;\n }\n\n return result;\n}\n","/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\n\ntype PropertyKey = string | number | symbol;\n\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n for (const key in obj) {\n const value = obj[key as K] as V;\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,mBAAK;AAEpB,aAAW,OAAO,MAAM;AACtB,WAAO,OAAO,GAAG;AAAA,EACnB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,WAAW,OAAO,GAAG,GAAG;AAC1B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACjBO,SAAS,KAAuD,KAAQ,MAAuB;AACpG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,MAAM;AACtB,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AAEA,SAAO;AACT;;;ACNO,SAAS,OACd,KACA,YACY;AACZ,QAAM,SAAqB,CAAC;AAE5B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,GAAG,GAAG;AAC9C,QAAI,CAAC,WAAW,OAAO,GAAG,GAAG;AAC3B;AAAA,IACF;AAEA,IAAC,OAAe,GAAG,IAAI;AAAA,EACzB;AAEA,SAAO;AACT;;;ACbO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAQ;AAC1B,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
@@ -1,18 +1,22 @@
1
- import "../chunk-T5JCRGXA.mjs";
2
- import {
3
- pickBy
4
- } from "../chunk-6CLH5YZ2.mjs";
5
- import {
6
- omit
7
- } from "../chunk-QZITBKWX.mjs";
1
+ import "../chunk-PMHULJNL.mjs";
8
2
  import {
9
3
  omitBy
10
4
  } from "../chunk-BCTYOXT7.mjs";
11
5
  import {
12
6
  pick
13
7
  } from "../chunk-HPFDYUGP.mjs";
8
+ import {
9
+ pickBy
10
+ } from "../chunk-6CLH5YZ2.mjs";
11
+ import {
12
+ invert
13
+ } from "../chunk-FLTT2MGF.mjs";
14
+ import {
15
+ omit
16
+ } from "../chunk-QZITBKWX.mjs";
14
17
  import "../chunk-2MM5EJJX.mjs";
15
18
  export {
19
+ invert,
16
20
  omit,
17
21
  omitBy,
18
22
  pick,
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.
3
+ *
4
+ * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,
5
+ * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping
6
+ * of the input object's key-value pairs.
7
+ *
8
+ * @template K - Type of the keys in the input object (string, number, symbol)
9
+ * @template V - Type of the values in the input object (string, number, symbol)
10
+ * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted
11
+ * @returns {{ [key in V]: K }} - A new object with keys and values inverted
12
+ *
13
+ * @example
14
+ * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }
15
+ * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }
16
+ * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }
17
+ * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }
18
+ */
19
+ type PropertyKey = string | number | symbol;
20
+ declare function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): {
21
+ [key in V]: K;
22
+ };
23
+
24
+ export { invert };
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.
3
+ *
4
+ * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,
5
+ * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping
6
+ * of the input object's key-value pairs.
7
+ *
8
+ * @template K - Type of the keys in the input object (string, number, symbol)
9
+ * @template V - Type of the values in the input object (string, number, symbol)
10
+ * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted
11
+ * @returns {{ [key in V]: K }} - A new object with keys and values inverted
12
+ *
13
+ * @example
14
+ * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }
15
+ * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }
16
+ * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }
17
+ * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }
18
+ */
19
+ type PropertyKey = string | number | symbol;
20
+ declare function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): {
21
+ [key in V]: K;
22
+ };
23
+
24
+ export { invert };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/object/invert.ts
21
+ var invert_exports = {};
22
+ __export(invert_exports, {
23
+ invert: () => invert
24
+ });
25
+ module.exports = __toCommonJS(invert_exports);
26
+ function invert(obj) {
27
+ const result = {};
28
+ for (const key in obj) {
29
+ const value = obj[key];
30
+ result[value] = key;
31
+ }
32
+ return result;
33
+ }
34
+ // Annotate the CommonJS export names for ESM import in node:
35
+ 0 && (module.exports = {
36
+ invert
37
+ });
38
+ //# sourceMappingURL=invert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/object/invert.ts"],"sourcesContent":["/**\n * Inverts the keys and values of an object. The keys of the input object become the values of the output object and vice versa.\n *\n * This function takes an object and creates a new object by inverting its keys and values. If the input object has duplicate values,\n * the key of the last occurrence will be used as the value for the new key in the output object. It effectively creates a reverse mapping\n * of the input object's key-value pairs.\n *\n * @template K - Type of the keys in the input object (string, number, symbol)\n * @template V - Type of the values in the input object (string, number, symbol)\n * @param {Record<K, V>} obj - The input object whose keys and values are to be inverted\n * @returns {{ [key in V]: K }} - A new object with keys and values inverted\n *\n * @example\n * invert({ a: 1, b: 2, c: 3 }); // { 1: 'a', 2: 'b', 3: 'c' }\n * invert({ 1: 'a', 2: 'b', 3: 'c' }); // { a: '1', b: '2', c: '3' }\n * invert({ a: 1, 2: 'b', c: 3, 4: 'd' }); // { 1: 'a', b: '2', 3: 'c', d: '4' }\n * invert({ a: Symbol('sym1'), b: Symbol('sym2') }); // { [Symbol('sym1')]: 'a', [Symbol('sym2')]: 'b' }\n */\n\ntype PropertyKey = string | number | symbol;\n\nexport function invert<K extends PropertyKey, V extends PropertyKey>(obj: Record<K, V>): { [key in V]: K } {\n const result = {} as { [key in V]: K };\n\n for (const key in obj) {\n const value = obj[key as K] as V;\n result[value] = key;\n }\n\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBO,SAAS,OAAqD,KAAsC;AACzG,QAAM,SAAS,CAAC;AAEhB,aAAW,OAAO,KAAK;AACrB,UAAM,QAAQ,IAAI,GAAQ;AAC1B,WAAO,KAAK,IAAI;AAAA,EAClB;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ invert
3
+ } from "../chunk-FLTT2MGF.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ invert
7
+ };
8
+ //# sourceMappingURL=invert.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "es-toolkit",
3
3
  "description": "A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.",
4
- "version": "1.7.1-dev.153+494519b2",
4
+ "version": "1.7.1-dev.155+1eada4d8",
5
5
  "homepage": "https://es-toolkit.slash.page",
6
6
  "bugs": "https://github.com/toss/es-toolkit/issues",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-T5JCRGXA.mjs.map
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-XJR5WV2Z.mjs.map