@thi.ng/transducers-patch 0.4.81 → 0.4.82

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-12-09T19:12:04Z
3
+ - **Last updated**: 2023-12-11T10:07:09Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
package/api.js CHANGED
@@ -1 +0,0 @@
1
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/transducers-patch",
3
- "version": "0.4.81",
3
+ "version": "0.4.82",
4
4
  "description": "Reducers for patch-based, immutable-by-default array & object editing",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -24,7 +24,9 @@
24
24
  "author": "Karsten Schmidt (https://thi.ng)",
25
25
  "license": "Apache-2.0",
26
26
  "scripts": {
27
- "build": "yarn clean && tsc --declaration",
27
+ "build": "yarn build:esbuild && yarn build:decl",
28
+ "build:decl": "tsc --declaration --emitDeclarationOnly",
29
+ "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
28
30
  "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
29
31
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
30
32
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
@@ -33,14 +35,15 @@
33
35
  "test": "bun test"
34
36
  },
35
37
  "dependencies": {
36
- "@thi.ng/api": "^8.9.11",
37
- "@thi.ng/checks": "^3.4.11",
38
- "@thi.ng/errors": "^2.4.5",
39
- "@thi.ng/paths": "^5.1.52",
40
- "@thi.ng/transducers": "^8.8.14"
38
+ "@thi.ng/api": "^8.9.12",
39
+ "@thi.ng/checks": "^3.4.12",
40
+ "@thi.ng/errors": "^2.4.6",
41
+ "@thi.ng/paths": "^5.1.53",
42
+ "@thi.ng/transducers": "^8.8.15"
41
43
  },
42
44
  "devDependencies": {
43
45
  "@microsoft/api-extractor": "^7.38.3",
46
+ "esbuild": "^0.19.8",
44
47
  "rimraf": "^5.0.5",
45
48
  "tools": "^0.0.1",
46
49
  "typedoc": "^0.25.4",
@@ -84,5 +87,5 @@
84
87
  "status": "alpha",
85
88
  "year": 2020
86
89
  },
87
- "gitHead": "25f2ac8ff795a432a930119661b364d4d93b59a0\n"
90
+ "gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
88
91
  }
package/patch-array.js CHANGED
@@ -2,56 +2,59 @@ import { isString } from "@thi.ng/checks/is-string";
2
2
  import { illegalArgs } from "@thi.ng/errors/illegal-arguments";
3
3
  import { illegalArity } from "@thi.ng/errors/illegal-arity";
4
4
  import { reduce, reducer } from "@thi.ng/transducers/reduce";
