@rimbu/base 1.1.0 → 2.0.1

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,33 @@
1
+ import { TraverseState, Update, type ArrayNonEmpty } from '@rimbu/common';
2
+ export declare function _appendNew<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
3
+ export declare function _appendOld<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
4
+ export declare const append: typeof _appendNew;
5
+ export declare function concat<T>(first: readonly T[], second: readonly T[]): readonly T[];
6
+ export declare function _reverseNew<T>(array: readonly T[], start?: number, end?: number): T[];
7
+ export declare function _reverseOld<T>(array: readonly T[], start?: number, end?: number): T[];
8
+ export declare const reverse: typeof _reverseNew;
9
+ export declare function forEach<T>(array: readonly T[], f: (value: T, index: number, halt: () => void) => void, state?: TraverseState, reversed?: boolean): void;
10
+ export declare function map<T, R>(array: readonly T[], f: (value: T, index: number) => R, indexOffset?: number): R[];
11
+ export declare function reverseMap<T, R>(array: readonly T[], f: (value: T, index: number) => R, indexOffset?: number): R[];
12
+ export declare function _prependNew<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
13
+ export declare function _prependOld<T>(array: readonly T[], value: T): ArrayNonEmpty<T>;
14
+ export declare const prepend: typeof _prependNew;
15
+ export declare function _lastNew<T>(arr: readonly T[]): T;
16
+ export declare function _lastOld<T>(arr: readonly T[]): T;
17
+ export declare const last: typeof _lastNew;
18
+ export declare function _updateNew<T>(arr: readonly T[], index: number, updater: Update<T>): readonly T[];
19
+ export declare function _updateOld<T>(arr: readonly T[], index: number, updater: Update<T>): readonly T[];
20
+ export declare const update: typeof _updateNew;
21
+ export declare function _modNew<T>(arr: readonly T[], index: number, f: (value: T) => T): readonly T[];
22
+ export declare function _modOld<T>(arr: readonly T[], index: number, f: (value: T) => T): readonly T[];
23
+ export declare const mod: typeof _modNew;
24
+ export declare function _insertNew<T>(arr: readonly T[], index: number, value: T): T[];
25
+ export declare function _insertOld<T>(arr: readonly T[], index: number, value: T): T[];
26
+ export declare const insert: typeof _insertNew;
27
+ export declare function tail<T>(arr: readonly T[]): T[];
28
+ export declare function init<T>(arr: readonly T[]): T[];
29
+ export declare function _spliceNew<T>(arr: readonly T[], start: number, deleteCount: number, ...items: T[]): T[];
30
+ export declare function _spliceOld<T>(arr: readonly T[], start: number, deleteCount: number, ...items: T[]): T[];
31
+ export declare const splice: typeof _spliceNew;
32
+ export declare function copySparse<T>(arr: readonly T[]): T[];
33
+ export declare function mapSparse<T, T2>(arr: readonly T[], f: (value: T, index: number) => T2): T2[];
package/dist/esm/arr.mjs CHANGED
@@ -1,10 +1,14 @@
1
- import { Update, TraverseState } from '@rimbu/common';
2
- // Returns a copy of the array with the given value appended
3
- export function append(array, value) {
1
+ import { TraverseState, Update } from '@rimbu/common';
2
+ export function _appendNew(array, value) {
3
+ return array.toSpliced(array.length, 0, value);
4
+ }
5
+ export function _appendOld(array, value) {
4
6
  const clone = array.slice();
5
7
  clone.push(value);
6
8
  return clone;
7
9
  }
10
+ // Returns a copy of the array with the given value appended
11
+ export const append = `toSpliced` in Array.prototype ? _appendNew : _appendOld;
8
12
  // Returns the concatenation of the two arrays, potentially reusing the input array if one of the arrays is empty
9
13
  export function concat(first, second) {
10
14
  if (first.length === 0)
@@ -13,16 +17,25 @@ export function concat(first, second) {
13
17
  return first;
14
18
  return first.concat(second);
15
19
  }
16
- // Returns an copy of the array between the start and end indices, with the elements in reversed order.
17
- export function reverse(array, start = 0, end = array.length - 1) {
18
- const length = end - start + 1;
20
+ export function _reverseNew(array, start, end) {
21
+ const source = undefined !== start || undefined !== end
22
+ ? array.slice(start ?? 0, (end ?? array.length - 1) + 1)
23
+ : array;
24
+ return source.toReversed();
25
+ }
26
+ export function _reverseOld(array, start, end) {
27
+ const _start = start ?? 0;
28
+ const _end = end ?? array.length - 1;
29
+ const length = _end - _start + 1;
19
30
  const res = [];
20
- let arrayIndex = start - 1;
31
+ let arrayIndex = _start - 1;
21
32
  let resIndex = length - 1;
22
- while (++arrayIndex <= end)
33
+ while (++arrayIndex <= _end)
23
34
  res[resIndex--] = array[arrayIndex];
24
35
  return res;
25
36
  }
37
+ // Returns an copy of the array between the start and end indices, with the elements in reversed order.
38
+ export const reverse = 'toReversed' in Array.prototype ? _reverseNew : _reverseOld;
26
39
  // Performs given function on each element of the array, in reverse order if 'reversed' is true.
27
40
  export function forEach(array, f, state = TraverseState(), reversed = false) {
28
41
  if (state.halted)
@@ -44,6 +57,10 @@ export function forEach(array, f, state = TraverseState(), reversed = false) {
44
57
  }
45
58
  // Returns a copy of the array where given function is applied to each element
46
59
  export function map(array, f, indexOffset = 0) {
60
+ if (indexOffset === 0) {
61
+ // without offset, can use standard array map
62
+ return array.map(f);
63
+ }
47
64
  const result = [];
48
65
  let index = indexOffset;
49
66
  let i = -1;
@@ -63,48 +80,88 @@ export function reverseMap(array, f, indexOffset = 0) {
63
80
  result[resultIndex++] = f(array[arrayIndex], index++);
64
81
  return result;
65
82
  }
66
- // Returns a copy of the given array with the given value added at the start
67
- export function prepend(array, value) {
83
+ export function _prependNew(array, value) {
84
+ return array.toSpliced(0, 0, value);
85
+ }
86
+ export function _prependOld(array, value) {
68
87
  const clone = array.slice();
69
88
  clone.unshift(value);
70
89
  return clone;
71
90
  }
72
- // Returns the last element of the array
73
- export function last(arr) {
91
+ // Returns a copy of the given array with the given value added at the start
92
+ export const prepend = `toSpliced` in Array.prototype ? _prependNew : _prependOld;
93
+ export function _lastNew(arr) {
94
+ return arr.at(-1);
95
+ }
96
+ export function _lastOld(arr) {
74
97
  return arr[arr.length - 1];
75
98
  }
76
- // Returns a copy of the array where the element at given index is replaced by the given updater.
77
- // If the new element is the same as the old element, the original array is returned
78
- export function update(arr, index, updater) {
79
- if (index < 0 || index >= arr.length)
99
+ // Returns the last element of the array
100
+ export const last = `at` in Array.prototype ? _lastNew : _lastOld;
101
+ export function _updateNew(arr, index, updater) {
102
+ if (index < 0 || index >= arr.length) {
80
103
  return arr;
104
+ }
81
105
  const curValue = arr[index];
82
106
  const newValue = Update(curValue, updater);
83
- if (Object.is(newValue, curValue))
107
+ if (Object.is(newValue, curValue)) {
84
108
  return arr;
109
+ }
110
+ return arr.with(index, newValue);
111
+ }
112
+ export function _updateOld(arr, index, updater) {
113
+ if (index < 0 || index >= arr.length) {
114
+ return arr;
115
+ }
116
+ const curValue = arr[index];
117
+ const newValue = Update(curValue, updater);
118
+ if (Object.is(newValue, curValue)) {
119
+ return arr;
120
+ }
85
121
  const newArr = arr.slice();
86
122
  newArr[index] = newValue;
87
123
  return newArr;
88
124
  }
89
- // Returns a copy of the array where the element at given index is replaced by applying given function.
125
+ // Returns a copy of the array where the element at given index is replaced by the given updater.
90
126
  // If the new element is the same as the old element, the original array is returned
91
- export function mod(arr, index, f) {
92
- if (index < 0 || index >= arr.length)
127
+ export const update = `with` in Array.prototype ? _updateNew : _updateOld;
128
+ export function _modNew(arr, index, f) {
129
+ if (index < 0 || index >= arr.length) {
93
130
  return arr;
131
+ }
94
132
  const curValue = arr[index];
95
133
  const newValue = f(curValue);
96
- if (Object.is(newValue, curValue))
134
+ if (Object.is(newValue, curValue)) {
97
135
  return arr;
136
+ }
137
+ return arr.with(index, newValue);
138
+ }
139
+ export function _modOld(arr, index, f) {
140
+ if (index < 0 || index >= arr.length) {
141
+ return arr;
142
+ }
143
+ const curValue = arr[index];
144
+ const newValue = f(curValue);
145
+ if (Object.is(newValue, curValue)) {
146
+ return arr;
147
+ }
98
148
  const newArr = arr.slice();
99
149
  newArr[index] = newValue;
100
150
  return newArr;
101
151
  }
102
- // Returns a copy of the array where at given index the given value is inserted
103
- export function insert(arr, index, value) {
152
+ // Returns a copy of the array where the element at given index is replaced by applying given function.
153
+ // If the new element is the same as the old element, the original array is returned
154
+ export const mod = `with` in Array.prototype ? _modNew : _modOld;
155
+ export function _insertNew(arr, index, value) {
156
+ return arr.toSpliced(index, 0, value);
157
+ }
158
+ export function _insertOld(arr, index, value) {
104
159
  const clone = arr.slice();
105
160
  clone.splice(index, 0, value);
106
161
  return clone;
107
162
  }
163
+ // Returns a copy of the array where at given index the given value is inserted
164
+ export const insert = `toSpliced` in Array.prototype ? _insertNew : _insertOld;
108
165
  // Returns a copy of the array, without its first element
109
166
  export function tail(arr) {
110
167
  return arr.slice(1);
@@ -113,12 +170,16 @@ export function tail(arr) {
113
170
  export function init(arr) {
114
171
  return arr.slice(0, arr.length - 1);
115
172
  }
116
- // Immutable version of the array .splice command, always returns a new array
117
- export function splice(arr, start, deleteCount, ...items) {
173
+ export function _spliceNew(arr, start, deleteCount, ...items) {
174
+ return arr.toSpliced(start, deleteCount, ...items);
175
+ }
176
+ export function _spliceOld(arr, start, deleteCount, ...items) {
118
177
  const clone = arr.slice();
119
178
  clone.splice(start, deleteCount, ...items);
120
179
  return clone;
121
180
  }
181
+ // Immutable version of the array .splice command, always returns a new array
182
+ export const splice = `toSpliced` in Array.prototype ? _spliceNew : _spliceOld;
122
183
  // Returns a copy of the array, where its 'sparse' property is kept (sparse = not all indices have a value)
123
184
  export function copySparse(arr) {
124
185
  const clone = [];
@@ -1 +1 @@
1
- {"version":3,"file":"arr.mjs","sourceRoot":"","sources":["../../src/arr.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAsB,MAAM,eAAe,CAAC;AAE1E,4DAA4D;AAC5D,MAAM,UAAU,MAAM,CAAI,KAAmB,EAAE,KAAQ;IACrD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;IAC5B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,OAAO,KAAyB,CAAC;AACnC,CAAC;AAED,iHAAiH;AACjH,MAAM,UAAU,MAAM,CACpB,KAAmB,EACnB,MAAoB;IAEpB,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC;IACtC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtC,OAAO,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GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAU,CAAC,CAAC;IACxC,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function first<K, V>(entry: readonly [K, V]): K;
2
+ export declare function second<K, V>(entry: readonly [K, V]): V;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Matches any type of function
3
+ */
4
+ export type AnyFunc = (...args: any[]) => any;
5
+ /**
6
+ * Gives true if the given type T is a function, false otherwise.
7
+ * @typeparam T - the input type
8
+ */
9
+ export type IsAnyFunc<T> = AnyFunc extends T ? true : false;
10
+ /**
11
+ * A predicate type for any record that resolves to true if any of the record
12
+ * properties is a function, false otherwise.
13
+ * This is useful to have a coarse discrimination between pure data objects and class instances.
14
+ * @typeparam T - the input type
15
+ */
16
+ export type IsObjWithoutFunctions<T> = AnyFunc extends T[keyof T] ? false : true;
17
+ /**
18
+ * A predicate type that resolves to true if the given type satisfies:
19
+ * - it is an object type (not a primitive)
20
+ * - it is not a function
21
+ * - it is not iterable
22
+ * - it does not have any properties that are functions
23
+ * Otherwise, it resolves to false
24
+ * @typeparam T - the input type
25
+ */
26
+ export type IsPlainObj<T> = T extends null | undefined | number | string | boolean | bigint | symbol | AnyFunc | Iterable<any> | AsyncIterable<any> ? false : IsObjWithoutFunctions<T>;
27
+ /**
28
+ * Utility type that will only accept objects that are considered 'plain objects' according
29
+ * to the `IsPlainObj` predicate type.
30
+ * @typeparam T - the value type to test
31
+ */
32
+ export type PlainObj<T> = IsPlainObj<T> extends true ? T : never;
33
+ /**
34
+ * Utility type that will only return true if the input type T is equal to `any`.
35
+ * @typeparam T - the value type to test
36
+ */
37
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
38
+ /**
39
+ * Utility type that will only return true if the input type T is a (readonly) array.
40
+ * @typeparm T - the value type to test
41
+ */
42
+ export type IsArray<T> = T extends readonly any[] ? true : false;
43
+ /**
44
+ * Utility type to exclude any types that are iterable. Useful in cases where
45
+ * plain objects are required as inputs but not arrays.
46
+ */
47
+ export type NotIterable = {
48
+ [Symbol.iterator]?: never;
49
+ };
50
+ /**
51
+ * Companion function to the `IsRecord<T>` type that checks whether the given object is a pure
52
+ * data object.
53
+ * @param obj - the object to check
54
+ * @returns true if the given object is a pure data object
55
+ * @note does not check whether a record's properties are not functions
56
+ */
57
+ export declare function isPlainObj(obj: any): obj is object;
58
+ /**
59
+ * Returns true if the given object is Iterable
60
+ * @param obj - the object to check
61
+ */
62
+ export declare function isIterable(obj: any): obj is Iterable<unknown>;
@@ -0,0 +1,16 @@
1
+ import { ErrBase } from '@rimbu/common';
2
+ export declare class EmptyCollectionAssumedNonEmptyError extends ErrBase.CustomError {
3
+ constructor();
4
+ }
5
+ export declare class ModifiedBuilderWhileLoopingOverItError extends ErrBase.CustomError {
6
+ constructor();
7
+ }
8
+ export declare class InvalidStateError extends ErrBase.CustomError {
9
+ constructor();
10
+ }
11
+ export declare class InvalidUsageError extends ErrBase.CustomError {
12
+ }
13
+ export declare function throwEmptyCollectionAssumedNonEmptyError(): never;
14
+ export declare function throwModifiedBuilderWhileLoopingOverItError(): never;
15
+ export declare function throwInvalidStateError(): never;
16
+ export declare function throwInvalidUsageError(msg: string): never;
@@ -0,0 +1,2 @@
1
+ export declare const Token: unique symbol;
2
+ export type Token = typeof Token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimbu/base",
3
- "version": "1.1.0",
3
+ "version": "2.0.1",
4
4
  "description": "Utilities to implement Rimbu collections",
5
5
  "keywords": [
6
6
  "array",
@@ -29,14 +29,18 @@
29
29
  "type": "module",
30
30
  "main": "./dist/cjs/index.cjs",
31
31
  "module": "./dist/esm/index.mjs",
32
- "types": "./dist/types/index.d.mts",
32
+ "types": "./dist/cjs/index.d.cts",
33
33
  "exports": {
34
34
  ".": {
35
- "types": "./dist/types/index.d.mts",
36
- "bun": "./dist/bun/index.mts",
37
- "import": "./dist/esm/index.mjs",
38
- "require": "./dist/cjs/index.cjs",
39
- "default": "./dist/esm/index.mjs"
35
+ "import": {
36
+ "types": "./dist/esm/index.d.mts",
37
+ "default": "./dist/esm/index.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./dist/cjs/index.d.cts",
41
+ "default": "./dist/cjs/index.cjs"
42
+ },
43
+ "bun": "./dist/bun/main/index.mts"
40
44
  }
41
45
  },
42
46
  "files": [
@@ -46,15 +50,17 @@
46
50
  "scripts": {
47
51
  "build": "yarn clean && yarn bundle",
48
52
  "build:deno": "yarn bundle:deno-prepare && yarn bundle:deno-convert && yarn bundle:deno-move && yarn bundle:deno-clean",
49
- "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:types && yarn bundle:bun",
50
- "bundle:bun": "node ../../config/bunnify.mjs",
51
- "bundle:cjs": "tsup src --format cjs --clean -d dist/cjs --loader '.mts=ts'",
53
+ "bundle": "yarn bundle:cjs && yarn bundle:esm && yarn bundle:bun",
54
+ "bundle:bun": "node ../../config/bunnify.mjs -mode bun",
55
+ "bundle:cjs": "yarn bundle:cjs-prepare && yarn bundle:cjs-build && yarn bundle:cjs-clean",
56
+ "bundle:cjs-prepare": "node ../../config/bunnify.mjs -mode cjs",
57
+ "bundle:cjs-build": "tsc -p tsconfig.cjs.json",
58
+ "bundle:cjs-clean": "rimraf _cjs_prepare",
52
59
  "bundle:deno-prepare": "node ../../config/prepare-denoify.mjs",
53
60
  "bundle:deno-convert": "denoify --src _deno_prepare/src",
54
61
  "bundle:deno-move": "rimraf ../../deno_dist/base && mv deno_dist ../../deno_dist/base",
55
62
  "bundle:deno-clean": "rimraf _deno_prepare",
56
63
  "bundle:esm": "tsc --p tsconfig.esm.json",
57
- "bundle:types": "tsc --p tsconfig.types.json",
58
64
  "clean": "rimraf dist",
59
65
  "format": "yarn format:base --write",
60
66
  "format:base": "prettier \"{!CHANGELOG.md}|**/**/*.{ts,tsx,js,mts,mjs,json,md}\"",
@@ -67,11 +73,10 @@
67
73
  "typecheck": "tsc"
68
74
  },
69
75
  "dependencies": {
70
- "@rimbu/common": "^1.1.0",
71
- "tslib": "^2.6.1"
76
+ "@rimbu/common": "^2.0.1"
72
77
  },
73
78
  "publishConfig": {
74
79
  "access": "public"
75
80
  },
76
- "gitHead": "f0a61c7e2ba7ecc76dd56a57a9fe7e6ae059eb59"
81
+ "gitHead": "b7ed656d2c55d1a715d6a3f52e364e68cb98c759"
77
82
  }