es-toolkit 1.9.0-dev.172 → 1.9.0-dev.174

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 (58) 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 +7 -0
  4. package/dist/array/index.js.map +1 -1
  5. package/dist/array/index.mjs +17 -13
  6. package/dist/array/last.d.mts +25 -0
  7. package/dist/array/last.d.ts +25 -0
  8. package/dist/array/last.js +33 -0
  9. package/dist/array/last.js.map +1 -0
  10. package/dist/array/last.mjs +8 -0
  11. package/dist/chunk-2M3YVRFS.mjs +1 -0
  12. package/dist/chunk-2M3YVRFS.mjs.map +1 -0
  13. package/dist/chunk-KPBQ7OUY.mjs +9 -0
  14. package/dist/chunk-KPBQ7OUY.mjs.map +1 -0
  15. package/dist/chunk-T5URDZEQ.mjs +7 -0
  16. package/dist/chunk-T5URDZEQ.mjs.map +1 -0
  17. package/dist/chunk-VRFIBW4H.mjs +14 -0
  18. package/dist/chunk-VRFIBW4H.mjs.map +1 -0
  19. package/dist/chunk-WGIVYA3P.mjs +1 -0
  20. package/dist/chunk-WGIVYA3P.mjs.map +1 -0
  21. package/dist/chunk-YOFIBRET.mjs +1 -0
  22. package/dist/chunk-YOFIBRET.mjs.map +1 -0
  23. package/dist/constants/caseSplitPattern.d.mts +19 -0
  24. package/dist/constants/caseSplitPattern.d.ts +19 -0
  25. package/dist/constants/caseSplitPattern.js +31 -0
  26. package/dist/constants/caseSplitPattern.js.map +1 -0
  27. package/dist/constants/caseSplitPattern.mjs +8 -0
  28. package/dist/constants/caseSplitPattern.mjs.map +1 -0
  29. package/dist/constants/index.d.mts +1 -0
  30. package/dist/constants/index.d.ts +1 -0
  31. package/dist/constants/index.js +33 -0
  32. package/dist/constants/index.js.map +1 -0
  33. package/dist/constants/index.mjs +9 -0
  34. package/dist/constants/index.mjs.map +1 -0
  35. package/dist/function/index.mjs +6 -6
  36. package/dist/index.d.mts +2 -0
  37. package/dist/index.d.ts +2 -0
  38. package/dist/index.js +18 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/index.mjs +69 -58
  41. package/dist/math/index.mjs +3 -3
  42. package/dist/object/index.mjs +6 -6
  43. package/dist/string/index.d.mts +1 -0
  44. package/dist/string/index.d.ts +1 -0
  45. package/dist/string/index.js +39 -0
  46. package/dist/string/index.js.map +1 -0
  47. package/dist/string/index.mjs +11 -0
  48. package/dist/string/index.mjs.map +1 -0
  49. package/dist/string/snakeCase.d.mts +17 -0
  50. package/dist/string/snakeCase.d.ts +17 -0
  51. package/dist/string/snakeCase.js +39 -0
  52. package/dist/string/snakeCase.js.map +1 -0
  53. package/dist/string/snakeCase.mjs +10 -0
  54. package/dist/string/snakeCase.mjs.map +1 -0
  55. package/package.json +21 -1
  56. package/string.d.ts +1 -0
  57. package/dist/chunk-LOY6PATI.mjs +0 -1
  58. /package/dist/{chunk-LOY6PATI.mjs.map → array/last.mjs.map} +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/constants/caseSplitPattern.ts"],"sourcesContent":["/**\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 */\n\nexport const CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;\n"],"mappings":";AAiBO,IAAM,qBAAqB;","names":[]}
