es-toolkit 1.10.1-dev.229 → 1.10.1-dev.231

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 (46) hide show
  1. package/dist/array/index.mjs +31 -31
  2. package/dist/chunk-54TK5BIS.mjs +1 -0
  3. package/dist/chunk-GL7PPRA4.mjs +25 -0
  4. package/dist/chunk-GL7PPRA4.mjs.map +1 -0
  5. package/dist/chunk-MJA7DAOJ.mjs +25 -0
  6. package/dist/chunk-MJA7DAOJ.mjs.map +1 -0
  7. package/dist/chunk-XT74R35S.mjs +1 -0
  8. package/dist/compat/index.d.mts +2 -0
  9. package/dist/compat/index.d.ts +2 -0
  10. package/dist/compat/index.js +42 -0
  11. package/dist/compat/index.js.map +1 -1
  12. package/dist/compat/index.mjs +66 -58
  13. package/dist/compat/index.mjs.map +1 -1
  14. package/dist/function/index.mjs +6 -6
  15. package/dist/index.d.mts +2 -0
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +42 -0
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +66 -58
  20. package/dist/object/index.d.mts +1 -0
  21. package/dist/object/index.d.ts +1 -0
  22. package/dist/object/index.js +25 -2
  23. package/dist/object/index.js.map +1 -1
  24. package/dist/object/index.mjs +6 -2
  25. package/dist/object/set.d.mts +32 -0
  26. package/dist/object/set.d.ts +32 -0
  27. package/dist/object/set.js +49 -0
  28. package/dist/object/set.js.map +1 -0
  29. package/dist/object/set.mjs +8 -0
  30. package/dist/object/set.mjs.map +1 -0
  31. package/dist/string/index.d.mts +1 -0
  32. package/dist/string/index.d.ts +1 -0
  33. package/dist/string/index.js +21 -2
  34. package/dist/string/index.js.map +1 -1
  35. package/dist/string/index.mjs +6 -2
  36. package/dist/string/startCase.d.mts +16 -0
  37. package/dist/string/startCase.d.ts +16 -0
  38. package/dist/string/startCase.js +54 -0
  39. package/dist/string/startCase.js.map +1 -0
  40. package/dist/string/startCase.mjs +9 -0
  41. package/dist/string/startCase.mjs.map +1 -0
  42. package/package.json +1 -1
  43. package/dist/chunk-OSOLEQLZ.mjs +0 -1
  44. package/dist/chunk-QKYYOLJ6.mjs +0 -1
  45. /package/dist/{chunk-OSOLEQLZ.mjs.map → chunk-54TK5BIS.mjs.map} +0 -0
  46. /package/dist/{chunk-QKYYOLJ6.mjs.map → chunk-XT74R35S.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import "./chunk-NKLIE2OI.mjs";
2
- import "./chunk-QKYYOLJ6.mjs";
2
+ import "./chunk-ARZ5BDR6.mjs";
3
+ import "./chunk-XT74R35S.mjs";
3
4
  import {
4
5
  camelCase
5
6
  } from "./chunk-Y5V7UAZZ.mjs";
@@ -15,6 +16,9 @@ import {
15
16
  import {
16
17
  snakeCase
17
18
  } from "./chunk-F3WCQQET.mjs";
19
+ import {
20
+ startCase
21
+ } from "./chunk-MJA7DAOJ.mjs";
18
22
  import "./chunk-WVQ7YVRK.mjs";
19
23
  import "./chunk-ASJF5D6C.mjs";
20
24
  import {
@@ -32,11 +36,13 @@ import {
32
36
  import {
33
37
  isUndefined
34
38
  } from "./chunk-VH2PV426.mjs";
35
- import "./chunk-ARZ5BDR6.mjs";
36
39
  import {
37
40
  delay
38
41
  } from "./chunk-O64NE2P4.mjs";
39
- import "./chunk-OSOLEQLZ.mjs";
42
+ import "./chunk-54TK5BIS.mjs";
43
+ import {
44
+ set
45
+ } from "./chunk-GL7PPRA4.mjs";
40
46
  import {
41
47
  clone
42
48
  } from "./chunk-U4JGKZ56.mjs";
@@ -74,22 +80,6 @@ import {
74
80
  import {
75
81
  sum
76
82
  } from "./chunk-2SLTL4KL.mjs";
77
- import "./chunk-236H5JZJ.mjs";
78
- import {
79
- debounce
80
- } from "./chunk-3IP4JVLL.mjs";
81
- import {
82
- negate
83
- } from "./chunk-BOOQBJN2.mjs";
84
- import {
85
- noop
86
- } from "./chunk-LKXCOLNY.mjs";
87
- import {
88
- once
89
- } from "./chunk-CMBC4MXG.mjs";
90
- import {
91
- throttle
92
- } from "./chunk-QOJGMVVR.mjs";
93
83
  import {
94
84
  clamp
95
85
  } from "./chunk-MLCL773E.mjs";
@@ -97,12 +87,6 @@ import {
97
87
  inRange
98
88
  } from "./chunk-BH6HLGBA.mjs";
99
89
  import "./chunk-DDH7K4QM.mjs";
100
- import {
101
- unzipWith
102
- } from "./chunk-IFNXROZR.mjs";
103
- import {
104
- without
105
- } from "./chunk-PYEYV7BY.mjs";
106
90
  import {
107
91
  xor
108
92
  } from "./chunk-L7FQX5MN.mjs";
@@ -121,21 +105,12 @@ import {
121
105
  import {
122
106
  zipWith
123
107
  } from "./chunk-4KYXHZ4R.mjs";
124
- import {
125
- toFilled
126
- } from "./chunk-OP4OAKQJ.mjs";
127
- import {
128
- union
129
- } from "./chunk-R6QA7PLZ.mjs";
130
108
  import {
131
109
  unionBy
132
110
  } from "./chunk-NFS7RWWE.mjs";
133
111
  import {
134
112
  unionWith
135
113
  } from "./chunk-2ZCITDMK.mjs";
136
- import {
137
- uniq
138
- } from "./chunk-DVK2N4KC.mjs";
139
114
  import {
140
115
  uniqBy
141
116
  } from "./chunk-OXAZEEGP.mjs";
@@ -146,17 +121,11 @@ import {
146
121
  unzip
147
122
  } from "./chunk-UYZKMBDO.mjs";
148
123
  import {
149
- sample
150
- } from "./chunk-2KNLZB7V.mjs";
151
- import {
152
- sampleSize
153
- } from "./chunk-EHSKB6DF.mjs";
154
- import {
155
- randomInt
156
- } from "./chunk-GIWAOOFY.mjs";
124
+ unzipWith
125
+ } from "./chunk-IFNXROZR.mjs";
157
126
  import {
158
- random
159
- } from "./chunk-SYWMYQYJ.mjs";
127
+ without
128
+ } from "./chunk-PYEYV7BY.mjs";
160
129
  import {
161
130
  shuffle
162
131
  } from "./chunk-G7UQ5PUR.mjs";
@@ -176,11 +145,14 @@ import {
176
145
  takeWhile
177
146
  } from "./chunk-2IXFGSUA.mjs";
178
147
  import {
179
- intersectionBy
180
- } from "./chunk-O6UXZR3U.mjs";
148
+ toFilled
149
+ } from "./chunk-OP4OAKQJ.mjs";
181
150
  import {
182
- intersectionWith
183
- } from "./chunk-XI7KRD2C.mjs";
151
+ union
152
+ } from "./chunk-R6QA7PLZ.mjs";
153
+ import {
154
+ uniq
155
+ } from "./chunk-DVK2N4KC.mjs";
184
156
  import {
185
157
  keyBy
186
158
  } from "./chunk-AJKZMN2V.mjs";
@@ -200,8 +172,17 @@ import {
200
172
  partition
201
173
  } from "./chunk-DN3NOZ3H.mjs";
202
174
  import {
203
- flattenDeep
204
- } from "./chunk-ML727RRJ.mjs";
175
+ sample
176
+ } from "./chunk-2KNLZB7V.mjs";
177
+ import {
178
+ sampleSize
179
+ } from "./chunk-EHSKB6DF.mjs";
180
+ import {
181
+ randomInt
182
+ } from "./chunk-GIWAOOFY.mjs";
183
+ import {
184
+ random
185
+ } from "./chunk-SYWMYQYJ.mjs";
205
186
  import {
206
187
  forEachRight
207
188
  } from "./chunk-IEA53J7P.mjs";
@@ -218,11 +199,11 @@ import {
218
199
  intersection
219
200
  } from "./chunk-FVVSE2F2.mjs";
220
201
  import {
221
- differenceBy
222
- } from "./chunk-LVWX5B43.mjs";
202
+ intersectionBy
203
+ } from "./chunk-O6UXZR3U.mjs";
223
204
  import {
224
- differenceWith
225
- } from "./chunk-6NVQAHXP.mjs";
205
+ intersectionWith
206
+ } from "./chunk-XI7KRD2C.mjs";
226
207
  import {
227
208
  drop
228
209
  } from "./chunk-S3CORED5.mjs";
