@bodil/monkey-business 0.2.0 → 0.2.2
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.
- package/dist/index.d.ts +26 -4
- package/dist/index.js +13 -25
- package/dist/index.js.map +1 -1
- package/package.json +22 -11
- package/src/index.test.ts +1 -1
- package/src/index.ts +37 -29
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { Option } from "@bodil/
|
|
1
|
+
import { Option } from "@bodil/opt";
|
|
2
2
|
import { type OrderFn } from "@bodil/core/order";
|
|
3
3
|
import type { Present } from "@bodil/core/types";
|
|
4
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
5
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
6
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
4
7
|
declare global {
|
|
8
|
+
/**
|
|
9
|
+
* Added methods on the {@link Object} global object.
|
|
10
|
+
*/
|
|
5
11
|
interface ObjectConstructor {
|
|
6
12
|
/**
|
|
7
13
|
* Checked key lookup. Returns {@link None} if a key isn't present.
|
|
@@ -15,6 +21,9 @@ declare global {
|
|
|
15
21
|
*/
|
|
16
22
|
mapEntries<A, B>(obj: Record<string, A>, fn: (entry: [key: string, value: A]) => [string, B]): Record<string, B>;
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Added methods on {@link Map}s.
|
|
26
|
+
*/
|
|
18
27
|
interface Map<K, V> {
|
|
19
28
|
/**
|
|
20
29
|
* If `key` exists in the map, return the value associated with it.
|
|
@@ -23,6 +32,9 @@ declare global {
|
|
|
23
32
|
*/
|
|
24
33
|
getOrSet(key: K, defaultValue: () => V): V;
|
|
25
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Added methods on {@link Array}s.
|
|
37
|
+
*/
|
|
26
38
|
interface Array<T> {
|
|
27
39
|
/**
|
|
28
40
|
* Insert `value` at `index` in the array.
|
|
@@ -77,6 +89,9 @@ declare global {
|
|
|
77
89
|
*/
|
|
78
90
|
get(index: number): Option<T>;
|
|
79
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Added methods on the {@link Iterator} global object.
|
|
94
|
+
*/
|
|
80
95
|
interface IteratorConstructor {
|
|
81
96
|
/**
|
|
82
97
|
* Construct an empty iterator.
|
|
@@ -84,22 +99,29 @@ declare global {
|
|
|
84
99
|
empty<T>(): IteratorObject<T>;
|
|
85
100
|
/**
|
|
86
101
|
* Sequence multiple iterators into a single one.
|
|
87
|
-
*
|
|
102
|
+
* @see https://github.com/tc39/proposal-iterator-sequencing
|
|
88
103
|
*/
|
|
89
104
|
concat<T>(...inputs: Array<Iterable<T>>): IteratorObject<T>;
|
|
105
|
+
/**
|
|
106
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
107
|
+
*/
|
|
108
|
+
zip<T>(inputs: Iterable<Iterable<T>>): IteratorObject<Array<T>>;
|
|
109
|
+
/**
|
|
110
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
111
|
+
*/
|
|
112
|
+
zipKeyed<T>(inputs: Record<string, Iterable<T>>): IteratorObject<Record<string, T>>;
|
|
90
113
|
}
|
|
91
114
|
interface IteratorObject<T, TReturn, TNext> {
|
|
92
115
|
/**
|
|
93
116
|
* Get the next value from the iterator, wrapped in an {@link Option}
|
|
94
117
|
* type. If the iterator has no more values, return {@link None}.
|
|
95
|
-
*
|
|
96
|
-
* This is the nicely utility typed version of {@link Iterator#next}.
|
|
97
118
|
*/
|
|
98
119
|
takeOne(): Option<T>;
|
|
99
120
|
/**
|
|
100
121
|
* Take items from the iterator only until the first time `predicate` returns false.
|
|
101
122
|
*/
|
|
102
123
|
takeWhile<S extends T>(predicate: (value: T, index: number) => value is S): IteratorObject<S, undefined>;
|
|
124
|
+
/** @ignore */
|
|
103
125
|
takeWhile(predicate: (value: T, index: number) => boolean): IteratorObject<T, undefined>;
|
|
104
126
|
/**
|
|
105
127
|
* Ignore all items matching `predicate` until the first item that
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
2
2
|
// deno-lint-ignore-file no-this-alias
|
|
3
|
-
import { None, Option, Some } from "@bodil/
|
|
3
|
+
import { None, Option, Some } from "@bodil/opt";
|
|
4
4
|
import { bisectHigh, bisectLow } from "@bodil/core/order";
|
|
5
5
|
import { assert } from "@bodil/core/assert";
|
|
6
6
|
import defineProperties from "define-properties";
|
|
7
|
+
import shimUnscopables from "es-shim-unscopables";
|
|
8
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
9
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
10
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
7
11
|
// Object
|
|
8
12
|
defineProperties(Object, {
|
|
9
13
|
get(obj, key) {
|
|
@@ -66,35 +70,19 @@ defineProperties(Array.prototype, {
|
|
|
66
70
|
return Object.get(this, index);
|
|
67
71
|
},
|
|
68
72
|
});
|
|
73
|
+
shimUnscopables("remove");
|
|
74
|
+
shimUnscopables("removeFn");
|
|
75
|
+
shimUnscopables("removeIndex");
|
|
76
|
+
shimUnscopables("insert");
|
|
77
|
+
shimUnscopables("insertOrdered");
|
|
78
|
+
shimUnscopables("present");
|
|
79
|
+
shimUnscopables("nonNullable");
|
|
80
|
+
shimUnscopables("get");
|
|
69
81
|
// Iterator
|
|
70
82
|
defineProperties(Iterator, {
|
|
71
83
|
empty() {
|
|
72
84
|
return Iterator.from([]);
|
|
73
85
|
},
|
|
74
|
-
concat(...inputs) {
|
|
75
|
-
if (inputs.length === 0) {
|
|
76
|
-
return Iterator.empty();
|
|
77
|
-
}
|
|
78
|
-
let iter = inputs[0][Symbol.iterator]();
|
|
79
|
-
let index = 0;
|
|
80
|
-
let done = false;
|
|
81
|
-
return Iterator.from({
|
|
82
|
-
next() {
|
|
83
|
-
if (!done) {
|
|
84
|
-
let result = iter.next();
|
|
85
|
-
while (result.done === true && index < inputs.length - 1) {
|
|
86
|
-
iter = inputs[++index][Symbol.iterator]();
|
|
87
|
-
result = iter.next();
|
|
88
|
-
}
|
|
89
|
-
if (result.done !== true) {
|
|
90
|
-
return result;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
done = true;
|
|
94
|
-
return { done: true, value: undefined };
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
86
|
});
|
|
99
87
|
defineProperties(Iterator.prototype, {
|
|
100
88
|
takeOne() {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sCAAsC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,sCAAsC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EAAgB,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AACjD,OAAO,eAAe,MAAM,qBAAqB,CAAC;AAElD,OAAO,0CAA0C,CAAC;AAClD,OAAO,uCAAuC,CAAC;AAC/C,OAAO,4CAA4C,CAAC;AA6KpD,SAAS;AAET,gBAAgB,CAAC,MAAM,EAAE;IACrB,GAAG,CAAsC,GAAM,EAAE,GAAM;QACnD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3D,CAAC;IAED,UAAU,CACN,GAAsB,EAC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,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC;YACpD,QAAQ,IAAI,IAAI,CAAC;QACrB,CAAC;QACD,MAAM,CAAC,QAAQ,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC;QAClC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,OAAO;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAsB,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;IACxF,CAAC;IAED,WAAW;QACP,OAAO,QAAQ,CAAC,IAAI,CAChB,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAA0B,EAAE,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,CAAC,CACrF,CAAC;IACN,CAAC;CACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bodil/monkey-business",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Let's give JS core types a polish",
|
|
5
5
|
"homepage": "https://codeberg.org/bodil/monkey-business",
|
|
6
6
|
"repository": {
|
|
@@ -26,27 +26,38 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@bodil/core": "^0.
|
|
29
|
+
"@bodil/core": "^0.4.0",
|
|
30
|
+
"@bodil/opt": "^0.4.1",
|
|
30
31
|
"@types/define-properties": "^1.1.5",
|
|
31
|
-
"define-properties": "^1.2.1"
|
|
32
|
+
"define-properties": "^1.2.1",
|
|
33
|
+
"es-iterator-helpers": "^1.2.1",
|
|
34
|
+
"es-shim-unscopables": "^1.1.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@bodil/opt-vitest": "^1.
|
|
37
|
+
"@bodil/opt-vitest": "^1.1.0",
|
|
35
38
|
"@eslint/eslintrc": "^3.3.1",
|
|
36
|
-
"@eslint/js": "^9.
|
|
37
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
38
|
-
"@typescript-eslint/parser": "^8.
|
|
39
|
-
"eslint": "^9.
|
|
39
|
+
"@eslint/js": "^9.34.0",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.41.0",
|
|
41
|
+
"@typescript-eslint/parser": "^8.41.0",
|
|
42
|
+
"eslint": "^9.34.0",
|
|
40
43
|
"eslint-config-prettier": "^10.1.8",
|
|
41
|
-
"eslint-plugin-jsdoc": "^
|
|
42
|
-
"globals": "^
|
|
44
|
+
"eslint-plugin-jsdoc": "^54.1.1",
|
|
45
|
+
"globals": "^16.3.0",
|
|
46
|
+
"npm-run-all2": "^8.0.4",
|
|
47
|
+
"typedoc": "^0.28.11",
|
|
48
|
+
"typedoc-plugin-extras": "^4.0.1",
|
|
49
|
+
"typedoc-plugin-mdn-links": "^5.0.9",
|
|
43
50
|
"typescript": "^5.9.2",
|
|
44
51
|
"vitest": "^3.2.4"
|
|
45
52
|
},
|
|
46
53
|
"scripts": {
|
|
47
54
|
"build": "tsc",
|
|
48
55
|
"test": "vitest --run",
|
|
49
|
-
"
|
|
56
|
+
"check:eslint": "eslint src",
|
|
57
|
+
"check:tsc": "tsc --noEmit",
|
|
58
|
+
"check": "run-p check:tsc check:eslint",
|
|
59
|
+
"doc": "typedoc",
|
|
60
|
+
"doc:readthedocs": "typedoc --out $READTHEDOCS_OUTPUT/html",
|
|
50
61
|
"prepublish": "tsc"
|
|
51
62
|
}
|
|
52
63
|
}
|
package/src/index.test.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-this-alias */
|
|
2
2
|
// deno-lint-ignore-file no-this-alias
|
|
3
3
|
|
|
4
|
-
import { None, Option, Some } from "@bodil/
|
|
4
|
+
import { None, Option, Some } from "@bodil/opt";
|
|
5
5
|
import { type OrderFn, bisectHigh, bisectLow } from "@bodil/core/order";
|
|
6
6
|
import type { Present } from "@bodil/core/types";
|
|
7
7
|
import { assert } from "@bodil/core/assert";
|
|
8
8
|
import defineProperties from "define-properties";
|
|
9
|
+
import shimUnscopables from "es-shim-unscopables";
|
|
10
|
+
|
|
11
|
+
import "es-iterator-helpers/Iterator.concat/auto";
|
|
12
|
+
import "es-iterator-helpers/Iterator.zip/auto";
|
|
13
|
+
import "es-iterator-helpers/Iterator.zipKeyed/auto";
|
|
9
14
|
|
|
10
15
|
declare global {
|
|
16
|
+
/**
|
|
17
|
+
* Added methods on the {@link Object} global object.
|
|
18
|
+
*/
|
|
11
19
|
interface ObjectConstructor {
|
|
12
20
|
/**
|
|
13
21
|
* Checked key lookup. Returns {@link None} if a key isn't present.
|
|
@@ -26,6 +34,9 @@ declare global {
|
|
|
26
34
|
): Record<string, B>;
|
|
27
35
|
}
|
|
28
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Added methods on {@link Map}s.
|
|
39
|
+
*/
|
|
29
40
|
interface Map<K, V> {
|
|
30
41
|
/**
|
|
31
42
|
* If `key` exists in the map, return the value associated with it.
|
|
@@ -35,6 +46,9 @@ declare global {
|
|
|
35
46
|
getOrSet(key: K, defaultValue: () => V): V;
|
|
36
47
|
}
|
|
37
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Added methods on {@link Array}s.
|
|
51
|
+
*/
|
|
38
52
|
interface Array<T> {
|
|
39
53
|
/**
|
|
40
54
|
* Insert `value` at `index` in the array.
|
|
@@ -97,6 +111,9 @@ declare global {
|
|
|
97
111
|
get(index: number): Option<T>;
|
|
98
112
|
}
|
|
99
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Added methods on the {@link Iterator} global object.
|
|
116
|
+
*/
|
|
100
117
|
interface IteratorConstructor {
|
|
101
118
|
/**
|
|
102
119
|
* Construct an empty iterator.
|
|
@@ -104,9 +121,17 @@ declare global {
|
|
|
104
121
|
empty<T>(): IteratorObject<T>;
|
|
105
122
|
/**
|
|
106
123
|
* Sequence multiple iterators into a single one.
|
|
107
|
-
*
|
|
124
|
+
* @see https://github.com/tc39/proposal-iterator-sequencing
|
|
108
125
|
*/
|
|
109
126
|
concat<T>(...inputs: Array<Iterable<T>>): IteratorObject<T>;
|
|
127
|
+
/**
|
|
128
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
129
|
+
*/
|
|
130
|
+
zip<T>(inputs: Iterable<Iterable<T>>): IteratorObject<Array<T>>;
|
|
131
|
+
/**
|
|
132
|
+
* @see https://github.com/tc39/proposal-joint-iteration
|
|
133
|
+
*/
|
|
134
|
+
zipKeyed<T>(inputs: Record<string, Iterable<T>>): IteratorObject<Record<string, T>>;
|
|
110
135
|
}
|
|
111
136
|
|
|
112
137
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -114,8 +139,6 @@ declare global {
|
|
|
114
139
|
/**
|
|
115
140
|
* Get the next value from the iterator, wrapped in an {@link Option}
|
|
116
141
|
* type. If the iterator has no more values, return {@link None}.
|
|
117
|
-
*
|
|
118
|
-
* This is the nicely utility typed version of {@link Iterator#next}.
|
|
119
142
|
*/
|
|
120
143
|
takeOne(): Option<T>;
|
|
121
144
|
/**
|
|
@@ -124,6 +147,7 @@ declare global {
|
|
|
124
147
|
takeWhile<S extends T>(
|
|
125
148
|
predicate: (value: T, index: number) => value is S
|
|
126
149
|
): IteratorObject<S, undefined>;
|
|
150
|
+
/** @ignore */
|
|
127
151
|
takeWhile(predicate: (value: T, index: number) => boolean): IteratorObject<T, undefined>;
|
|
128
152
|
/**
|
|
129
153
|
* Ignore all items matching `predicate` until the first item that
|
|
@@ -249,37 +273,21 @@ defineProperties(Array.prototype, {
|
|
|
249
273
|
},
|
|
250
274
|
});
|
|
251
275
|
|
|
276
|
+
shimUnscopables("remove");
|
|
277
|
+
shimUnscopables("removeFn");
|
|
278
|
+
shimUnscopables("removeIndex");
|
|
279
|
+
shimUnscopables("insert");
|
|
280
|
+
shimUnscopables("insertOrdered");
|
|
281
|
+
shimUnscopables("present");
|
|
282
|
+
shimUnscopables("nonNullable");
|
|
283
|
+
shimUnscopables("get");
|
|
284
|
+
|
|
252
285
|
// Iterator
|
|
253
286
|
|
|
254
287
|
defineProperties(Iterator, {
|
|
255
288
|
empty<T>(): IteratorObject<T> {
|
|
256
289
|
return Iterator.from([]);
|
|
257
290
|
},
|
|
258
|
-
|
|
259
|
-
concat<T>(...inputs: Array<Iterable<T>>): IteratorObject<T> {
|
|
260
|
-
if (inputs.length === 0) {
|
|
261
|
-
return Iterator.empty();
|
|
262
|
-
}
|
|
263
|
-
let iter: Iterator<T> = inputs[0][Symbol.iterator]();
|
|
264
|
-
let index = 0;
|
|
265
|
-
let done = false;
|
|
266
|
-
return Iterator.from({
|
|
267
|
-
next(): IteratorResult<T, undefined> {
|
|
268
|
-
if (!done) {
|
|
269
|
-
let result = iter.next();
|
|
270
|
-
while (result.done === true && index < inputs.length - 1) {
|
|
271
|
-
iter = inputs[++index][Symbol.iterator]();
|
|
272
|
-
result = iter.next();
|
|
273
|
-
}
|
|
274
|
-
if (result.done !== true) {
|
|
275
|
-
return result;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
done = true;
|
|
279
|
-
return { done: true, value: undefined };
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
},
|
|
283
291
|
});
|
|
284
292
|
|
|
285
293
|
defineProperties(Iterator.prototype, {
|