@@ -0,0 +1,14 @@
1
+ import {
2
+ CASE_SPLIT_PATTERN
3
+ } from "./chunk-T5URDZEQ.mjs";
4
+
5
+ // src/string/snakeCase.ts
6
+ var snakeCase = (str) => {
7
+ const splitWords = str.match(CASE_SPLIT_PATTERN) || [];
8
+ return splitWords.map((word) => word.toLowerCase()).join("_");
9
+ };
10
+
11
+ export {
12
+ snakeCase
13
+ };
14
+ //# sourceMappingURL=chunk-VRFIBW4H.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/string/snakeCase.ts"],"sourcesContent":["import { CASE_SPLIT_PATTERN } from '../constants';\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 splitWords = str.match(CASE_SPLIT_PATTERN) || [];\n return splitWords.map(word => word.toLowerCase()).join('_');\n};\n"],"mappings":";;;;;AAiBO,IAAM,YAAY,CAAC,QAAwB;AAChD,QAAM,aAAa,IAAI,MAAM,kBAAkB,KAAK,CAAC;AACrD,SAAO,WAAW,IAAI,UAAQ,KAAK,YAAY,CAAC,EAAE,KAAK,GAAG;AAC5D;","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-WGIVYA3P.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-YOFIBRET.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Regular expression pattern to split strings into words for various case conversions
3
+ *
4
+ * This pattern matchs sequences of characters in a string, considering the following case:
5
+ * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)
6
+ * - Sequences of one uppercase letter optionally followed by lowercase letters and digits
7
+ * - Single uppercase letters
8
+ * - Sequences of digis
9
+ *
10
+ * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into
11
+ * a consistent format like snake case.
12
+ *
13
+ * @example
14
+ * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);
15
+ * // matchs: ['camel', 'Case', 'HTTP', 'Request']
16
+ */
17
+ declare const CASE_SPLIT_PATTERN: RegExp;
18
+
19
+ export { CASE_SPLIT_PATTERN };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Regular expression pattern to split strings into words for various case conversions
3
+ *
4
+ * This pattern matchs sequences of characters in a string, considering the following case:
5
+ * - Sequences of two or more uppercase letters followed by an uppercase letter and lowercase letters or digits (for acronyms)
6
+ * - Sequences of one uppercase letter optionally followed by lowercase letters and digits
7
+ * - Single uppercase letters
8
+ * - Sequences of digis
9
+ *
10
+ * The resulting match can be used to convert camelCase, snake_case, kebab-case, and other mixed formats into
11
+ * a consistent format like snake case.
12
+ *
13
+ * @example
14
+ * const matches = 'camelCaseHTTPRequest'.match(CASE_SPLIT_PATTERN);
15
+ * // matchs: ['camel', 'Case', 'HTTP', 'Request']
16
+ */
17
+ declare const CASE_SPLIT_PATTERN: RegExp;
18
+
19
+ export { CASE_SPLIT_PATTERN };
@@ -0,0 +1,31 @@
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/constants/caseSplitPattern.ts
21
+ var caseSplitPattern_exports = {};
22
+ __export(caseSplitPattern_exports, {
23
+ CASE_SPLIT_PATTERN: () => CASE_SPLIT_PATTERN
24
+ });
25
+ module.exports = __toCommonJS(caseSplitPattern_exports);
26
+ var CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ CASE_SPLIT_PATTERN
30
+ });
31
+ //# sourceMappingURL=caseSplitPattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/constants/caseSplitPattern.ts"],"sourcesContent":["/**\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 */\n\nexport const CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,IAAM,qBAAqB;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ CASE_SPLIT_PATTERN
3
+ } from "../chunk-T5URDZEQ.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ CASE_SPLIT_PATTERN
7
+ };
8
+ //# sourceMappingURL=caseSplitPattern.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1 @@
1
+ export { CASE_SPLIT_PATTERN } from './caseSplitPattern.mjs';
@@ -0,0 +1 @@
1
+ export { CASE_SPLIT_PATTERN } from './caseSplitPattern.js';
@@ -0,0 +1,33 @@
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/constants/index.ts
21
+ var constants_exports = {};
22
+ __export(constants_exports, {
23
+ CASE_SPLIT_PATTERN: () => CASE_SPLIT_PATTERN
24
+ });
25
+ module.exports = __toCommonJS(constants_exports);
26
+
27
+ // src/constants/caseSplitPattern.ts
28
+ var CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ CASE_SPLIT_PATTERN
32
+ });
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/constants/index.ts","../../src/constants/caseSplitPattern.ts"],"sourcesContent":["export { CASE_SPLIT_PATTERN } from './caseSplitPattern';\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 */\n\nexport const CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,IAAM,qBAAqB;","names":[]}
@@ -0,0 +1,9 @@
1
+ import "../chunk-2M3YVRFS.mjs";
2
+ import {
3
+ CASE_SPLIT_PATTERN
4
+ } from "../chunk-T5URDZEQ.mjs";
5
+ import "../chunk-2MM5EJJX.mjs";
6
+ export {
7
+ CASE_SPLIT_PATTERN
8
+ };
9
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,16 +1,16 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
- import {
3
- debounce
4
- } from "../chunk-3IP4JVLL.mjs";
5
- import {
6
- noop
7
- } from "../chunk-LKXCOLNY.mjs";
8
2
  import {
9
3
  once
10
4
  } from "../chunk-CMBC4MXG.mjs";