@@ -241,13 +222,12 @@ import {
241
222
  import {
242
223
  flatMap
243
224
  } from "./chunk-KBXHURLW.mjs";
225
+ import {
226
+ flattenDeep
227
+ } from "./chunk-ML727RRJ.mjs";
244
228
  import {
245
229
  flatten
246
230
  } from "./chunk-33MSBDC6.mjs";
247
- import "./chunk-FZEZH22H.mjs";
248
- import {
249
- AbortError
250
- } from "./chunk-DXB7EZUQ.mjs";
251
231
  import {
252
232
  chunk
253
233
  } from "./chunk-E6C5EZQA.mjs";
@@ -260,6 +240,32 @@ import {
260
240
  import {
261
241
  difference
262
242
  } from "./chunk-JPUKH67K.mjs";
243
+ import {
244
+ differenceBy
245
+ } from "./chunk-LVWX5B43.mjs";
246
+ import {
247
+ differenceWith
248
+ } from "./chunk-6NVQAHXP.mjs";
249
+ import "./chunk-FZEZH22H.mjs";
250
+ import {
251
+ AbortError
252
+ } from "./chunk-DXB7EZUQ.mjs";
253
+ import "./chunk-236H5JZJ.mjs";
254
+ import {
255
+ once
256
+ } from "./chunk-CMBC4MXG.mjs";
257
+ import {
258
+ throttle
259
+ } from "./chunk-QOJGMVVR.mjs";
260
+ import {
261
+ debounce
262
+ } from "./chunk-3IP4JVLL.mjs";
263
+ import {
264
+ negate
265
+ } from "./chunk-BOOQBJN2.mjs";
266
+ import {
267
+ noop
268
+ } from "./chunk-LKXCOLNY.mjs";
263
269
  import "./chunk-2MM5EJJX.mjs";
264
270
  export {
265
271
  AbortError,
@@ -320,8 +326,10 @@ export {
320
326
  round,
321
327
  sample,
322
328
  sampleSize,
329
+ set,
323
330
  shuffle,
324
331
  snakeCase,
332
+ startCase,
325
333
  sum,
326
334
  sumBy,
327
335
  tail,
@@ -4,3 +4,4 @@ export { pick } from './pick.mjs';
4
4
  export { pickBy } from './pickBy.mjs';
5
5
  export { invert } from './invert.mjs';
6
6
  export { clone } from './clone.mjs';
7
+ export { set } from './set.mjs';
@@ -4,3 +4,4 @@ export { pick } from './pick.js';
4
4
  export { pickBy } from './pickBy.js';
5
5
  export { invert } from './invert.js';
6
6
  export { clone } from './clone.js';
7
+ export { set } from './set.js';
@@ -39,7 +39,8 @@ __export(object_exports, {
39
39
  omit: () => omit,
40
40
  omitBy: () => omitBy,
41
41
  pick: () => pick,
42
- pickBy: () => pickBy
42
+ pickBy: () => pickBy,
43
+ set: () => set
43
44
  });
44
45
  module.exports = __toCommonJS(object_exports);
45
46
 
@@ -133,6 +134,27 @@ function clone(obj) {
133
134
  function isPrimitive(value) {
134
135
  return value == null || typeof value !== "object" && typeof value !== "function";
135
136
  }
137
+
138
+ // src/object/set.ts
139
+ function set(obj, path, value) {
140
+ if (obj instanceof Map || obj instanceof Set) {
141
+ throw new TypeError("Set or Map is not supported");
142
+ }
143
+ const keys = Array.isArray(path) ? path : String(path).replace(/\[|\]/g, (match) => {
144
+ return match === "[" ? "." : "";
145
+ }).split(".");
146
+ let pointer = obj;
147
+ for (let i = 0; i < keys.length - 1; i++) {
148
+ const key = keys[i];
149
+ const nextKey = keys[i + 1];
150
+ if (pointer[key] == null || typeof pointer[key] !== "object") {
151
+ pointer[key] = /^\d+$/.test(nextKey) ? [] : {};
152
+ }
153
+ pointer = pointer[key];
154
+ }
155
+ pointer[keys[keys.length - 1]] = value;
156
+ return obj;
157
+ }
136
158
  // Annotate the CommonJS export names for ESM import in node:
137
159
  0 && (module.exports = {
138
160
  clone,
@@ -140,6 +162,7 @@ function isPrimitive(value) {
140
162
  omit,
141
163
  omitBy,
142
164
  pick,
143
- pickBy
165
+ pickBy,
166
+ set
144
167
  });
145
168
  //# sourceMappingURL=index.js.map
@@ -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","../../src/object/invert.ts","../../src/object/clone.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';\nexport { clone } from './clone.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 */\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 const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;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;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AK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,CAAC,KAAK,KAAK,KAAK,KAAK;AAC9B,aAAO,IAAI,KAAK,KAAK;AAAA,IACvB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,eAAe,KAAK;AACtB,UAAM,SAAS,oBAAI,IAAI;AACvB,eAAW,SAAS,KAAK;AACvB,aAAO,IAAI,KAAK;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,QAAQ,UAAU;AAC3B,WAAO,OAAO,OAAO,CAAC,GAAG,GAAG;AAAA,EAC9B;AACA,SAAO;AACT;AAIA,SAAS,YAAY,OAAoC;AACvD,SAAO,SAAS,QACb,OAAO,UAAU,YAAY,OAAO,UAAU;AACnD;","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","../../src/object/clone.ts","../../src/object/set.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';\nexport { clone } from './clone.ts';\nexport { set } from './set.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 */\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 const keys = Object.keys(obj) as K[];\n \n for (let i = 0; i < keys.length; i++) {\n const key = keys[i];\n const value = obj[key];\n result[value] = key;\n }\n\n return result;\n}\n","/**\n * Creates a shallow clone of the given object.\n *\n * @template T - The type of the object.\n * @param {T} obj - The object to clone.\n * @returns {T} - A shallow clone of the given object.\n *\n * @example\n * // Clone a primitive values\n * const num = 29;\n * const clonedNum = clone(num);\n * console.log(clonedNum); // 29\n * console.log(clonedNum === num) ; // true\n *\n * @example\n * // Clone an array\n * const arr = [1, 2, 3];\n * const clonedArr = clone(arr);\n * console.log(clonedArr); // [1, 2, 3]\n * console.log(clonedArr === arr); // false\n *\n * @example\n * // Clone an object\n * const obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };\n * const clonedObj = clone(obj);\n * console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }\n * console.log(clonedObj === obj); // false\n */\nexport function clone<T>(obj: T): T {\n if (isPrimitive(obj)) {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.slice() as T;\n }\n\n if (obj instanceof Date) {\n return new Date(obj.getTime()) as T;\n }\n\n if (obj instanceof RegExp) {\n return new RegExp(obj.source, obj.flags) as T;\n }\n\n if (obj instanceof Map) {\n const result = new Map();\n for (const [key, value] of obj) {\n result.set(key, value);\n }\n return result as T;\n }\n\n if (obj instanceof Set) {\n const result = new Set();\n for (const value of obj) {\n result.add(value);\n }\n return result as T;\n }\n\n if (typeof obj === \"object\") {\n return Object.assign({}, obj) as T;\n }\n return obj;\n}\n\ntype Primitive = null | undefined | string | number | boolean | symbol | bigint;\n\nfunction isPrimitive(value: unknown): value is Primitive {\n return value == null ||\n (typeof value !== \"object\" && typeof value !== \"function\");\n}\n","/**\n * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.\n *\n * @template T - The type of the object.\n * @param {Settable} obj - The object to modify.\n * @param {Path} path - The path of the property to set.\n * @param {any} value - The value to set.\n * @returns {T} - The modified object.\n *\n * @example\n * // Set a value in a nested object\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * console.log(obj.a.b.c); // 4\n *\n * @example\n * // Set a value in an array\n * const arr = [1, 2, 3];\n * set(arr, 1, 4);\n * console.log(arr[1]); // 4\n *\n * @example\n * // Create non-existent path and set value\n * const obj = {};\n * set(obj, 'a.b.c', 4);\n * console.log(obj); // { a: { b: { c: 4 } } }\n */\nexport function set<T>(obj: Settable, path: Path, value: any): T {\n if (obj instanceof Map || obj instanceof Set) {\n throw new TypeError('Set or Map is not supported');\n }\n //TODO: memoize\n const keys = Array.isArray(path)\n ? path\n : String(path as string)\n .replace(/\\[|\\]/g, match => {\n return match === '[' ? '.' : '';\n })\n .split('.');\n\n let pointer: any = obj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n const nextKey = keys[i + 1];\n if (pointer[key] == null || typeof pointer[key] !== 'object') {\n pointer[key] = /^\\d+$/.test(nextKey as string) ? [] : {};\n }\n pointer = pointer[key];\n }\n\n pointer[keys[keys.length - 1]] = value;\n return obj as T;\n}\n\ntype Settable = object | any[];\ntype Path = string | number | Array<string | number>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;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;A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I,eAAe,OAAO,eAAe,KAAK;AAC5C,UAAM,IAAI,UAAU,6BAA6B;AAAA,EACnD;AAEA,QAAM,OAAO,MAAM,QAAQ,IAAI,IAC3B,OACA,OAAO,IAAc,EAClB,QAAQ,UAAU,WAAS;AAC1B,WAAO,UAAU,MAAM,MAAM;AAAA,EAC/B,CAAC,EACA,MAAM,GAAG;AAEhB,MAAI,UAAe;AAEnB,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;AACxC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,UAAU,KAAK,IAAI,CAAC;AAC1B,QAAI,QAAQ,GAAG,KAAK,QAAQ,OAAO,QAAQ,GAAG,MAAM,UAAU;AAC5D,cAAQ,GAAG,IAAI,QAAQ,KAAK,OAAiB,IAAI,CAAC,IAAI,CAAC;AAAA,IACzD;AACA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,UAAQ,KAAK,KAAK,SAAS,CAAC,CAAC,IAAI;AACjC,SAAO;AACT;","names":[]}
@@ -1,4 +1,7 @@
1
- import "../chunk-OSOLEQLZ.mjs";
1
+ import "../chunk-54TK5BIS.mjs";
2
+ import {
3
+ set
4
+ } from "../chunk-GL7PPRA4.mjs";
2
5
  import {
3
6
  clone
4
7
  } from "../chunk-U4JGKZ56.mjs";
@@ -24,6 +27,7 @@ export {
24
27
  omit,
25
28
  omitBy,
26
29
  pick,
27
- pickBy
30
+ pickBy,
31
+ set
28
32
  };
29
33
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {Settable} obj - The object to modify.
6
+ * @param {Path} path - The path of the property to set.
7
+ * @param {any} value - The value to set.
8
+ * @returns {T} - The modified object.
9
+ *
10
+ * @example
11
+ * // Set a value in a nested object
12
+ * const obj = { a: { b: { c: 3 } } };
13
+ * set(obj, 'a.b.c', 4);
14
+ * console.log(obj.a.b.c); // 4
15
+ *
16
+ * @example
17
+ * // Set a value in an array
18
+ * const arr = [1, 2, 3];
19
+ * set(arr, 1, 4);
20
+ * console.log(arr[1]); // 4
21
+ *
22
+ * @example
23
+ * // Create non-existent path and set value
24
+ * const obj = {};
25
+ * set(obj, 'a.b.c', 4);
26
+ * console.log(obj); // { a: { b: { c: 4 } } }
27
+ */
28
+ declare function set<T>(obj: Settable, path: Path, value: any): T;
29
+ type Settable = object | any[];
30
+ type Path = string | number | Array<string | number>;
31
+
32
+ export { set };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.
3
+ *
4
+ * @template T - The type of the object.
5
+ * @param {Settable} obj - The object to modify.
6
+ * @param {Path} path - The path of the property to set.
7
+ * @param {any} value - The value to set.
8
+ * @returns {T} - The modified object.
9
+ *
10
+ * @example
11
+ * // Set a value in a nested object
12
+ * const obj = { a: { b: { c: 3 } } };
13
+ * set(obj, 'a.b.c', 4);
14
+ * console.log(obj.a.b.c); // 4
15
+ *
16
+ * @example
17
+ * // Set a value in an array
18
+ * const arr = [1, 2, 3];
19
+ * set(arr, 1, 4);
20
+ * console.log(arr[1]); // 4
21
+ *
22
+ * @example
23
+ * // Create non-existent path and set value
24
+ * const obj = {};
25
+ * set(obj, 'a.b.c', 4);
26
+ * console.log(obj); // { a: { b: { c: 4 } } }
27
+ */
28
+ declare function set<T>(obj: Settable, path: Path, value: any): T;
29
+ type Settable = object | any[];
30
+ type Path = string | number | Array<string | number>;
31
+
32
+ export { set };
@@ -0,0 +1,49 @@
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/set.ts
21
+ var set_exports = {};
22
+ __export(set_exports, {
23
+ set: () => set
24
+ });
25
+ module.exports = __toCommonJS(set_exports);
26
+ function set(obj, path, value) {
27
+ if (obj instanceof Map || obj instanceof Set) {
28
+ throw new TypeError("Set or Map is not supported");
29
+ }
30
+ const keys = Array.isArray(path) ? path : String(path).replace(/\[|\]/g, (match) => {
31
+ return match === "[" ? "." : "";
32
+ }).split(".");
33
+ let pointer = obj;
34
+ for (let i = 0; i < keys.length - 1; i++) {
35
+ const key = keys[i];
36
+ const nextKey = keys[i + 1];
37
+ if (pointer[key] == null || typeof pointer[key] !== "object") {
38
+ pointer[key] = /^\d+$/.test(nextKey) ? [] : {};
39
+ }
40
+ pointer = pointer[key];
41
+ }
42
+ pointer[keys[keys.length - 1]] = value;
43
+ return obj;
44
+ }
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ set
48
+ });
49
+ //# sourceMappingURL=set.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/object/set.ts"],"sourcesContent":["/**\n * Sets the value at the specified path of the given object. If any part of the path does not exist, it will be created.\n *\n * @template T - The type of the object.\n * @param {Settable} obj - The object to modify.\n * @param {Path} path - The path of the property to set.\n * @param {any} value - The value to set.\n * @returns {T} - The modified object.\n *\n * @example\n * // Set a value in a nested object\n * const obj = { a: { b: { c: 3 } } };\n * set(obj, 'a.b.c', 4);\n * console.log(obj.a.b.c); // 4\n *\n * @example\n * // Set a value in an array\n * const arr = [1, 2, 3];\n * set(arr, 1, 4);\n * console.log(arr[1]); // 4\n *\n * @example\n * // Create non-existent path and set value\n * const obj = {};\n * set(obj, 'a.b.c', 4);\n * console.log(obj); // { a: { b: { c: 4 } } }\n */\nexport function set<T>(obj: Settable, path: Path, value: any): T {\n if (obj instanceof Map || obj instanceof Set) {\n throw new TypeError('Set or Map is not supported');\n }\n //TODO: memoize\n const keys = Array.isArray(path)\n ? path\n : String(path as string)\n .replace(/\\[|\\]/g, match => {\n return match === '[' ? '.' : '';\n })\n .split('.');\n\n let pointer: any = obj;\n\n for (let i = 0; i < keys.length - 1; i++) {\n const key = keys[i];\n const nextKey = keys[i + 1];\n if (pointer[key] == null || typeof pointer[key] !== 'object') {\n pointer[key] = /^\\d+$/.test(nextKey as string) ? [] : {};\n }\n pointer = pointer[key];\n }\n\n pointer[keys[keys.length - 1]] = value;\n return obj as T;\n}\n\ntype Settable = object | any[];\ntype Path = string | number | Array<string | number>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2BO,SAAS,IAAO,KAAe,MAAY,OAAe;AAC/D,MAAI,eAAe,OAAO,eAAe,KAAK;AAC5C,UAAM,IAAI,UAAU,6BAA6B;AAAA,EACnD;AAEA,QAAM,OAAO,MAAM,QAAQ,IAAI,IAC3B,OACA,OAAO,IAAc,EAClB,QAAQ,UAAU,WAAS;AAC1B,WAAO,UAAU,MAAM,MAAM;AAAA,EAC/B,CAAC,EACA,MAAM,GAAG;AAEhB,MAAI,UAAe;AAEnB,WAAS,IAAI,GAAG,IAAI,KAAK,SAAS,GAAG,KAAK;AACxC,UAAM,MAAM,KAAK,CAAC;AAClB,UAAM,UAAU,KAAK,IAAI,CAAC;AAC1B,QAAI,QAAQ,GAAG,KAAK,QAAQ,OAAO,QAAQ,GAAG,MAAM,UAAU;AAC5D,cAAQ,GAAG,IAAI,QAAQ,KAAK,OAAiB,IAAI,CAAC,IAAI,CAAC;AAAA,IACzD;AACA,cAAU,QAAQ,GAAG;AAAA,EACvB;AAEA,UAAQ,KAAK,KAAK,SAAS,CAAC,CAAC,IAAI;AACjC,SAAO;AACT;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ set
3
+ } from "../chunk-GL7PPRA4.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ set
7
+ };
8
+ //# sourceMappingURL=set.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -2,4 +2,5 @@ export { camelCase } from './camelCase.mjs';
2
2
  export { snakeCase } from './snakeCase.mjs';
3
3
  export { kebabCase } from './kebabCase.mjs';
4
4
  export { lowerCase } from './lowerCase.mjs';
5
+ export { startCase } from './startCase.mjs';
5
6
  export { capitalize } from './capitalize.mjs';
@@ -2,4 +2,5 @@ export { camelCase } from './camelCase.js';
2
2
  export { snakeCase } from './snakeCase.js';
3
3
  export { kebabCase } from './kebabCase.js';
4
4
  export { lowerCase } from './lowerCase.js';
5
+ export { startCase } from './startCase.js';
5
6
  export { capitalize } from './capitalize.js';
@@ -24,7 +24,8 @@ __export(string_exports, {
24
24
  capitalize: () => capitalize,
25
25
  kebabCase: () => kebabCase,
26
26
  lowerCase: () => lowerCase,
27
- snakeCase: () => snakeCase
27
+ snakeCase: () => snakeCase,
28
+ startCase: () => startCase
28
29
  });
29
30
  module.exports = __toCommonJS(string_exports);
30
31
 
@@ -67,12 +68,30 @@ var lowerCase = (str) => {
67
68
  const words = getWords(str);
68
69
  return words.map((word) => word.toLowerCase()).join(" ");
69
70
  };
71
+
72
+ // src/string/startCase.ts
73
+ function startCase(str) {
74
+ const words = getWords(str.trim());
75
+ let result = "";
76
+ for (const word of words) {
77
+ if (result) {
78
+ result += " ";
79
+ }
80
+ if (word === word.toUpperCase()) {
81
+ result += word;
82
+ } else {
83
+ result += word[0].toUpperCase() + word.slice(1).toLowerCase();
84
+ }
85
+ }
86
+ return result;
87
+ }
70
88
  // Annotate the CommonJS export names for ESM import in node:
71
89
  0 && (module.exports = {
72
90
  camelCase,
73
91
  capitalize,
74
92
  kebabCase,
75
93
  lowerCase,
76
- snakeCase
94
+ snakeCase,
95
+ startCase
77
96
  });
78
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/string/index.ts","../../src/string/capitalize.ts","../../src/string/_internal/getWords.ts","../../src/string/camelCase.ts","../../src/string/snakeCase.ts","../../src/string/kebabCase.ts","../../src/string/lowerCase.ts"],"sourcesContent":["export { camelCase } from './camelCase.ts';\nexport { snakeCase } from './snakeCase.ts';\nexport { kebabCase } from './kebabCase.ts';\nexport { lowerCase } from './lowerCase.ts';\nexport { capitalize } from './capitalize.ts';\n","/**\n * Converts the first character of string to upper case and the remaining to lower case.\n *\n * @template T - Literal type of the string.\n * @param {T} str - The string to be converted to uppercase.\n * @returns {Capitalize<T>} - The capitalized string.\n *\n * @example\n * const result = capitalize('fred') // returns 'Fred'\n * const result2 = capitalize('FRED') // returns 'Fred'\n */\n\nexport const capitalize = <T extends string>(str: T): Capitalize<T> => {\n return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()) as Capitalize<T>;\n};\n","/**\n * Regular expression pattern to split strings into words for various case conversions\n *\n * This pattern matchs sequences of characters in a string, considering the following case:\n * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)\n * - Sequences of one uppercase letter optionally followed by lowercase letters and digits\n * - Single uppercase letters\n * - Sequences of digis\n *\n * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into\n * a consistent format like snake case.\n *\n * @example\n * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);\n * // matchs: ['camel', 'Case', 'HTTP', 'Request']\n */\nconst CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;\n\nexport function getWords(str: string): string[] {\n return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);\n}\n","import { capitalize } from \"./capitalize.ts\";\nimport { getWords } from \"./_internal/getWords.ts\";\n\n/**\n * Converts a string to camel case.\n *\n * camel case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to camel case.\n * @returns {string} - The converted string to camel case.\n *\n * @example\n * const convertedStr1 = camelCase('camelCase') // returns 'camelCase'\n * const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'\n * const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'\n * const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'\n */\n\nexport function camelCase(str: string): string {\n const words = getWords(str);\n\n if (words.length === 0) {\n return \"\";\n }\n\n const [first, ...rest] = words;\n\n return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join(\"\")\n }`;\n}\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to snake case.\n *\n * Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to snake case.\n * @returns {string} - The converted string to snake case.\n *\n * @example\n * const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'\n * const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'\n * const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'\n * const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'\n */\n\nexport const snakeCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('_');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to kebab case.\n *\n * Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.\n *\n * @param {string} str - The string that is to be changed to kebab case.\n * @returns {string} - The converted string to kebab case.\n *\n * @example\n * const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'\n * const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'\n * const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'\n * const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'\n */\n\nexport const kebabCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('-');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to lower case.\n *\n * Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.\n *\n * @param {string} str - The string that is to be changed to lower case.\n * @returns {string} - The converted string to lower case.\n *\n * @example\n * const convertedStr1 = lowerCase('camelCase') // returns 'camel case'\n * const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'\n * const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'\n * const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'\n */\nexport const lowerCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join(' ');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,IAAM,aAAa,CAAmB,QAA0B;AACrE,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,EAAE,YAAY;AACjE;;;ACEA,IAAM,qBAAqB;AAEpB,SAAS,SAAS,KAAuB;AAlBhD;AAmBE,SAAO,MAAM,MAAK,SAAI,MAAM,kBAAkB,MAA5B,YAAiC,CAAC,CAAC;AACvD;;;ACFO,SAAS,UAAU,KAAqB;AAC7C,QAAM,QAAQ,SAAS,GAAG;AAE1B,MAAI,MAAM,WAAW,GAAG;AACtB,WAAO;AAAA,EACT;AAEA,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI;AAEzB,SAAO,GAAG,MAAM,YAAY,CAAC,GAAG,KAAK,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,EAAE,KAAK,EAAE,CAC1E;AACJ;;;ACZO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACHO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;;;ACJO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,QAAQ,SAAS,GAAG;AAC1B,SAAO,MAAM,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AACvD;","names":[]}
1
+ {"version":3,"sources":["../../src/string/index.ts","../../src/string/capitalize.ts","../../src/string/_internal/getWords.ts","../../src/string/camelCase.ts","../../src/string/snakeCase.ts","../../src/string/kebabCase.ts","../../src/string/lowerCase.ts","../../src/string/startCase.ts"],"sourcesContent":["export { camelCase } from './camelCase.ts';\nexport { snakeCase } from './snakeCase.ts';\nexport { kebabCase } from './kebabCase.ts';\nexport { lowerCase } from './lowerCase.ts';\nexport { startCase } from './startCase.ts';\nexport { capitalize } from './capitalize.ts';\n","/**\n * Converts the first character of string to upper case and the remaining to lower case.\n *\n * @template T - Literal type of the string.\n * @param {T} str - The string to be converted to uppercase.\n * @returns {Capitalize<T>} - The capitalized string.\n *\n * @example\n * const result = capitalize('fred') // returns 'Fred'\n * const result2 = capitalize('FRED') // returns 'Fred'\n */\n\nexport const capitalize = <T extends string>(str: T): Capitalize<T> => {\n return (str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()) as Capitalize<T>;\n};\n","/**\n * Regular expression pattern to split strings into words for various case conversions\n *\n * This pattern matchs sequences of characters in a string, considering the following case:\n * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)\n * - Sequences of one uppercase letter optionally followed by lowercase letters and digits\n * - Single uppercase letters\n * - Sequences of digis\n *\n * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into\n * a consistent format like snake case.\n *\n * @example\n * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);\n * // matchs: ['camel', 'Case', 'HTTP', 'Request']\n */\nconst CASE_SPLIT_PATTERN = /[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?![a-z])/g;\n\nexport function getWords(str: string): string[] {\n return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);\n}\n","import { capitalize } from \"./capitalize.ts\";\nimport { getWords } from \"./_internal/getWords.ts\";\n\n/**\n * Converts a string to camel case.\n *\n * camel case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to camel case.\n * @returns {string} - The converted string to camel case.\n *\n * @example\n * const convertedStr1 = camelCase('camelCase') // returns 'camelCase'\n * const convertedStr2 = camelCase('some whitespace') // returns 'someWhitespace'\n * const convertedStr3 = camelCase('hyphen-text') // returns 'hyphenText'\n * const convertedStr4 = camelCase('HTTPRequest') // returns 'httpRequest'\n */\n\nexport function camelCase(str: string): string {\n const words = getWords(str);\n\n if (words.length === 0) {\n return \"\";\n }\n\n const [first, ...rest] = words;\n\n return `${first.toLowerCase()}${rest.map((word) => capitalize(word)).join(\"\")\n }`;\n}\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to snake case.\n *\n * Snake case is the naming convention in which each word is written in lowercase and separated by an underscore (_) character.\n *\n * @param {string} str - The string that is to be changed to snake case.\n * @returns {string} - The converted string to snake case.\n *\n * @example\n * const convertedStr1 = snakeCase('camelCase') // returns 'camel_case'\n * const convertedStr2 = snakeCase('some whitespace') // returns 'some_whitespace'\n * const convertedStr3 = snakeCase('hyphen-text') // returns 'hyphen_text'\n * const convertedStr4 = snakeCase('HTTPRequest') // returns 'http_request'\n */\n\nexport const snakeCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('_');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to kebab case.\n *\n * Kebab case is the naming convention in which each word is written in lowercase and separated by a dash (-) character.\n *\n * @param {string} str - The string that is to be changed to kebab case.\n * @returns {string} - The converted string to kebab case.\n *\n * @example\n * const convertedStr1 = kebabCase('camelCase') // returns 'camel-case'\n * const convertedStr2 = kebabCase('some whitespace') // returns 'some-whitespace'\n * const convertedStr3 = kebabCase('hyphen-text') // returns 'hyphen-text'\n * const convertedStr4 = kebabCase('HTTPRequest') // returns 'http-request'\n */\n\nexport const kebabCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join('-');\n};\n","import { getWords } from './_internal/getWords.ts';\n\n/**\n * Converts a string to lower case.\n *\n * Lower case is the naming convention in which each word is written in lowercase and separated by an space ( ) character.\n *\n * @param {string} str - The string that is to be changed to lower case.\n * @returns {string} - The converted string to lower case.\n *\n * @example\n * const convertedStr1 = lowerCase('camelCase') // returns 'camel case'\n * const convertedStr2 = lowerCase('some whitespace') // returns 'some whitespace'\n * const convertedStr3 = lowerCase('hyphen-text') // returns 'hyphen text'\n * const convertedStr4 = lowerCase('HTTPRequest') // returns 'http request'\n */\nexport const lowerCase = (str: string): string => {\n const words = getWords(str);\n return words.map(word => word.toLowerCase()).join(' ');\n};\n","import { getWords } from './_internal/getWords';\n\n/**\n * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.\n *\n * Start case is the naming convention in which each word is written with an initial capital letter.\n * @param {string} str - The string to convert.\n * @returns {string} The converted string.\n *\n * @example\n * const result1 = startCase('hello world'); // result will be 'Hello World'\n * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'\n * const result3 = startCase('hello-world'); // result will be 'Hello World'\n * const result4 = startCase('hello_world'); // result will be 'Hello World'\n */\nexport function startCase(str: string): string {\n const words = getWords(str.trim());\n let result = '';\n for (const word of words) {\n if (result) {\n result += ' ';\n }\n if (word === word.toUpperCase()) {\n result += word;\n } else {\n result += word[0].toUpperCase() + word.slice(1).toLowerCase();\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACYO,IAAM,aAAa,CAAmB,QAA0B;AACrE,SAAQ,IAAI,OAAO,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC,EAAE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s";
1
+ import "../chunk-XT74R35S.mjs";
2
2
  import {
3
3
  camelCase
4
4
  } from "../chunk-Y5V7UAZZ.mjs";
@@ -14,6 +14,9 @@ import {
14
14
  import {
15
15
  snakeCase
16
16
  } from "../chunk-F3WCQQET.mjs";
17
+ import {
18
+ startCase
19
+ } from "../chunk-MJA7DAOJ.mjs";
17
20
  import "../chunk-WVQ7YVRK.mjs";
18
21
  import "../chunk-2MM5EJJX.mjs";
19
22
  export {
@@ -21,6 +24,7 @@ export {
21
24
  capitalize,
22
25
  kebabCase,
23
26
  lowerCase,
24
- snakeCase
27
+ snakeCase,
28
+ startCase
25
29
  };
26
30
  //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
3
+ *
4
+ * Start case is the naming convention in which each word is written with an initial capital letter.
5
+ * @param {string} str - The string to convert.
6
+ * @returns {string} The converted string.
7
+ *
8
+ * @example
9
+ * const result1 = startCase('hello world'); // result will be 'Hello World'
10
+ * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'
11
+ * const result3 = startCase('hello-world'); // result will be 'Hello World'
12
+ * const result4 = startCase('hello_world'); // result will be 'Hello World'
13
+ */
14
+ declare function startCase(str: string): string;
15
+
16
+ export { startCase };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Converts the first character of each word in a string to uppercase and the remaining characters to lowercase.
3
+ *
4
+ * Start case is the naming convention in which each word is written with an initial capital letter.
5
+ * @param {string} str - The string to convert.
6
+ * @returns {string} The converted string.
7
+ *
8
+ * @example
9
+ * const result1 = startCase('hello world'); // result will be 'Hello World'
10
+ * const result2 = startCase('HELLO WORLD'); // result will be 'Hello World'
11
+ * const result3 = startCase('hello-world'); // result will be 'Hello World'
12
+ * const result4 = startCase('hello_world'); // result will be 'Hello World'
13
+ */
14
+ declare function startCase(str: string): string;
15
+
16
+ export { startCase };