@hyperjump/json-pointer 0.9.7 → 1.0.0

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/README.md CHANGED
@@ -8,8 +8,7 @@ the JSON document.
8
8
 
9
9
  Installation
10
10
  ------------
11
- Includes support for node.js JavaScript (CommonJS and ES Modules), TypeScript,
12
- and browsers.
11
+ Includes support for node.js (ES Modules, TypeScript) and browsers.
13
12
 
14
13
  ```bash
15
14
  npm install @hyperjump/json-pointer
package/lib/index.d.ts CHANGED
@@ -1,36 +1,34 @@
1
- export type JsonPointer = {
2
- nil: "";
3
- append: (
1
+ export const nil: "";
2
+ export const append: (
4
3
  (segment: string, pointer: string) => string
5
4
  ) & (
6
5
  (segment: string) => (pointer: string) => string
7
6
  );
8
- get: (
7
+ export const get: (
9
8
  (pointer: string, subject: Pointable) => unknown
10
9
  ) & (
11
10
  (pointer: string) => Getter
12
11
  );
13
- set: (
12
+ export const set: (
14
13
  <A extends Pointable>(pointer: string, subject: A, value: unknown) => A
15
14
  ) & (
16
15
  (pointer: string) => Setter
17
16
  );
18
- assign: (
17
+ export const assign: (
19
18
  <A extends Pointable>(pointer: string, subject: A, value: unknown) => void
20
19
  ) & (
21
20
  (pointer: string) => Assigner
22
21
  );
23
- unset: (
22
+ export const unset: (
24
23
  <A extends Pointable>(pointer: string, subject: A) => A
25
24
  ) & (
26
25
  (pointer: string) => Unsetter
27
26
  );
28
- remove: (
27
+ export const remove: (
29
28
  (pointer: string, subject: Pointable) => void
30
29
  ) & (
31
30
  (pointer: string) => Remover
32
31
  );
33
- }
34
32
 
35
33
  export type Getter = (subject: Pointable) => unknown;
36
34
  export type Setter = (
@@ -52,14 +50,3 @@ export type JsonObject = {
52
50
  };
53
51
 
54
52
  export type Pointable = JsonObject | Json[];
55
-
56
- declare const JsonPointer: JsonPointer;
57
- export const nil: JsonPointer["nil"];
58
- export const append: JsonPointer["append"];
59
- export const get: JsonPointer["get"];
60
- export const set: JsonPointer["set"];
61
- export const assign: JsonPointer["assign"];
62
- export const unset: JsonPointer["unset"];
63
- export const remove: JsonPointer["remove"];
64
-
65
- export default JsonPointer;
package/lib/index.js CHANGED
@@ -1,122 +1,144 @@
1
- const curry = require("just-curry-it");
1
+ import curry from "just-curry-it";
2
2
 
3
3
 
4
- const nil = "";
4
+ export const nil = "";
5
5
 
6
- const compile = (pointer) => {
6
+ const EXISTS = Symbol("EXISTS");
7
+
8
+ const segmentGenerator = (pointer) => {
7
9
  if (pointer.length > 0 && pointer[0] !== "/") {
8
10
  throw Error("Invalid JSON Pointer");
9
11
  }
10
12
 
11
- return pointer.split("/").slice(1).map(unescape);
12
- };
13
+ let segmentStart = 1;
14
+ let segmentEnd = 0;
13
15
 
14
- const get = (pointer, value = undefined) => {
15
- const ptr = compile(pointer);
16
+ return (mode) => {
17
+ if (mode === EXISTS) {
18
+ return segmentEnd < pointer.length;
19
+ }
20
+
21
+ if (segmentEnd >= pointer.length) {
22
+ return;
23
+ }
16
24
 
17
- const fn = (value) => ptr.reduce(([value, pointer], segment) => {
18
- return [applySegment(value, segment, pointer), append(segment, pointer)];
19
- }, [value, ""])[0];
25
+ const position = pointer.indexOf("/", segmentStart);
26
+ segmentEnd = position === -1 ? pointer.length : position;
27
+ const segment = unescape(pointer.slice(segmentStart, segmentEnd));
28
+ segmentStart = segmentEnd + 1;
29
+
30
+ return segment;
31
+ };
32
+ };
33
+
34
+ export const get = (pointer, subject = undefined) => {
35
+ const nextSegment = segmentGenerator(pointer);
36
+ const fn = (subject) => _get(nextSegment, subject, nil);
37
+ return subject === undefined ? fn : fn(subject);
38
+ };
20
39
 
21
- return value === undefined ? fn : fn(value);
40
+ const _get = (nextSegment, subject, cursor) => {
41
+ if (!nextSegment(EXISTS)) {
42
+ return subject;
43
+ } else {
44
+ const segment = nextSegment();
45
+ return _get(nextSegment, applySegment(subject, segment, cursor), append(segment, cursor));
46
+ }
22
47
  };
23
48
 
24
- const set = (pointer, subject = undefined, value = undefined) => {
25
- const ptr = compile(pointer);
26
- const fn = curry((subject, value) => _set(ptr, subject, value, nil));
49
+ export const set = (pointer, subject = undefined, value = undefined) => {
50
+ const nextSegment = segmentGenerator(pointer);
51
+ const fn = curry((subject, value) => _set(nextSegment, subject, value, nil));
27
52
  return subject === undefined ? fn : fn(subject, value);
28
53
  };
29
54
 
30
- const _set = (pointer, subject, value, cursor) => {
31
- if (pointer.length === 0) {
55
+ const _set = (nextSegment, subject, value, cursor) => {
56
+ const segment = nextSegment();
57
+ if (segment === undefined) {
32
58
  return value;
33
- } else if (pointer.length > 1) {
59
+ } else if (nextSegment(EXISTS)) {
34
60
  if (Array.isArray(subject)) {
35
- const index = pointer.shift();
36
61
  const clonedSubject = [...subject];
37
- clonedSubject[index] = _set(pointer, applySegment(subject, index, cursor), value, append(index, cursor));
62
+ clonedSubject[segment] = _set(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor));
38
63
  return clonedSubject;
39
64
  } else {
40
- const segment = pointer.shift();
41
- return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
65
+ return { ...subject, [segment]: _set(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
42
66
  }
43
67
  } else if (Array.isArray(subject)) {
44
68
  const clonedSubject = [...subject];
45
- const segment = computeSegment(subject, pointer[0]);
46
- clonedSubject[segment] = value;
69
+ clonedSubject[computeSegment(subject, segment)] = value;
47
70
  return clonedSubject;
48
71
  } else if (typeof subject === "object" && subject !== null) {
49
- return { ...subject, [pointer[0]]: value };
72
+ return { ...subject, [segment]: value };
50
73
  } else {
51
- return applySegment(subject, pointer[0], cursor);
74
+ return applySegment(subject, segment, cursor);
52
75
  }
53
76
  };
54
77
 
55
- const assign = (pointer, subject = undefined, value = undefined) => {
56
- const ptr = compile(pointer);
57
- const fn = curry((subject, value) => _assign(ptr, subject, value, nil));
78
+ export const assign = (pointer, subject = undefined, value = undefined) => {
79
+ const nextSegment = segmentGenerator(pointer);
80
+ const fn = curry((subject, value) => _assign(nextSegment, subject, value, nil));
58
81
  return subject === undefined ? fn : fn(subject, value);
59
82
  };
60
83
 
61
- const _assign = (pointer, subject, value, cursor) => {
62
- if (pointer.length === 0) {
84
+ const _assign = (nextSegment, subject, value, cursor) => {
85
+ const segment = nextSegment();
86
+ if (segment === undefined) {
63
87
  return;
64
- } else if (pointer.length === 1 && !isScalar(subject)) {
65
- const segment = computeSegment(subject, pointer[0]);
66
- subject[segment] = value;
88
+ } else if (!nextSegment(EXISTS) && !isScalar(subject)) {
89
+ subject[computeSegment(subject, segment)] = value;
67
90
  } else {
68
- const segment = pointer.shift();
69
- _assign(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));
91
+ _assign(nextSegment, applySegment(subject, segment, cursor), value, append(segment, cursor));
70
92
  }
71
93
  };
72
94
 
73
- const unset = (pointer, subject = undefined) => {
74
- const ptr = compile(pointer);
75
- const fn = (subject) => _unset(ptr, subject, nil);
95
+ export const unset = (pointer, subject = undefined) => {
96
+ const nextSegment = segmentGenerator(pointer);
97
+ const fn = (subject) => _unset(nextSegment, subject, nil);
76
98
  return subject === undefined ? fn : fn(subject);
77
99
  };
78
100
 
79
- const _unset = (pointer, subject, cursor) => {
80
- if (pointer.length == 0) {
81
- return undefined;
82
- } else if (pointer.length > 1) {
83
- const segment = pointer.shift();
101
+ const _unset = (nextSegment, subject, cursor) => {
102
+ const segment = nextSegment();
103
+ if (segment === undefined) {
104
+ return;
105
+ } else if (nextSegment(EXISTS)) {
84
106
  const value = applySegment(subject, segment, cursor);
85
- return { ...subject, [segment]: _unset(pointer, value, append(segment, cursor)) };
107
+ return { ...subject, [segment]: _unset(nextSegment, value, append(segment, cursor)) };
86
108
  } else if (Array.isArray(subject)) {
87
- return subject.filter((_, ndx) => ndx != pointer[0]);
109
+ const clonedSubject = [...subject];
110
+ delete clonedSubject[computeSegment(subject, segment)];
111
+ return clonedSubject;
88
112
  } else if (typeof subject === "object" && subject !== null) {
89
113
  // eslint-disable-next-line no-unused-vars
90
- const { [pointer[0]]: _, ...result } = subject;
114
+ const { [segment]: _, ...result } = subject;
91
115
  return result;
92
116
  } else {
93
- return applySegment(subject, pointer[0], cursor);
117
+ return applySegment(subject, segment, cursor);
94
118
  }
95
119
  };
96
120
 
97
- const remove = (pointer, subject = undefined) => {
98
- const ptr = compile(pointer);
99
- const fn = (subject) => _remove(ptr, subject, nil);
121
+ export const remove = (pointer, subject = undefined) => {
122
+ const nextSegment = segmentGenerator(pointer);
123
+ const fn = (subject) => _remove(nextSegment, subject, nil);
100
124
  return subject === undefined ? fn : fn(subject);
101
125
  };
102
126
 
103
- const _remove = (pointer, subject, cursor) => {
104
- if (pointer.length === 0) {
127
+ const _remove = (nextSegment, subject, cursor) => {
128
+ const segment = nextSegment();
129
+ if (segment === undefined) {
105
130
  return;
106
- } else if (pointer.length > 1) {
107
- const segment = pointer.shift();
131
+ } else if (nextSegment(EXISTS)) {
108
132
  const value = applySegment(subject, segment, cursor);
109
- _remove(pointer, value, append(segment, cursor));
110
- } else if (Array.isArray(subject)) {
111
- subject.splice(pointer[0], 1);
112
- } else if (typeof subject === "object" && subject !== null) {
113
- delete subject[pointer[0]];
133
+ _remove(nextSegment, value, append(segment, cursor));
134
+ } else if (!isScalar(subject)) {
135
+ delete subject[segment];
114
136
  } else {
115
- applySegment(subject, pointer[0], cursor);
137
+ applySegment(subject, segment, cursor);
116
138
  }
117
139
  };
118
140
 
119
- const append = curry((segment, pointer) => pointer + "/" + escape(segment));
141
+ export const append = curry((segment, pointer) => pointer + "/" + escape(segment));
120
142
 
121
143
  const escape = (segment) => segment.toString().replace(/~/g, "~0").replace(/\//g, "~1");
122
144
  const unescape = (segment) => segment.toString().replace(/~1/g, "/").replace(/~0/g, "~");
@@ -136,5 +158,3 @@ const applySegment = (value, segment, cursor = "") => {
136
158
  };
137
159
 
138
160
  const isScalar = (value) => value === null || typeof value !== "object";
139
-
140
- module.exports = { nil, append, get, set, assign, unset, remove };
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@hyperjump/json-pointer",
3
- "version": "0.9.7",
3
+ "version": "1.0.0",
4
4
  "description": "An RFC-6901 JSON Pointer implementation",
5
+ "type": "module",
5
6
  "main": "lib/index.js",
6
7
  "exports": {
7
8
  "require": "./lib/index.js",
@@ -10,10 +11,7 @@
10
11
  "scripts": {
11
12
  "clean": "xargs -a .gitignore rm -rf",
12
13
  "lint": "eslint lib",
13
- "test": "mocha --require ts-node/register 'lib/**/*.spec.ts'",
14
- "build": "rollup --config rollup.config.js",
15
- "prepublishOnly": "npm run build",
16
- "postinstall": "node -e \"require('fs').rmSync('dist', { recursive: true })\""
14
+ "test": "mocha 'lib/**/*.spec.ts'"
17
15
  },
18
16
  "repository": "github:hyperjump-io/json-pointer",
19
17
  "keywords": [
@@ -27,8 +25,6 @@
27
25
  "url": "https://github.com/sponsors/jdesrosiers"
28
26
  },
29
27
  "devDependencies": {
30
- "@rollup/plugin-commonjs": "*",
31
- "@rollup/plugin-node-resolve": "*",
32
28
  "@types/chai": "*",
33
29
  "@types/mocha": "*",
34
30
  "@typescript-eslint/eslint-plugin": "*",
@@ -39,13 +35,10 @@
39
35
  "eslint-import-resolver-typescript": "*",
40
36
  "eslint-plugin-import": "*",
41
37
  "mocha": "*",
42
- "rimraf": "*",
43
- "rollup": "*",
44
- "rollup-plugin-terser": "*",
45
38
  "ts-node": "*",
46
39
  "typescript": "*"
47
40
  },
48
41
  "dependencies": {
49
- "just-curry-it": "^5.2.1"
42
+ "just-curry-it": "^5.3.0"
50
43
  }
51
44
  }
@@ -1,188 +0,0 @@
1
- define((function () { 'use strict';
2
-
3
- var justCurryIt = curry$1;
4
-
5
- /*
6
- function add(a, b, c) {
7
- return a + b + c;
8
- }
9
- curry(add)(1)(2)(3); // 6
10
- curry(add)(1)(2)(2); // 5
11
- curry(add)(2)(4, 3); // 9
12
-
13
- function add(...args) {
14
- return args.reduce((sum, n) => sum + n, 0)
15
- }
16
- var curryAdd4 = curry(add, 4)
17
- curryAdd4(1)(2, 3)(4); // 10
18
-
19
- function converter(ratio, input) {
20
- return (input*ratio).toFixed(1);
21
- }
22
- const curriedConverter = curry(converter)
23
- const milesToKm = curriedConverter(1.62);
24
- milesToKm(35); // 56.7
25
- milesToKm(10); // 16.2
26
- */
27
-
28
- function curry$1(fn, arity) {
29
- return function curried() {
30
- if (arity == null) {
31
- arity = fn.length;
32
- }
33
- var args = [].slice.call(arguments);
34
- if (args.length >= arity) {
35
- return fn.apply(this, args);
36
- } else {
37
- return function() {
38
- return curried.apply(this, args.concat([].slice.call(arguments)));
39
- };
40
- }
41
- };
42
- }
43
-
44
- const curry = justCurryIt;
45
-
46
-
47
- const nil = "";
48
-
49
- const compile = (pointer) => {
50
- if (pointer.length > 0 && pointer[0] !== "/") {
51
- throw Error("Invalid JSON Pointer");
52
- }
53
-
54
- return pointer.split("/").slice(1).map(unescape);
55
- };
56
-
57
- const get = (pointer, value = undefined) => {
58
- const ptr = compile(pointer);
59
-
60
- const fn = (value) => ptr.reduce(([value, pointer], segment) => {
61
- return [applySegment(value, segment, pointer), append(segment, pointer)];
62
- }, [value, ""])[0];
63
-
64
- return value === undefined ? fn : fn(value);
65
- };
66
-
67
- const set = (pointer, subject = undefined, value = undefined) => {
68
- const ptr = compile(pointer);
69
- const fn = curry((subject, value) => _set(ptr, subject, value, nil));
70
- return subject === undefined ? fn : fn(subject, value);
71
- };
72
-
73
- const _set = (pointer, subject, value, cursor) => {
74
- if (pointer.length === 0) {
75
- return value;
76
- } else if (pointer.length > 1) {
77
- if (Array.isArray(subject)) {
78
- const index = pointer.shift();
79
- const clonedSubject = [...subject];
80
- clonedSubject[index] = _set(pointer, applySegment(subject, index, cursor), value, append(index, cursor));
81
- return clonedSubject;
82
- } else {
83
- const segment = pointer.shift();
84
- return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };
85
- }
86
- } else if (Array.isArray(subject)) {
87
- const clonedSubject = [...subject];
88
- const segment = computeSegment(subject, pointer[0]);
89
- clonedSubject[segment] = value;
90
- return clonedSubject;
91
- } else if (typeof subject === "object" && subject !== null) {
92
- return { ...subject, [pointer[0]]: value };
93
- } else {
94
- return applySegment(subject, pointer[0], cursor);
95
- }
96
- };
97
-
98
- const assign = (pointer, subject = undefined, value = undefined) => {
99
- const ptr = compile(pointer);
100
- const fn = curry((subject, value) => _assign(ptr, subject, value, nil));
101
- return subject === undefined ? fn : fn(subject, value);
102
- };
103
-
104
- const _assign = (pointer, subject, value, cursor) => {
105
- if (pointer.length === 0) {
106
- return;
107
- } else if (pointer.length === 1 && !isScalar(subject)) {
108
- const segment = computeSegment(subject, pointer[0]);
109
- subject[segment] = value;
110
- } else {
111
- const segment = pointer.shift();
112
- _assign(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));
113
- }
114
- };
115
-
116
- const unset = (pointer, subject = undefined) => {
117
- const ptr = compile(pointer);
118
- const fn = (subject) => _unset(ptr, subject, nil);
119
- return subject === undefined ? fn : fn(subject);
120
- };
121
-
122
- const _unset = (pointer, subject, cursor) => {
123
- if (pointer.length == 0) {
124
- return undefined;
125
- } else if (pointer.length > 1) {
126
- const segment = pointer.shift();
127
- const value = applySegment(subject, segment, cursor);
128
- return { ...subject, [segment]: _unset(pointer, value, append(segment, cursor)) };
129
- } else if (Array.isArray(subject)) {
130
- return subject.filter((_, ndx) => ndx != pointer[0]);
131
- } else if (typeof subject === "object" && subject !== null) {
132
- // eslint-disable-next-line no-unused-vars
133
- const { [pointer[0]]: _, ...result } = subject;
134
- return result;
135
- } else {
136
- return applySegment(subject, pointer[0], cursor);
137
- }
138
- };
139
-
140
- const remove = (pointer, subject = undefined) => {
141
- const ptr = compile(pointer);
142
- const fn = (subject) => _remove(ptr, subject, nil);
143
- return subject === undefined ? fn : fn(subject);
144
- };
145
-
146
- const _remove = (pointer, subject, cursor) => {
147
- if (pointer.length === 0) {
148
- return;
149
- } else if (pointer.length > 1) {
150
- const segment = pointer.shift();
151
- const value = applySegment(subject, segment, cursor);
152
- _remove(pointer, value, append(segment, cursor));
153
- } else if (Array.isArray(subject)) {
154
- subject.splice(pointer[0], 1);
155
- } else if (typeof subject === "object" && subject !== null) {
156
- delete subject[pointer[0]];
157
- } else {
158
- applySegment(subject, pointer[0], cursor);
159
- }
160
- };
161
-
162
- const append = curry((segment, pointer) => pointer + "/" + escape(segment));
163
-
164
- const escape = (segment) => segment.toString().replace(/~/g, "~0").replace(/\//g, "~1");
165
- const unescape = (segment) => segment.toString().replace(/~1/g, "/").replace(/~0/g, "~");
166
- const computeSegment = (value, segment) => Array.isArray(value) && segment === "-" ? value.length : segment;
167
-
168
- const applySegment = (value, segment, cursor = "") => {
169
- if (value === undefined) {
170
- throw TypeError(`Value at '${cursor}' is undefined and does not have property '${segment}'`);
171
- } else if (value === null) {
172
- throw TypeError(`Value at '${cursor}' is null and does not have property '${segment}'`);
173
- } else if (isScalar(value)) {
174
- throw TypeError(`Value at '${cursor}' is a ${typeof value} and does not have property '${segment}'`);
175
- } else {
176
- const computedSegment = computeSegment(value, segment);
177
- return value[computedSegment];
178
- }
179
- };
180
-
181
- const isScalar = (value) => value === null || typeof value !== "object";
182
-
183
- var lib = { nil, append, get, set, assign, unset, remove };
184
-
185
- return lib;
186
-
187
- }));
188
- //# sourceMappingURL=json-pointer-amd.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-pointer-amd.js","sources":["../node_modules/just-curry-it/index.js","../lib/index.js"],"sourcesContent":["module.exports = curry;\n\n/*\n function add(a, b, c) {\n return a + b + c;\n }\n curry(add)(1)(2)(3); // 6\n curry(add)(1)(2)(2); // 5\n curry(add)(2)(4, 3); // 9\n\n function add(...args) {\n return args.reduce((sum, n) => sum + n, 0)\n }\n var curryAdd4 = curry(add, 4)\n curryAdd4(1)(2, 3)(4); // 10\n\n function converter(ratio, input) {\n return (input*ratio).toFixed(1);\n }\n const curriedConverter = curry(converter)\n const milesToKm = curriedConverter(1.62);\n milesToKm(35); // 56.7\n milesToKm(10); // 16.2\n*/\n\nfunction curry(fn, arity) {\n return function curried() {\n if (arity == null) {\n arity = fn.length;\n }\n var args = [].slice.call(arguments);\n if (args.length >= arity) {\n return fn.apply(this, args);\n } else {\n return function() {\n return curried.apply(this, args.concat([].slice.call(arguments)));\n };\n }\n };\n}\n","const curry = require(\"just-curry-it\");\n\n\nconst nil = \"\";\n\nconst compile = (pointer) => {\n if (pointer.length > 0 && pointer[0] !== \"/\") {\n throw Error(\"Invalid JSON Pointer\");\n }\n\n return pointer.split(\"/\").slice(1).map(unescape);\n};\n\nconst get = (pointer, value = undefined) => {\n const ptr = compile(pointer);\n\n const fn = (value) => ptr.reduce(([value, pointer], segment) => {\n return [applySegment(value, segment, pointer), append(segment, pointer)];\n }, [value, \"\"])[0];\n\n return value === undefined ? fn : fn(value);\n};\n\nconst set = (pointer, subject = undefined, value = undefined) => {\n const ptr = compile(pointer);\n const fn = curry((subject, value) => _set(ptr, subject, value, nil));\n return subject === undefined ? fn : fn(subject, value);\n};\n\nconst _set = (pointer, subject, value, cursor) => {\n if (pointer.length === 0) {\n return value;\n } else if (pointer.length > 1) {\n if (Array.isArray(subject)) {\n const index = pointer.shift();\n const clonedSubject = [...subject];\n clonedSubject[index] = _set(pointer, applySegment(subject, index, cursor), value, append(index, cursor));\n return clonedSubject;\n } else {\n const segment = pointer.shift();\n return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };\n }\n } else if (Array.isArray(subject)) {\n const clonedSubject = [...subject];\n const segment = computeSegment(subject, pointer[0]);\n clonedSubject[segment] = value;\n return clonedSubject;\n } else if (typeof subject === \"object\" && subject !== null) {\n return { ...subject, [pointer[0]]: value };\n } else {\n return applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst assign = (pointer, subject = undefined, value = undefined) => {\n const ptr = compile(pointer);\n const fn = curry((subject, value) => _assign(ptr, subject, value, nil));\n return subject === undefined ? fn : fn(subject, value);\n};\n\nconst _assign = (pointer, subject, value, cursor) => {\n if (pointer.length === 0) {\n return;\n } else if (pointer.length === 1 && !isScalar(subject)) {\n const segment = computeSegment(subject, pointer[0]);\n subject[segment] = value;\n } else {\n const segment = pointer.shift();\n _assign(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));\n }\n};\n\nconst unset = (pointer, subject = undefined) => {\n const ptr = compile(pointer);\n const fn = (subject) => _unset(ptr, subject, nil);\n return subject === undefined ? fn : fn(subject);\n};\n\nconst _unset = (pointer, subject, cursor) => {\n if (pointer.length == 0) {\n return undefined;\n } else if (pointer.length > 1) {\n const segment = pointer.shift();\n const value = applySegment(subject, segment, cursor);\n return { ...subject, [segment]: _unset(pointer, value, append(segment, cursor)) };\n } else if (Array.isArray(subject)) {\n return subject.filter((_, ndx) => ndx != pointer[0]);\n } else if (typeof subject === \"object\" && subject !== null) {\n // eslint-disable-next-line no-unused-vars\n const { [pointer[0]]: _, ...result } = subject;\n return result;\n } else {\n return applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst remove = (pointer, subject = undefined) => {\n const ptr = compile(pointer);\n const fn = (subject) => _remove(ptr, subject, nil);\n return subject === undefined ? fn : fn(subject);\n};\n\nconst _remove = (pointer, subject, cursor) => {\n if (pointer.length === 0) {\n return;\n } else if (pointer.length > 1) {\n const segment = pointer.shift();\n const value = applySegment(subject, segment, cursor);\n _remove(pointer, value, append(segment, cursor));\n } else if (Array.isArray(subject)) {\n subject.splice(pointer[0], 1);\n } else if (typeof subject === \"object\" && subject !== null) {\n delete subject[pointer[0]];\n } else {\n applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst append = curry((segment, pointer) => pointer + \"/\" + escape(segment));\n\nconst escape = (segment) => segment.toString().replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\nconst unescape = (segment) => segment.toString().replace(/~1/g, \"/\").replace(/~0/g, \"~\");\nconst computeSegment = (value, segment) => Array.isArray(value) && segment === \"-\" ? value.length : segment;\n\nconst applySegment = (value, segment, cursor = \"\") => {\n if (value === undefined) {\n throw TypeError(`Value at '${cursor}' is undefined and does not have property '${segment}'`);\n } else if (value === null) {\n throw TypeError(`Value at '${cursor}' is null and does not have property '${segment}'`);\n } else if (isScalar(value)) {\n throw TypeError(`Value at '${cursor}' is a ${typeof value} and does not have property '${segment}'`);\n } else {\n const computedSegment = computeSegment(value, segment);\n return value[computedSegment];\n }\n};\n\nconst isScalar = (value) => value === null || typeof value !== \"object\";\n\nmodule.exports = { nil, append, get, set, assign, unset, remove };\n"],"names":["curry","require$$0"],"mappings":";;MAAA,WAAc,GAAGA,OAAK,CAAC;AACvB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACA;EACA;EACA;EACA;EACA;EACA;AACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;AACA;EACA,SAASA,OAAK,CAAC,EAAE,EAAE,KAAK,EAAE;EAC1B,EAAE,OAAO,SAAS,OAAO,GAAG;EAC5B,IAAI,IAAI,KAAK,IAAI,IAAI,EAAE;EACvB,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,CAAC;EACxB,KAAK;EACL,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;EACxC,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE;EAC9B,MAAM,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;EAClC,KAAK,MAAM;EACX,MAAM,OAAO,WAAW;EACxB,QAAQ,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;EAC1E,OAAO,CAAC;EACR,KAAK;EACL,GAAG,CAAC;EACJ;;ECvCA,MAAM,KAAK,GAAGC,WAAwB,CAAC;AACvC;AACA;EACA,MAAM,GAAG,GAAG,EAAE,CAAC;AACf;EACA,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK;EAC7B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IAAI,MAAM,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,sCAAsC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;EAC5F,GAAG,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;EAC9B,IAAI,MAAM,SAAS,CAAC,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,KAAK,CAAC,6BAA6B,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;EACzG,GAAG,MAAM;EACT,IAAI,MAAM,eAAe,GAAG,cAAc,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;EAC3D,IAAI,OAAO,KAAK,CAAC,eAAe,CAAC,CAAC;EAClC,GAAG;EACH,CAAC,CAAC;AACF;EACA,MAAM,QAAQ,GAAG,CAAC,KAAK,KAAK,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC;AACxE;AACA,MAAA,GAAc,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;;;;;;;;"}
@@ -1,2 +0,0 @@
1
- define((function(){"use strict";var r=function(r,t){return function e(){null==t&&(t=r.length);var n=[].slice.call(arguments);return n.length>=t?r.apply(this,n):function(){return e.apply(this,n.concat([].slice.call(arguments)))}}};const t=r,e=r=>{if(r.length>0&&"/"!==r[0])throw Error("Invalid JSON Pointer");return r.split("/").slice(1).map(u)},n=(r,t,e,i)=>{if(0===r.length)return e;if(r.length>1){if(Array.isArray(t)){const o=r.shift(),l=[...t];return l[o]=n(r,f(t,o,i),e,s(o,i)),l}{const o=r.shift();return{...t,[o]:n(r,f(t,o,i),e,s(o,i))}}}if(Array.isArray(t)){const n=[...t];return n[c(t,r[0])]=e,n}return"object"==typeof t&&null!==t?{...t,[r[0]]:e}:f(t,r[0],i)},i=(r,t,e,n)=>{if(0!==r.length)if(1!==r.length||p(t)){const o=r.shift();i(r,f(t,o,n),e,s(o,n))}else{t[c(t,r[0])]=e}},o=(r,t,e)=>{if(0!=r.length){if(r.length>1){const n=r.shift(),i=f(t,n,e);return{...t,[n]:o(r,i,s(n,e))}}if(Array.isArray(t))return t.filter(((t,e)=>e!=r[0]));if("object"==typeof t&&null!==t){const{[r[0]]:e,...n}=t;return n}return f(t,r[0],e)}},l=(r,t,e)=>{if(0!==r.length)if(r.length>1){const n=r.shift(),i=f(t,n,e);l(r,i,s(n,e))}else Array.isArray(t)?t.splice(r[0],1):"object"==typeof t&&null!==t?delete t[r[0]]:f(t,r[0],e)},s=t(((r,t)=>t+"/"+a(r))),a=r=>r.toString().replace(/~/g,"~0").replace(/\//g,"~1"),u=r=>r.toString().replace(/~1/g,"/").replace(/~0/g,"~"),c=(r,t)=>Array.isArray(r)&&"-"===t?r.length:t,f=(r,t,e="")=>{if(void 0===r)throw TypeError(`Value at '${e}' is undefined and does not have property '${t}'`);if(null===r)throw TypeError(`Value at '${e}' is null and does not have property '${t}'`);if(p(r))throw TypeError(`Value at '${e}' is a ${typeof r} and does not have property '${t}'`);return r[c(r,t)]},p=r=>null===r||"object"!=typeof r;return{nil:"",append:s,get:(r,t)=>{const n=e(r),i=r=>n.reduce((([r,t],e)=>[f(r,e,t),s(e,t)]),[r,""])[0];return void 0===t?i:i(t)},set:(r,i,o)=>{const l=e(r),s=t(((r,t)=>n(l,r,t,"")));return void 0===i?s:s(i,o)},assign:(r,n,o)=>{const l=e(r),s=t(((r,t)=>i(l,r,t,"")));return void 0===n?s:s(n,o)},unset:(r,t)=>{const n=e(r),i=r=>o(n,r,"");return void 0===t?i:i(t)},remove:(r,t)=>{const n=e(r),i=r=>l(n,r,"");return void 0===t?i:i(t)}}}));
2
- //# sourceMappingURL=json-pointer-amd.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json-pointer-amd.min.js","sources":["../node_modules/just-curry-it/index.js","../lib/index.js"],"sourcesContent":["module.exports = curry;\n\n/*\n function add(a, b, c) {\n return a + b + c;\n }\n curry(add)(1)(2)(3); // 6\n curry(add)(1)(2)(2); // 5\n curry(add)(2)(4, 3); // 9\n\n function add(...args) {\n return args.reduce((sum, n) => sum + n, 0)\n }\n var curryAdd4 = curry(add, 4)\n curryAdd4(1)(2, 3)(4); // 10\n\n function converter(ratio, input) {\n return (input*ratio).toFixed(1);\n }\n const curriedConverter = curry(converter)\n const milesToKm = curriedConverter(1.62);\n milesToKm(35); // 56.7\n milesToKm(10); // 16.2\n*/\n\nfunction curry(fn, arity) {\n return function curried() {\n if (arity == null) {\n arity = fn.length;\n }\n var args = [].slice.call(arguments);\n if (args.length >= arity) {\n return fn.apply(this, args);\n } else {\n return function() {\n return curried.apply(this, args.concat([].slice.call(arguments)));\n };\n }\n };\n}\n","const curry = require(\"just-curry-it\");\n\n\nconst nil = \"\";\n\nconst compile = (pointer) => {\n if (pointer.length > 0 && pointer[0] !== \"/\") {\n throw Error(\"Invalid JSON Pointer\");\n }\n\n return pointer.split(\"/\").slice(1).map(unescape);\n};\n\nconst get = (pointer, value = undefined) => {\n const ptr = compile(pointer);\n\n const fn = (value) => ptr.reduce(([value, pointer], segment) => {\n return [applySegment(value, segment, pointer), append(segment, pointer)];\n }, [value, \"\"])[0];\n\n return value === undefined ? fn : fn(value);\n};\n\nconst set = (pointer, subject = undefined, value = undefined) => {\n const ptr = compile(pointer);\n const fn = curry((subject, value) => _set(ptr, subject, value, nil));\n return subject === undefined ? fn : fn(subject, value);\n};\n\nconst _set = (pointer, subject, value, cursor) => {\n if (pointer.length === 0) {\n return value;\n } else if (pointer.length > 1) {\n if (Array.isArray(subject)) {\n const index = pointer.shift();\n const clonedSubject = [...subject];\n clonedSubject[index] = _set(pointer, applySegment(subject, index, cursor), value, append(index, cursor));\n return clonedSubject;\n } else {\n const segment = pointer.shift();\n return { ...subject, [segment]: _set(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor)) };\n }\n } else if (Array.isArray(subject)) {\n const clonedSubject = [...subject];\n const segment = computeSegment(subject, pointer[0]);\n clonedSubject[segment] = value;\n return clonedSubject;\n } else if (typeof subject === \"object\" && subject !== null) {\n return { ...subject, [pointer[0]]: value };\n } else {\n return applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst assign = (pointer, subject = undefined, value = undefined) => {\n const ptr = compile(pointer);\n const fn = curry((subject, value) => _assign(ptr, subject, value, nil));\n return subject === undefined ? fn : fn(subject, value);\n};\n\nconst _assign = (pointer, subject, value, cursor) => {\n if (pointer.length === 0) {\n return;\n } else if (pointer.length === 1 && !isScalar(subject)) {\n const segment = computeSegment(subject, pointer[0]);\n subject[segment] = value;\n } else {\n const segment = pointer.shift();\n _assign(pointer, applySegment(subject, segment, cursor), value, append(segment, cursor));\n }\n};\n\nconst unset = (pointer, subject = undefined) => {\n const ptr = compile(pointer);\n const fn = (subject) => _unset(ptr, subject, nil);\n return subject === undefined ? fn : fn(subject);\n};\n\nconst _unset = (pointer, subject, cursor) => {\n if (pointer.length == 0) {\n return undefined;\n } else if (pointer.length > 1) {\n const segment = pointer.shift();\n const value = applySegment(subject, segment, cursor);\n return { ...subject, [segment]: _unset(pointer, value, append(segment, cursor)) };\n } else if (Array.isArray(subject)) {\n return subject.filter((_, ndx) => ndx != pointer[0]);\n } else if (typeof subject === \"object\" && subject !== null) {\n // eslint-disable-next-line no-unused-vars\n const { [pointer[0]]: _, ...result } = subject;\n return result;\n } else {\n return applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst remove = (pointer, subject = undefined) => {\n const ptr = compile(pointer);\n const fn = (subject) => _remove(ptr, subject, nil);\n return subject === undefined ? fn : fn(subject);\n};\n\nconst _remove = (pointer, subject, cursor) => {\n if (pointer.length === 0) {\n return;\n } else if (pointer.length > 1) {\n const segment = pointer.shift();\n const value = applySegment(subject, segment, cursor);\n _remove(pointer, value, append(segment, cursor));\n } else if (Array.isArray(subject)) {\n subject.splice(pointer[0], 1);\n } else if (typeof subject === \"object\" && subject !== null) {\n delete subject[pointer[0]];\n } else {\n applySegment(subject, pointer[0], cursor);\n }\n};\n\nconst append = curry((segment, pointer) => pointer + \"/\" + escape(segment));\n\nconst escape = (segment) => segment.toString().replace(/~/g, \"~0\").replace(/\\//g, \"~1\");\nconst unescape = (segment) => segment.toString().replace(/~1/g, \"/\").replace(/~0/g, \"~\");\nconst computeSegment = (value, segment) => Array.isArray(value) && segment === \"-\" ? value.length : segment;\n\nconst applySegment = (value, segment, cursor = \"\") => {\n if (value === undefined) {\n throw TypeError(`Value at '${cursor}' is undefined and does not have property '${segment}'`);\n } else if (value === null) {\n throw TypeError(`Value at '${cursor}' is null and does not have property '${segment}'`);\n } else if (isScalar(value)) {\n throw TypeError(`Value at '${cursor}' is a ${typeof value} and does not have property '${segment}'`);\n } else {\n const computedSegment = computeSegment(value, segment);\n return value[computedSegment];\n }\n};\n\nconst isScalar = (value) => value === null || typeof value !== \"object\";\n\nmodule.exports = { nil, append, get, set, assign, unset, remove };\n"],"names":["justCurryIt","fn","arity","curried","length","args","slice","call","arguments","apply","this","concat","curry","require$$0","compile","pointer","Error","split","map","unescape","_set","subject","value","cursor","Array","isArray","index","shift","clonedSubject","applySegment","append","segment","computeSegment","_assign","isScalar","_unset","filter","_","ndx","result","_remove","splice","escape","toString","replace","undefined","TypeError","nil","get","ptr","reduce","set","assign","unset","remove"],"mappings":"oCAAAA,EAyBA,SAAeC,EAAIC,GACjB,OAAO,SAASC,IACD,MAATD,IACFA,EAAQD,EAAGG,QAEb,IAAIC,EAAO,GAAGC,MAAMC,KAAKC,WACzB,OAAIH,EAAKD,QAAUF,EACVD,EAAGQ,MAAMC,KAAML,GAEf,WACL,OAAOF,EAAQM,MAAMC,KAAML,EAAKM,OAAO,GAAGL,MAAMC,KAAKC,YAC7D,CAEA,CACA,ECvCA,MAAMI,EAAQC,EAKRC,EAAWC,IACf,GAAIA,EAAQX,OAAS,GAAoB,MAAfW,EAAQ,GAChC,MAAMC,MAAM,wBAGd,OAAOD,EAAQE,MAAM,KAAKX,MAAM,GAAGY,IAAIC,EAAS,EAmB5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