es-toolkit 1.10.1-dev.228 → 1.10.1-dev.230

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.
@@ -1,5 +1,5 @@
1
1
  import "../chunk-NKLIE2OI.mjs";
2
- import "../chunk-QKYYOLJ6.mjs";
2
+ import "../chunk-XT74R35S.mjs";
3
3
  import {
4
4
  camelCase
5
5
  } from "../chunk-Y5V7UAZZ.mjs";
@@ -15,6 +15,9 @@ import {
15
15
  import {
16
16
  snakeCase
17
17
  } from "../chunk-F3WCQQET.mjs";
18
+ import {
19
+ startCase
20
+ } from "../chunk-MJA7DAOJ.mjs";
18
21
  import "../chunk-WVQ7YVRK.mjs";
19
22
  import "../chunk-ASJF5D6C.mjs";
20
23
  import {
@@ -42,7 +45,7 @@ import {
42
45
  } from "../chunk-U4JGKZ56.mjs";
43
46
  import {
44
47
  invert
45
- } from "../chunk-74WWMNZS.mjs";
48
+ } from "../chunk-OLX53VEF.mjs";
46
49
  import {
47
50
  omit
48
51
  } from "../chunk-QZITBKWX.mjs";
@@ -331,6 +334,7 @@ export {
331
334
  sampleSize,
332
335
  shuffle,
333
336
  snakeCase,
337
+ startCase,
334
338
  sum,
335
339
  sumBy,
336
340
  tail,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/compat/array/chunk.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAASA,OAAS,KAAmB,OAAe,GAAU;AACnE,SAAO,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAEnC,MAAI,SAAS,GAAG;AACd,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,MAAa,KAAK,IAAI;AAC/B;","names":["chunk"]}
1
+ {"version":3,"sources":["../../src/compat/array/chunk.ts"],"sourcesContent":["import { chunk as chunkToolkit } from '../../array/chunk.ts';\n\n/**\n * Splits an array into smaller arrays of a specified length.\n *\n * This function takes an input array and divides it into multiple smaller arrays,\n * each of a specified length. If the input array cannot be evenly divided,\n * the final sub-array will contain the remaining elements.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The array to be chunked into smaller arrays.\n * @param {number} size - The size of each smaller array. Must be a positive integer.\n * @returns {T[][]} A two-dimensional array where each sub-array has a maximum length of `size`.\n * @throws {Error} Throws an error if `size` is not a positive integer.\n *\n * @example\n * // Splits an array of numbers into sub-arrays of length 2\n * chunk([1, 2, 3, 4, 5], 2);\n * // Returns: [[1, 2], [3, 4], [5]]\n *\n * @example\n * // Splits an array of strings into sub-arrays of length 3\n * chunk(['a', 'b', 'c', 'd', 'e', 'f', 'g'], 3);\n * // Returns: [['a', 'b', 'c'], ['d', 'e', 'f'], ['g']]\n */\nexport function chunk<T>(arr: readonly T[], size: number = 1): T[][] {\n size = Math.max(Math.floor(size), 0);\n\n if (size === 0) {\n return [];\n }\n\n return chunkToolkit(arr, size);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAASA,OAAS,KAAmB,OAAe,GAAU;AACnE,SAAO,KAAK,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC;AAEnC,MAAI,SAAS,GAAG;AACd,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,MAAa,KAAK,IAAI;AAC/B;","names":["chunk"]}
package/dist/index.d.mts CHANGED
@@ -81,4 +81,5 @@ export { camelCase } from './string/camelCase.mjs';
81
81
  export { snakeCase } from './string/snakeCase.mjs';
82
82
  export { kebabCase } from './string/kebabCase.mjs';
83
83
  export { lowerCase } from './string/lowerCase.mjs';
84
+ export { startCase } from './string/startCase.mjs';
84
85
  export { capitalize } from './string/capitalize.mjs';
package/dist/index.d.ts CHANGED
@@ -81,4 +81,5 @@ export { camelCase } from './string/camelCase.js';
81
81
  export { snakeCase } from './string/snakeCase.js';
82
82
  export { kebabCase } from './string/kebabCase.js';
83
83
  export { lowerCase } from './string/lowerCase.js';
84
+ export { startCase } from './string/startCase.js';
84
85
  export { capitalize } from './string/capitalize.js';
package/dist/index.js CHANGED
@@ -94,6 +94,7 @@ __export(src_exports, {
94
94
  sampleSize: () => sampleSize,
95
95
  shuffle: () => shuffle,
96
96
  snakeCase: () => snakeCase,
97
+ startCase: () => startCase,
97
98
  sum: () => sum,
98
99
  sumBy: () => sumBy,
99
100
  tail: () => tail,
@@ -834,7 +835,9 @@ function pickBy(obj, shouldPick) {
834
835
  // src/object/invert.ts
835
836
  function invert(obj) {
836
837
  const result = {};
837
- for (const key in obj) {
838
+ const keys = Object.keys(obj);
839
+ for (let i = 0; i < keys.length; i++) {
840
+ const key = keys[i];
838
841
  const value = obj[key];
839
842
  result[value] = key;
840
843
  }
@@ -988,6 +991,23 @@ var lowerCase = (str) => {
988
991
  const words = getWords(str);
989
992
  return words.map((word) => word.toLowerCase()).join(" ");
990
993
  };
994
+
995
+ // src/string/startCase.ts
996
+ function startCase(str) {
997
+ const words = getWords(str.trim());
998
+ let result = "";
999
+ for (const word of words) {
1000
+ if (result) {
1001
+ result += " ";
1002
+ }
1003
+ if (word === word.toUpperCase()) {
1004
+ result += word;
1005
+ } else {
1006
+ result += word[0].toUpperCase() + word.slice(1).toLowerCase();
1007
+ }
1008
+ }
1009
+ return result;
1010
+ }
991
1011
  // Annotate the CommonJS export names for ESM import in node:
992
1012
  0 && (module.exports = {
993
1013
  AbortError,
@@ -1050,6 +1070,7 @@ var lowerCase = (str) => {
1050
1070
  sampleSize,
1051
1071
  shuffle,
1052
1072
  snakeCase,
1073
+ startCase,
1053
1074
  sum,
1054
1075
  sumBy,
1055
1076
  tail,