es-toolkit 1.9.0-dev.182 → 1.9.0-dev.184

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,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":[]}
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,