es-toolkit 1.9.0-dev.183 → 1.9.0-dev.185

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.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Returns a new array containing all elements except the last one from the input array.
3
+ * If the input array is empty or has only one element, the function returns an empty array.
4
+ *
5
+ * @template T The type of elements in the array.
6
+ * @param {T[]} arr - The input array to query.
7
+ * @returns {T[]} A new array containing all but the last element of the input array.
8
+ *
9
+ * @example
10
+ * const arr = [1, 2, 3, 4];
11
+ * const newArr = initial(arr);
12
+ * // newArr will be [1, 2, 3]
13
+ *
14
+ * @example
15
+ * const emptyArr: number[] = [];
16
+ * const newEmptyArr = initial(emptyArr);
17
+ * // newEmptyArr will be []
18
+ *
19
+ * @example
20
+ * const singleElementArr = ['only one'];
21
+ * const newSingleElementArr = initial(singleElementArr);
22
+ * // newSingleElementArr will be []
23
+ */
24
+ declare function initial<T>(arr: T[]): T[];
25
+
26
+ export { initial };
@@ -0,0 +1,36 @@
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/array/initial.ts
21
+ var initial_exports = {};
22
+ __export(initial_exports, {
23
+ initial: () => initial
24
+ });
25
+ module.exports = __toCommonJS(initial_exports);
26
+ function initial(arr) {
27
+ if (arr.length <= 1) {
28
+ return [];
29
+ }
30
+ return arr.slice(0, -1);
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ initial
35
+ });
36
+ //# sourceMappingURL=initial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array/initial.ts"],"sourcesContent":["/**\n * Returns a new array containing all elements except the last one from the input array.\n * If the input array is empty or has only one element, the function returns an empty array.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The input array to query.\n * @returns {T[]} A new array containing all but the last element of the input array.\n *\n * @example\n * const arr = [1, 2, 3, 4];\n * const newArr = initial(arr);\n * // newArr will be [1, 2, 3]\n *\n * @example\n * const emptyArr: number[] = [];\n * const newEmptyArr = initial(emptyArr);\n * // newEmptyArr will be []\n *\n * @example\n * const singleElementArr = ['only one'];\n * const newSingleElementArr = initial(singleElementArr);\n * // newSingleElementArr will be []\n */\nexport function initial<T>(arr: T[]): T[] {\n if (arr.length <= 1) {\n return [];\n }\n return arr.slice(0, -1);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBO,SAAS,QAAW,KAAe;AACxC,MAAI,IAAI,UAAU,GAAG;AACnB,WAAO,CAAC;AAAA,EACV;AACA,SAAO,IAAI,MAAM,GAAG,EAAE;AACxB;","names":[]}
@@ -0,0 +1,8 @@
1
+ import {
2
+ initial
3
+ } from "../chunk-XPSOKBRZ.mjs";
4
+ import "../chunk-2MM5EJJX.mjs";
5
+ export {
6
+ initial
7
+ };
8
+ //# sourceMappingURL=initial.mjs.map
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-2MRZANXZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,12 @@
1
+ // src/array/initial.ts
2
+ function initial(arr) {
3
+ if (arr.length <= 1) {
4
+ return [];
5
+ }
6
+ return arr.slice(0, -1);
7
+ }
8
+
9
+ export {
10
+ initial
11
+ };
12
+ //# sourceMappingURL=chunk-XPSOKBRZ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array/initial.ts"],"sourcesContent":["/**\n * Returns a new array containing all elements except the last one from the input array.\n * If the input array is empty or has only one element, the function returns an empty array.\n *\n * @template T The type of elements in the array.\n * @param {T[]} arr - The input array to query.\n * @returns {T[]} A new array containing all but the last element of the input array.\n *\n * @example\n * const arr = [1, 2, 3, 4];\n * const newArr = initial(arr);\n * // newArr will be [1, 2, 3]\n *\n * @example\n * const emptyArr: number[] = [];\n * const newEmptyArr = initial(emptyArr);\n * // newEmptyArr will be []\n *\n * @example\n * const singleElementArr = ['only one'];\n * const newSingleElementArr = initial(singleElementArr);\n * // newSingleElementArr will be []\n */\nexport function initial<T>(arr: T[]): T[] {\n if (arr.length <= 1) {\n return [];\n }\n return arr.slice(0, -1);\n}\n"],"mappings":";AAuBO,SAAS,QAAW,KAAe;AACxC,MAAI,IAAI,UAAU,GAAG;AACnB,WAAO,CAAC;AAAA,EACV;AACA,SAAO,IAAI,MAAM,GAAG,EAAE;AACxB;","names":[]}
@@ -1,4 +1,7 @@
1
1
  import "../chunk-N6EM6ETS.mjs";
2
+ import {
3
+ debounce
4
+ } from "../chunk-3IP4JVLL.mjs";
2
5
  import {
3
6
  noop
4
7
  } from "../chunk-LKXCOLNY.mjs";
@@ -8,9 +11,6 @@ import {
8
11
  import {
9
12
  throttle
10
13
  } from "../chunk-QOJGMVVR.mjs";
11
- import {
12
- debounce
13
- } from "../chunk-3IP4JVLL.mjs";
14
14
  import "../chunk-2MM5EJJX.mjs";
15
15
  export {
16
16
  debounce,
package/dist/index.d.mts CHANGED
@@ -47,6 +47,7 @@ export { head } from './array/head.mjs';
47
47
  export { tail } from './array/tail.mjs';
48
48
  export { toFilled } from './array/toFilled.mjs';
49
49
  export { last } from './array/last.mjs';
50
+ export { initial } from './array/initial.mjs';
50
51
  export { AbortError } from './error/AbortError.mjs';
51
52
  export { debounce } from './function/debounce.mjs';
52
53
  export { noop } from './function/noop.mjs';
package/dist/index.d.ts CHANGED
@@ -47,6 +47,7 @@ export { head } from './array/head.js';
47
47
  export { tail } from './array/tail.js';
48
48
  export { toFilled } from './array/toFilled.js';
49
49
  export { last } from './array/last.js';
50
+ export { initial } from './array/initial.js';
50
51
  export { AbortError } from './error/AbortError.js';
51
52
  export { debounce } from './function/debounce.js';
52
53
  export { noop } from './function/noop.js';
package/dist/index.js CHANGED
@@ -56,6 +56,7 @@ __export(src_exports, {
56
56
  groupBy: () => groupBy,
57
57
  head: () => head,
58
58
  inRange: () => inRange,
59
+ initial: () => initial,
59
60
  intersection: () => intersection,
60
61
  intersectionBy: () => intersectionBy,
61
62
  intersectionWith: () => intersectionWith,
@@ -618,6 +619,14 @@ function last(arr) {
618
619
  return arr[arr.length - 1];
619
620
  }
620
621
 
622
+ // src/array/initial.ts
623
+ function initial(arr) {
624
+ if (arr.length <= 1) {
625
+ return [];
626
+ }
627
+ return arr.slice(0, -1);
628
+ }
629
+
621
630
  // src/error/AbortError.ts
622
631
  var AbortError = class extends Error {
623
632
  constructor(message = "The operation was aborted") {
@@ -894,6 +903,7 @@ var capitalize = (str) => {
894
903
  groupBy,
895
904
  head,
896
905
  inRange,
906
+ initial,
897
907
  intersection,
898
908
  intersectionBy,
899
909
  intersectionWith,