11
5
  import {
12
6
  throttle
13
7
  } from "../chunk-QOJGMVVR.mjs";
8
+ import {
9
+ debounce
10
+ } from "../chunk-3IP4JVLL.mjs";
11
+ import {
12
+ noop
13
+ } from "../chunk-LKXCOLNY.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
package/dist/index.d.mts CHANGED
@@ -44,6 +44,7 @@ export { zipWith } from './array/zipWith.mjs';
44
44
  export { without } from './array/without.mjs';
45
45
  export { head } from './array/head.mjs';
46
46
  export { tail } from './array/tail.mjs';
47
+ export { last } from './array/last.mjs';
47
48
  export { AbortError } from './error/AbortError.mjs';
48
49
  export { debounce } from './function/debounce.mjs';
49
50
  export { noop } from './function/noop.mjs';
@@ -68,3 +69,4 @@ export { isNotNil } from './predicate/isNotNil.mjs';
68
69
  export { isNull } from './predicate/isNull.mjs';
69
70
  export { isUndefined } from './predicate/isUndefined.mjs';
70
71
  export { delay } from './promise/delay.mjs';
72
+ export { snakeCase } from './string/snakeCase.mjs';
package/dist/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { zipWith } from './array/zipWith.js';
44
44
  export { without } from './array/without.js';
45
45
  export { head } from './array/head.js';
46
46
  export { tail } from './array/tail.js';
47
+ export { last } from './array/last.js';
47
48
  export { AbortError } from './error/AbortError.js';
48
49
  export { debounce } from './function/debounce.js';
49
50
  export { noop } from './function/noop.js';
@@ -68,3 +69,4 @@ export { isNotNil } from './predicate/isNotNil.js';
68
69
  export { isNull } from './predicate/isNull.js';
69
70
  export { isUndefined } from './predicate/isUndefined.js';
70
71
  export { delay } from './promise/delay.js';
72
+ export { snakeCase } from './string/snakeCase.js';
package/dist/index.js CHANGED
@@ -63,6 +63,7 @@ __export(src_exports, {
63
63
  isNull: () => isNull,
64
64
  isUndefined: () => isUndefined,
65
65
  keyBy: () => keyBy,
66
+ last: () => last,
66
67
  maxBy: () => maxBy,
67
68
  mean: () => mean,
68
69
  meanBy: () => meanBy,
@@ -82,6 +83,7 @@ __export(src_exports, {
82
83
  sample: () => sample,
83
84
  sampleSize: () => sampleSize,
84
85
  shuffle: () => shuffle,
86
+ snakeCase: () => snakeCase,
85
87
  sum: () => sum,
86
88
  tail: () => tail,
87
89
  take: () => take,
@@ -589,6 +591,11 @@ function tail(arr) {
589
591
  return result;
590
592
  }
591
593
 
594
+ // src/array/last.ts
595
+ function last(arr) {
596
+ return arr[arr.length - 1];
597
+ }
598
+
592
599
  // src/error/AbortError.ts
593
600
  var AbortError = class extends Error {
594
601
  constructor(message = "The operation was aborted") {
@@ -815,6 +822,15 @@ function delay(ms, { signal } = {}) {
815
822
  signal == null ? void 0 : signal.addEventListener("abort", abortHandler, { once: true });
816
823
  });
817
824
  }
825
+
826
+ // src/constants/caseSplitPattern.ts
827
+ var CASE_SPLIT_PATTERN = /[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g;
828
+
829
+ // src/string/snakeCase.ts
830
+ var snakeCase = (str) => {
831
+ const splitWords = str.match(CASE_SPLIT_PATTERN) || [];
832
+ return splitWords.map((word) => word.toLowerCase()).join("_");
833
+ };
818
834
  // Annotate the CommonJS export names for ESM import in node:
819
835
  0 && (module.exports = {
820
836
  AbortError,
@@ -846,6 +862,7 @@ function delay(ms, { signal } = {}) {
846
862
  isNull,
847
863
  isUndefined,
848
864
  keyBy,
865
+ last,
849
866
  maxBy,
850
867
  mean,
851
868
  meanBy,
@@ -865,6 +882,7 @@ function delay(ms, { signal } = {}) {
865
882
  sample,
866
883
  sampleSize,
867
884
  shuffle,
885
+ snakeCase,
868
886
  sum,
869
887
  tail,
870
888
  take,