5
- export function patchArray(...args) {
6
- let immutable;
7
- let init;
8
- let patches;
9
- switch (args.length) {
10
- case 0:
11
- immutable = true;
12
- break;
13
- case 1:
14
- immutable = args[0];
15
- break;
16
- case 3:
17
- immutable = args[0];
18
- init = args[1];
19
- patches = args[2];
20
- break;
21
- default:
22
- illegalArity(args.length);
5
+ function patchArray(...args) {
6
+ let immutable;
7
+ let init;
8
+ let patches;
9
+ switch (args.length) {
10
+ case 0:
11
+ immutable = true;
12
+ break;
13
+ case 1:
14
+ immutable = args[0];
15
+ break;
16
+ case 3:
17
+ immutable = args[0];
18
+ init = args[1];
19
+ patches = args[2];
20
+ break;
21
+ default:
22
+ illegalArity(args.length);
23
+ }
24
+ const edit = (acc, x) => {
25
+ switch (x[0]) {
26
+ case "set":
27
+ acc[x[1]] = x[2];
28
+ break;
29
+ case "update":
30
+ acc[x[1]] = x[2](acc[x[1]], ...x.slice(3));
31
+ break;
32
+ case "insert":
33
+ acc.splice(x[1], 0, ...x[2]);
34
+ break;
35
+ case "delete":
36
+ acc.splice(x[1], 1);
37
+ break;
38
+ default:
39
+ illegalArgs(`patch op: ${x}`);
23
40
  }
24
- const edit = (acc, x) => {
25
- switch (x[0]) {
26
- case "set":
27
- acc[x[1]] = x[2];
28
- break;
29
- case "update":
30
- acc[x[1]] = x[2](acc[x[1]], ...x.slice(3));
31
- break;
32
- case "insert":
33
- acc.splice(x[1], 0, ...x[2]);
34
- break;
35
- case "delete":
36
- acc.splice(x[1], 1);
37
- break;
38
- default:
39
- illegalArgs(`patch op: ${x}`);
41
+ return acc;
42
+ };
43
+ return patches ? reduce(patchArray(immutable), init, patches) : reducer(
44
+ () => [],
45
+ (acc, x) => {
46
+ immutable && (acc = acc.slice());
47
+ if (isString(x[0])) {
48
+ acc = edit(acc, x);
49
+ } else {
50
+ for (let e of x) {
51
+ acc = edit(acc, e);
40
52
  }
41
- return acc;
42
- };
43
- return patches
44
- ? reduce(patchArray(immutable), init, patches)
45
- : reducer(() => [], (acc, x) => {
46
- immutable && (acc = acc.slice());
47
- if (isString(x[0])) {
48
- acc = edit(acc, x);
49
- }
50
- else {
51
- for (let e of x) {
52
- acc = edit(acc, e);
53
- }
54
- }
55
- return acc;
56
- });
53
+ }
54
+ return acc;
55
+ }
56
+ );
57
57
  }
58
+ export {
59
+ patchArray
60
+ };
package/patch-obj.js CHANGED
@@ -4,30 +4,33 @@ import { deleteInUnsafe } from "@thi.ng/paths/delete-in";
4
4
  import { setInUnsafe } from "@thi.ng/paths/set-in";
5
5
  import { updateInUnsafe } from "@thi.ng/paths/update-in";
6
6
  import { reduce, reducer } from "@thi.ng/transducers/reduce";
7
- export function patchObj(init, patches) {
8
- const edit = (acc, x) => {
9
- switch (x[0]) {
10
- case "set":
11
- return setInUnsafe(acc, x[1], x[2]);
12
- case "update":
13
- return updateInUnsafe(acc, x[1], x[2], ...x.slice(3));
14
- case "delete":
15
- return deleteInUnsafe(acc, x[1]);
16
- default:
17
- illegalArgs(`patch op: ${x}`);
7
+ function patchObj(init, patches) {
8
+ const edit = (acc, x) => {
9
+ switch (x[0]) {
10
+ case "set":
11
+ return setInUnsafe(acc, x[1], x[2]);
12
+ case "update":
13
+ return updateInUnsafe(acc, x[1], x[2], ...x.slice(3));
14
+ case "delete":
15
+ return deleteInUnsafe(acc, x[1]);
16
+ default:
17
+ illegalArgs(`patch op: ${x}`);
18
+ }
19
+ };
20
+ return patches ? reduce(patchObj(), init, patches) : reducer(
21
+ () => ({}),
22
+ (acc, x) => {
23
+ if (isString(x[0])) {
24
+ acc = edit(acc, x);
25
+ } else {
26
+ for (let e of x) {
27
+ acc = edit(acc, e);
18
28
  }
19
- };
20
- return patches
21
- ? reduce(patchObj(), init, patches)
22
- : reducer(() => ({}), (acc, x) => {
23
- if (isString(x[0])) {
24
- acc = edit(acc, x);
25
- }
26
- else {
27
- for (let e of x) {
28
- acc = edit(acc, e);
29
- }
30
- }
31
- return acc;
32
- });
29
+ }
30
+ return acc;
31
+ }
32
+ );
33
33
  }
34
+ export {
35
+ patchObj
36
+ };