@hyperjump/json-pointer 0.9.0 → 0.9.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperjump/json-pointer",
3
- "version": "0.9.0",
3
+ "version": "0.9.3",
4
4
  "description": "An RFC-6901 JSON Pointer implementation",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -12,7 +12,8 @@
12
12
  "lint": "eslint lib",
13
13
  "test": "mocha --require ts-node/register 'lib/**/*.spec.ts'",
14
14
  "build": "rollup --config rollup.config.js",
15
- "prepublishOnly": "npm run build"
15
+ "prepublishOnly": "npm run build",
16
+ "postinstall": "rimraf dist"
16
17
  },
17
18
  "repository": "github:hyperjump-io/json-pointer",
18
19
  "keywords": [
@@ -38,6 +39,7 @@
38
39
  "eslint-import-resolver-typescript": "^2.4.0",
39
40
  "eslint-plugin-import": "^2.24.2",
40
41
  "mocha": "^9.1.1",
42
+ "rimraf": "^3.0.2",
41
43
  "rollup": "^2.56.3",
42
44
  "rollup-plugin-terser": "^7.0.2",
43
45
  "ts-node": "^10.2.1",
@@ -1,20 +0,0 @@
1
- import { expect } from "chai";
2
- import JsonPointer from ".";
3
-
4
-
5
- describe("append", () => {
6
- it("should append a segment to a pointer", () => {
7
- const subject = JsonPointer.append("bar", "/foo");
8
- expect(subject).to.eql("/foo/bar");
9
- });
10
-
11
- it("should append a segment to the nil pointer", () => {
12
- const subject = JsonPointer.append("bar", JsonPointer.nil);
13
- expect(subject).to.eql("/bar");
14
- });
15
-
16
- it("should escape a segment when it is appended to a pointer", () => {
17
- const subject = JsonPointer.append("b~a/r", "/foo");
18
- expect(subject).to.eql("/foo/b~0a~1r");
19
- });
20
- });
@@ -1,160 +0,0 @@
1
- import { expect } from "chai";
2
- import { Given, When, Then } from "./mocha-gherkin.spec";
3
- import JsonPointer, { Json, JsonObject, Pointable } from ".";
4
-
5
-
6
- describe("JsonPointer.assign", () => {
7
- Given("The nil pointer", () => {
8
- const pointer = JsonPointer.nil;
9
-
10
- When("mutating any value", () => {
11
- const subject = { foo: "bar" };
12
- JsonPointer.assign(pointer, subject, "foo");
13
-
14
- Then("the value is not changed", () => {
15
- expect(subject).to.eql({ "foo": "bar" });
16
- });
17
- });
18
- });
19
-
20
- Given("a pointer to a property of an object", () => {
21
- const pointer = "/aaa";
22
-
23
- When("mutating a property", () => {
24
- const subject = { "aaa": 111, "bbb": [] };
25
- JsonPointer.assign(pointer, subject, "foo");
26
-
27
- Then("the new value should be set", () => {
28
- expect(subject.aaa).to.equal("foo");
29
- });
30
- });
31
- });
32
-
33
- Given("a pointer to an item of an array", () => {
34
- const pointer = "/0";
35
-
36
- When("mutating an item", () => {
37
- const subject = [111, 222];
38
- JsonPointer.assign(pointer, subject, "foo");
39
-
40
- Then("the new value should be set", () => {
41
- expect(subject[0]).to.equal("foo");
42
- });
43
- });
44
- });
45
-
46
- Given("a pointer to a nested property of an object", () => {
47
- const pointer = "/aaa/ccc";
48
-
49
- When("mutating a property", () => {
50
- const subject = { "aaa": { "ccc": 333, "ddd": 444 }, "bbb": 222 };
51
- JsonPointer.assign(pointer, subject, "foo");
52
-
53
- Then("the new value should be set", () => {
54
- expect(subject.aaa.ccc).to.equal("foo");
55
- });
56
- });
57
- });
58
-
59
- Given("an object", () => {
60
- let subject: JsonObject;
61
-
62
- beforeEach(() => {
63
- subject = { aaa: { bbb: {} } };
64
- });
65
-
66
- When("mutating a value that doesn't exist", () => {
67
- beforeEach(() => {
68
- JsonPointer.assign("/bbb", subject, "foo");
69
- });
70
-
71
- Then("the value should be set", () => {
72
- expect(subject.bbb).to.equal("foo");
73
- });
74
- });
75
-
76
- When("mutating a value whose parent doesn't exist", () => {
77
- const assign = JsonPointer.assign("/aaa/ccc/bbb");
78
-
79
- Then("an error should be thrown", () => {
80
- expect(() => assign(subject, "foo")).to.throw(Error, "Value at '/aaa/ccc' is undefined and does not have property 'bbb'");
81
- });
82
- });
83
- });
84
-
85
- Given("an array", () => {
86
- let subject: Json[];
87
-
88
- beforeEach(() => {
89
- subject = [];
90
- });
91
-
92
- When("mutating a value that doesn't exist", () => {
93
- beforeEach(() => {
94
- JsonPointer.assign("/0", subject, "foo");
95
- });
96
-
97
- Then("the value should be set", () => {
98
- expect(subject[0]).to.equal("foo");
99
- });
100
- });
101
-
102
- When("adding an item to the end of the array", () => {
103
- beforeEach(() => {
104
- JsonPointer.assign("/-", subject, "foo");
105
- });
106
-
107
- Then("the value should be set", () => {
108
- expect(subject[0]).to.equal("foo");
109
- });
110
- });
111
- });
112
-
113
- Given("a number", () => {
114
- let subject: unknown;
115
-
116
- beforeEach(() => {
117
- subject = 42;
118
- });
119
-
120
- When("indexing into the number", () => {
121
- const assign = JsonPointer.assign("/0");
122
-
123
- Then("an error should be thrown", () => {
124
- expect(() => assign(subject as Pointable, "foo")).to.throw(Error, "Value at '' is a number and does not have property '0'");
125
- });
126
- });
127
- });
128
-
129
- Given("a string", () => {
130
- let subject: unknown;
131
-
132
- beforeEach(() => {
133
- subject = "foo";
134
- });
135
-
136
- When("indexing into the string", () => {
137
- const assign = JsonPointer.assign("/0");
138
-
139
- Then("an error should be thrown", () => {
140
- expect(() => assign(subject as Pointable, "foo")).to.throw(Error, "Value at '' is a string and does not have property '0'");
141
- });
142
- });
143
- });
144
-
145
- Given("null", () => {
146
- let subject: unknown;
147
-
148
- beforeEach(() => {
149
- subject = null;
150
- });
151
-
152
- When("indexing into null", () => {
153
- const assign = JsonPointer.assign("/0");
154
-
155
- Then("an error should be thrown", () => {
156
- expect(() => assign(subject as Pointable, "foo")).to.throw(Error, "Value at '' is null and does not have property '0'");
157
- });
158
- });
159
- });
160
- });
package/lib/get.spec.ts DELETED
@@ -1,91 +0,0 @@
1
- import { expect } from "chai";
2
- import JsonPointer, { Getter } from ".";
3
-
4
-
5
- describe("JsonPointer", () => {
6
- const subject = {
7
- "foo": ["bar", "baz"],
8
- "": 0,
9
- "a/b": 1,
10
- "c%d": 2,
11
- "e^f": 3,
12
- "g|h": 4,
13
- "i\\j": 5,
14
- "k\"l": 6,
15
- " ": 7,
16
- "m~n": 8,
17
- "~0": 9,
18
- "~1": 10,
19
- "/0": 11,
20
- "/1": 12,
21
- "aaa": null,
22
- "bbb": { "-": { "ccc": 13 } }
23
- };
24
-
25
- describe("get", () => {
26
- const tests: [string, unknown][] = [
27
- ["", subject],
28
- ["/foo", ["bar", "baz"]],
29
- ["/foo/0", "bar"],
30
- ["/", 0],
31
- ["/a~1b", 1],
32
- ["/c%d", 2],
33
- ["/e^f", 3],
34
- ["/g|h", 4],
35
- ["/i\\j", 5],
36
- ["/k\"l", 6],
37
- ["/ ", 7],
38
- ["/m~0n", 8],
39
- ["/~00", 9],
40
- ["/~01", 10],
41
- ["/~10", 11],
42
- ["/~11", 12],
43
- ["/bbb/-/ccc", 13],
44
- ["/bbb/-", { "ccc": 13 }],
45
- ["/bar", undefined],
46
- ["/foo/2", undefined],
47
- ["/foo/-", undefined],
48
- ["/0", undefined]
49
- ];
50
- tests.forEach(([pointer, expected]) => {
51
- describe(JSON.stringify(pointer), () => {
52
- let ptr: Getter;
53
-
54
- beforeEach(() => {
55
- ptr = JsonPointer.get(pointer);
56
- });
57
-
58
- it(`should equal ${JSON.stringify(expected)}`, () => {
59
- expect(ptr(subject)).to.eql(expected);
60
- });
61
- });
62
- });
63
- });
64
-
65
- describe("indexing into a number", () => {
66
- it("should throw an error", () => {
67
- const ptr = JsonPointer.get("//foo");
68
- expect(() => ptr(subject)).to.throw(Error, "Value at '/' is a number and does not have property 'foo'");
69
- });
70
- });
71
-
72
- describe("indexing into a string", () => {
73
- it("should throw an error", () => {
74
- const ptr = JsonPointer.get("/foo/0/0");
75
- expect(() => ptr(subject)).to.throw(Error, "Value at '/foo/0' is a string and does not have property '0'");
76
- });
77
- });
78
-
79
- describe("indexing into a null", () => {
80
- it("should throw an error", () => {
81
- const ptr = JsonPointer.get("/aaa/0");
82
- expect(() => ptr(subject)).to.throw(Error, "Value at '/aaa' is null and does not have property '0'");
83
- });
84
- });
85
-
86
- describe("a pointer that doesn't start with '/'", () => {
87
- it("should throw an error", () => {
88
- expect(() => JsonPointer.get("foo")).to.throw(Error, "Invalid JSON Pointer");
89
- });
90
- });
91
- });
@@ -1,9 +0,0 @@
1
- import { Suite, Test, Func } from "mocha";
2
-
3
-
4
- type SuiteFunc = (this: Suite) => void;
5
-
6
- export const Given = (message: string, fn: SuiteFunc): Suite => describe("Given " + message, fn);
7
- export const When = (message: string, fn: SuiteFunc): Suite => describe("When " + message, fn);
8
- export const Then = (message: string, fn: Func): Test => it("Then " + message, fn);
9
- export const And = (message: string, fn: SuiteFunc): Suite => describe("And " + message, fn);
@@ -1,160 +0,0 @@
1
- import { expect } from "chai";
2
- import { Given, When, Then } from "./mocha-gherkin.spec";
3
- import JsonPointer, { Json, JsonObject, Pointable } from ".";
4
-
5
-
6
- describe("JsonPointer.remove", () => {
7
- Given("The nil pointer", () => {
8
- const pointer = JsonPointer.nil;
9
-
10
- When("deleting any value", () => {
11
- const subject = { foo: "bar" };
12
- JsonPointer.remove(pointer, subject);
13
-
14
- Then("the value is not changed", () => {
15
- expect(subject).to.eql({ foo: "bar" });
16
- });
17
- });
18
- });
19
-
20
- Given("a pointer to a property of an object", () => {
21
- const pointer = "/aaa";
22
-
23
- When("deleting a property", () => {
24
- const subject = { "aaa": 111, "bbb": [] };
25
- JsonPointer.remove(pointer, subject);
26
-
27
- Then("the value should be removed", () => {
28
- expect(subject).to.eql({ "bbb": [] });
29
- });
30
- });
31
- });
32
-
33
- Given("a pointer to an item of an array", () => {
34
- const pointer = "/0";
35
-
36
- When("deleting an item", () => {
37
- const subject = [111, 222];
38
- JsonPointer.remove(pointer, subject);
39
-
40
- Then("the value should be removed", () => {
41
- expect(subject).to.eql([222]);
42
- });
43
- });
44
- });
45
-
46
- Given("a pointer to a nested property of an object", () => {
47
- const pointer = "/aaa/ccc";
48
-
49
- When("deleting a property", () => {
50
- const subject = { "aaa": { "ccc": 333, "ddd": 444 }, "bbb": 222 };
51
- JsonPointer.remove(pointer, subject);
52
-
53
- Then("the value should be removed", () => {
54
- expect(subject).to.eql({ "aaa": { "ddd": 444 }, "bbb": 222 });
55
- });
56
- });
57
- });
58
-
59
- Given("an object", () => {
60
- let subject: JsonObject;
61
-
62
- beforeEach(() => {
63
- subject = { aaa: { bbb: {} } };
64
- });
65
-
66
- When("deleting a value that doesn't exist", () => {
67
- beforeEach(() => {
68
- JsonPointer.remove("/bbb", subject);
69
- });
70
-
71
- Then("the value should be unchanged", () => {
72
- expect(subject).to.eql({ aaa: { bbb: {} } });
73
- });
74
- });
75
-
76
- When("deleting a value whose parent doesn't exist", () => {
77
- const remove = JsonPointer.remove("/aaa/ccc/bbb");
78
-
79
- Then("an error should be thrown", () => {
80
- expect(() => remove(subject)).to.throw(Error, "Value at '/aaa/ccc' is undefined and does not have property 'bbb'");
81
- });
82
- });
83
- });
84
-
85
- Given("an array", () => {
86
- let subject: Json[];
87
-
88
- beforeEach(() => {
89
- subject = [];
90
- });
91
-
92
- When("deleting a value that doesn't exist", () => {
93
- beforeEach(() => {
94
- JsonPointer.remove("/0", subject);
95
- });
96
-
97
- Then("the value should be unchanged", () => {
98
- expect(subject).to.eql([]);
99
- });
100
- });
101
-
102
- When("deleting past the end of the array", () => {
103
- beforeEach(() => {
104
- JsonPointer.remove("/-", subject);
105
- });
106
-
107
- Then("the value should be unchanged", () => {
108
- expect(subject).to.eql([]);
109
- });
110
- });
111
- });
112
-
113
- Given("a number", () => {
114
- let subject: unknown;
115
-
116
- beforeEach(() => {
117
- subject = 42;
118
- });
119
-
120
- When("indexing into the number", () => {
121
- const remove = JsonPointer.remove("/0");
122
-
123
- Then("an error should be thrown", () => {
124
- expect(() => remove(subject as Pointable)).to.throw(Error, "Value at '' is a number and does not have property '0'");
125
- });
126
- });
127
- });
128
-
129
- Given("a string", () => {
130
- let subject: unknown;
131
-
132
- beforeEach(() => {
133
- subject = "foo";
134
- });
135
-
136
- When("indexing into the string", () => {
137
- const remove = JsonPointer.remove("/0");
138
-
139
- Then("an error should be thrown", () => {
140
- expect(() => remove(subject as Pointable)).to.throw(Error, "Value at '' is a string and does not have property '0'");
141
- });
142
- });
143
- });
144
-
145
- Given("null", () => {
146
- let subject: unknown;
147
-
148
- beforeEach(() => {
149
- subject = null;
150
- });
151
-
152
- When("indexing into null", () => {
153
- const remove = JsonPointer.remove("/0");
154
-
155
- Then("an error should be thrown", () => {
156
- expect(() => remove(subject as Pointable)).to.throw(Error, "Value at '' is null and does not have property '0'");
157
- });
158
- });
159
- });
160
- });
package/lib/set.spec.ts DELETED
@@ -1,207 +0,0 @@
1
- import { expect } from "chai";
2
- import { Given, When, Then } from "./mocha-gherkin.spec";
3
- import JsonPointer, { Json, JsonObject, Pointable } from ".";
4
-
5
-
6
- describe("JsonPointer.set", () => {
7
- Given("The nil pointer", () => {
8
- const pointer = JsonPointer.nil;
9
-
10
- When("setting any value", () => {
11
- const subject = { foo: "bar" };
12
- const result = JsonPointer.set(pointer, subject, "foo");
13
-
14
- Then("the value is echoed back", () => {
15
- expect(result).to.equal("foo");
16
- });
17
-
18
- Then("the original value should not change", () => {
19
- expect(subject).to.eql({ foo: "bar" });
20
- });
21
- });
22
- });
23
-
24
- Given("a pointer to a property of an object", () => {
25
- const pointer = "/aaa";
26
-
27
- When("setting a property", () => {
28
- const subject = { "aaa": 111, "bbb": [] };
29
- const result = JsonPointer.set(pointer, subject, "foo");
30
-
31
- Then("the new value should be set", () => {
32
- expect(result.aaa).to.equal("foo");
33
- });
34
-
35
- Then("the original value should not change", () => {
36
- expect(subject.aaa).to.equal(111);
37
- });
38
-
39
- Then("the other properties should not change", () => {
40
- expect(result.bbb).to.equal(subject.bbb);
41
- });
42
- });
43
- });
44
-
45
- Given("a pointer to an item of an array", () => {
46
- const pointer = "/0";
47
-
48
- When("setting an item", () => {
49
- const subject = [111, []];
50
- const result = JsonPointer.set(pointer, subject, "foo");
51
-
52
- Then("the new value should be set", () => {
53
- expect(result[0]).to.equal("foo");
54
- });
55
-
56
- Then("the original value should not change", () => {
57
- expect(subject[0]).to.equal(111);
58
- });
59
-
60
- Then("the other items should not change", () => {
61
- expect(result[1]).to.equal(subject[1]);
62
- });
63
- });
64
- });
65
-
66
- Given("a pointer to a nested property of an object", () => {
67
- const pointer = "/aaa/ccc";
68
-
69
- When("setting a property", () => {
70
- const subject = { "aaa": { "ccc": 333, "ddd": 444 }, "bbb": 222 };
71
- const result = JsonPointer.set(pointer, subject, "foo");
72
-
73
- Then("the new value should be set", () => {
74
- expect(result.aaa.ccc).to.equal("foo");
75
- });
76
-
77
- Then("the original value should not change", () => {
78
- expect(subject.aaa.ccc).to.equal(333);
79
- });
80
-
81
- Then("the other properties should not change", () => {
82
- expect(result.bbb).to.equal(subject.bbb);
83
- expect(result.aaa.ddd).to.equal(subject.aaa.ddd);
84
- });
85
- });
86
- });
87
-
88
- Given("an object", () => {
89
- let subject: JsonObject;
90
-
91
- beforeEach(() => {
92
- subject = { aaa: { bbb: {} } };
93
- });
94
-
95
- When("setting a value that doesn't exist", () => {
96
- let result: JsonObject;
97
-
98
- beforeEach(() => {
99
- result = JsonPointer.set("/bbb", subject, "foo");
100
- });
101
-
102
- Then("the value should be set", () => {
103
- expect(result.bbb).to.equal("foo");
104
- });
105
-
106
- Then("the original value should not change", () => {
107
- expect(subject.bbb).to.equal(undefined);
108
- });
109
- });
110
-
111
- When("setting a value whose parent doesn't exist", () => {
112
- const set = JsonPointer.set("/aaa/ccc/bbb");
113
-
114
- Then("an error should be thrown", () => {
115
- expect(() => set(subject, "foo")).to.throw(Error, "Value at '/aaa/ccc' is undefined and does not have property 'bbb'");
116
- });
117
- });
118
- });
119
-
120
- Given("an array", () => {
121
- let subject: Json[];
122
-
123
- beforeEach(() => {
124
- subject = [];
125
- });
126
-
127
- When("setting a value that doesn't exist", () => {
128
- let result: Json[];
129
-
130
- beforeEach(() => {
131
- result = JsonPointer.set("/0", subject, "foo");
132
- });
133
-
134
- Then("the value should be set", () => {
135
- expect(result[0]).to.equal("foo");
136
- });
137
-
138
- Then("the original value should not change", () => {
139
- expect(subject[0]).to.equal(undefined);
140
- });
141
- });
142
-
143
- When("adding an item to the end of the array", () => {
144
- let result: Json[];
145
-
146
- beforeEach(() => {
147
- result = JsonPointer.set("/-", subject, "foo");
148
- });
149
-
150
- Then("the value should be set", () => {
151
- expect(result[0]).to.equal("foo");
152
- });
153
-
154
- Then("the original value should not change", () => {
155
- expect(subject[0]).to.equal(undefined);
156
- });
157
- });
158
- });
159
-
160
- Given("a number", () => {
161
- let subject: unknown;
162
-
163
- beforeEach(() => {
164
- subject = 42;
165
- });
166
-
167
- When("indexing into the number", () => {
168
- const set = JsonPointer.set("/0");
169
-
170
- Then("an error should be thrown", () => {
171
- expect(() => set(subject as Pointable, "foo")).to.throw(TypeError, "Value at '' is a number and does not have property '0'");
172
- });
173
- });
174
- });
175
-
176
- Given("a string", () => {
177
- let subject: unknown;
178
-
179
- beforeEach(() => {
180
- subject = "foo";
181
- });
182
-
183
- When("indexing into the string", () => {
184
- const set = JsonPointer.set("/0");
185
-
186
- Then("an error should be thrown", () => {
187
- expect(() => set(subject as Pointable, "foo")).to.throw(TypeError, "Value at '' is a string and does not have property '0'");
188
- });
189
- });
190
- });
191
-
192
- Given("null", () => {
193
- let subject: unknown;
194
-
195
- beforeEach(() => {
196
- subject = null;
197
- });
198
-
199
- When("indexing into null", () => {
200
- const set = JsonPointer.set("/0");
201
-
202
- Then("an error should be thrown", () => {
203
- expect(() => set(subject as Pointable, "foo")).to.throw(Error, "Value at '' is null and does not have property '0'");
204
- });
205
- });
206
- });
207
- });
package/lib/unset.spec.ts DELETED
@@ -1,198 +0,0 @@
1
- import { expect } from "chai";
2
- import { Given, When, Then } from "./mocha-gherkin.spec";
3
- import JsonPointer, { Json, JsonObject, Pointable } from ".";
4
-
5
-
6
- describe("JsonPointer.unset", () => {
7
- Given("The nil pointer", () => {
8
- const pointer = JsonPointer.nil;
9
-
10
- When("deleting any value", () => {
11
- const subject = { foo: "bar" };
12
- const result = JsonPointer.unset(pointer, subject);
13
-
14
- Then("the value is undefined", () => {
15
- expect(result).to.equal(undefined);
16
- });
17
-
18
- Then("the original value should not change", () => {
19
- expect(subject).to.eql({ foo: "bar" });
20
- });
21
- });
22
- });
23
-
24
- Given("a pointer to a property of an object", () => {
25
- const pointer = "/aaa";
26
-
27
- When("deleting a property", () => {
28
- const subject = { "aaa": 111, "bbb": [] };
29
- const result = JsonPointer.unset(pointer, subject);
30
-
31
- Then("the value should be undefined", () => {
32
- expect(result.aaa).to.equal(undefined);
33
- });
34
-
35
- Then("the original value should not change", () => {
36
- expect(subject.aaa).to.equal(111);
37
- });
38
-
39
- Then("the other properties should not change", () => {
40
- expect(result.bbb).to.equal(subject.bbb);
41
- });
42
- });
43
- });
44
-
45
- Given("a pointer to an item of an array", () => {
46
- const pointer = "/0";
47
-
48
- When("deleting an item", () => {
49
- const subject = [111, []];
50
- const result = JsonPointer.unset(pointer, subject);
51
-
52
- Then("the value should be removed", () => {
53
- expect(result).to.eql([[]]);
54
- });
55
-
56
- Then("the original value should not change", () => {
57
- expect(subject[0]).to.equal(111);
58
- });
59
-
60
- Then("the other items should not change", () => {
61
- expect(result[0]).to.equal(subject[1]);
62
- });
63
- });
64
- });
65
-
66
- Given("a pointer to a nested property of an object", () => {
67
- const pointer = "/aaa/ccc";
68
-
69
- When("deleting a property", () => {
70
- const subject = { "aaa": { "ccc": 333, "ddd": 444 }, "bbb": 222 };
71
- const result = JsonPointer.unset(pointer, subject);
72
-
73
- Then("the value should be undefined", () => {
74
- expect(result.aaa.ccc).to.equal(undefined);
75
- });
76
-
77
- Then("the original value should not change", () => {
78
- expect(subject.aaa.ccc).to.equal(333);
79
- });
80
-
81
- Then("the other properties should not change", () => {
82
- expect(result.bbb).to.equal(subject.bbb);
83
- expect(result.aaa.ddd).to.equal(subject.aaa.ddd);
84
- });
85
- });
86
- });
87
-
88
- Given("an object", () => {
89
- let subject: JsonObject;
90
-
91
- beforeEach(() => {
92
- subject = { aaa: { bbb: {} } };
93
- });
94
-
95
- When("deleting a value that doesn't exist", () => {
96
- let result: JsonObject;
97
- beforeEach(() => {
98
- result = JsonPointer.unset("/bbb", subject);
99
- });
100
-
101
- Then("the value should be undefined", () => {
102
- expect(result.bbb).to.equal(undefined);
103
- });
104
-
105
- Then("the original value should not change", () => {
106
- expect(subject.bbb).to.equal(undefined);
107
- });
108
- });
109
-
110
- When("deleting a value whose parent doesn't exist", () => {
111
- const unset = JsonPointer.unset("/aaa/ccc/bbb");
112
-
113
- Then("an error should be thrown", () => {
114
- expect(() => unset(subject)).to.throw(Error, "Value at '/aaa/ccc' is undefined and does not have property 'bbb'");
115
- });
116
- });
117
- });
118
-
119
- Given("an array", () => {
120
- let subject: Json[];
121
-
122
- beforeEach(() => {
123
- subject = [];
124
- });
125
-
126
- When("deleting a value that doesn't exist", () => {
127
- let result: Json[];
128
-
129
- beforeEach(() => {
130
- result = JsonPointer.unset("/0", subject);
131
- });
132
-
133
- Then("the original value should not change", () => {
134
- expect(result).to.eql(subject);
135
- });
136
- });
137
-
138
- When("deleting past the end of the array", () => {
139
- let result: Json[];
140
-
141
- beforeEach(() => {
142
- result = JsonPointer.unset("/-", subject);
143
- });
144
-
145
- Then("the original value should not change", () => {
146
- expect(result).to.eql(subject);
147
- });
148
- });
149
- });
150
-
151
- Given("a number", () => {
152
- let subject: unknown;
153
-
154
- beforeEach(() => {
155
- subject = 42;
156
- });
157
-
158
- When("indexing into the number", () => {
159
- const unset = JsonPointer.unset("/0");
160
-
161
- Then("an error should be thrown", () => {
162
- expect(() => unset(subject as Pointable)).to.throw(Error, "Value at '' is a number and does not have property '0'");
163
- });
164
- });
165
- });
166
-
167
- Given("a string", () => {
168
- let subject: unknown;
169
-
170
- beforeEach(() => {
171
- subject = "foo";
172
- });
173
-
174
- When("indexing into the string", () => {
175
- const unset = JsonPointer.unset("/0");
176
-
177
- Then("an error should be thrown", () => {
178
- expect(() => unset(subject as Pointable)).to.throw(Error, "Value at '' is a string and does not have property '0'");
179
- });
180
- });
181
- });
182
-
183
- Given("null", () => {
184
- let subject: unknown;
185
-
186
- beforeEach(() => {
187
- subject = null;
188
- });
189
-
190
- When("indexing into null", () => {
191
- const unset = JsonPointer.unset("/0");
192
-
193
- Then("an error should be thrown", () => {
194
- expect(() => unset(subject as Pointable)).to.throw(Error, "Value at '' is null and does not have property '0'");
195
- });
196
- });
197
- });
198
- });
package/tsconfig.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "commonjs",
4
- "target": "es2015",
5
- "moduleResolution": "node",
6
- "esModuleInterop": true,
7
- "strict": true,
8
- "allowJs": true
9
- }
10
- }