Skip to content

Commit d1c63c9

Browse files
committed
Drop jsonTypeOf and Hyperjump.typeOf
1 parent 8dc3de5 commit d1c63c9

File tree

6 files changed

+21
-89
lines changed

6 files changed

+21
-89
lines changed

src/hyperjump/hyperjump.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { JsonCompatible } from "../json/jsonast.d.ts";
22
import type { JrefNode } from "../jref/jref-ast.d.ts";
33
import type { UriSchemePlugin } from "./uri-schemes/uri-scheme-plugin.d.ts";
44
import type { DocumentNode, MediaTypePlugin } from "./media-types/media-type-plugin.d.ts";
5-
import type { jsonObjectHas, jsonObjectKeys, jsonTypeOf, jsonValue } from "../json/jsonast-util.js";
5+
import type { jsonObjectHas, jsonObjectKeys, jsonValue } from "../json/jsonast-util.js";
66

77

88
export type HyperjumpConfig = object;
@@ -87,7 +87,6 @@ export class Hyperjump<T extends JrefNode = JrefNode> {
8787
setMediaTypeQuality: (contentType: string, quality: number) => void;
8888

8989
value: typeof jsonValue;
90-
typeOf: typeof jsonTypeOf;
9190
has: typeof jsonObjectHas;
9291

9392
/**

src/hyperjump/hyperjump.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { FileUriSchemePlugin } from "./uri-schemes/file-scheme-plugin.js";
66
import { JsonMediaTypePlugin } from "./media-types/json-media-type-plugin.js";
77
import { JrefMediaTypePlugin } from "./media-types/jref-media-type-plugin.js";
88
import { pointerGet, pointerStep } from "../jref/jref-util.js";
9-
import { jsonObjectHas, jsonObjectKeys, jsonTypeOf, jsonValue } from "../json/jsonast-util.js";
9+
import { jsonObjectHas, jsonObjectKeys, jsonValue } from "../json/jsonast-util.js";
1010
import { mimeMatch } from "./utilities.js";
1111

1212
/**
@@ -201,7 +201,6 @@ export class Hyperjump {
201201
}
202202

203203
value = jsonValue;
204-
typeOf = jsonTypeOf;
205204
has = jsonObjectHas;
206205

207206
/** @type API.Hyperjump<T>["step"] */

src/hyperjump/node-functions.test.js

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,68 +71,41 @@ describe("JSON Browser", () => {
7171

7272
test("null", async () => {
7373
const node = await hyperjump.get(`${testDomain}/foo#/null`);
74-
if (hyperjump.typeOf(node, "null")) {
75-
/** @type null */
76-
const subject = hyperjump.value(node);
77-
expect(subject).to.equal(null);
78-
} else {
79-
expect.fail();
80-
}
74+
const subject = hyperjump.value(node);
75+
expect(subject).to.equal(null);
8176
});
8277

8378
test("true", async () => {
8479
const node = await hyperjump.get(`${testDomain}/foo#/true`);
85-
if (hyperjump.typeOf(node, "boolean")) {
86-
/** @type boolean */
87-
const subject = hyperjump.value(node);
88-
expect(subject).to.equal(true);
89-
} else {
90-
expect.fail();
91-
}
80+
const subject = hyperjump.value(node);
81+
expect(subject).to.equal(true);
9282
});
9383

9484
test("false", async () => {
9585
const node = await hyperjump.get(`${testDomain}/foo#/false`);
96-
if (hyperjump.typeOf(node, "boolean")) {
97-
/** @type boolean */
98-
const subject = hyperjump.value(node);
99-
expect(subject).to.equal(false);
100-
} else {
101-
expect.fail();
102-
}
86+
const subject = hyperjump.value(node);
87+
expect(subject).to.equal(false);
10388
});
10489

10590
test("number", async () => {
10691
const node = await hyperjump.get(`${testDomain}/foo#/number`);
107-
if (hyperjump.typeOf(node, "number")) {
108-
/** @type number */
109-
const subject = hyperjump.value(node);
110-
expect(subject).to.equal(42);
111-
} else {
112-
expect.fail();
113-
}
92+
const subject = hyperjump.value(node);
93+
expect(subject).to.equal(42);
11494
});
11595

11696
test("string", async () => {
11797
const node = await hyperjump.get(`${testDomain}/foo#/string`);
118-
if (hyperjump.typeOf(node, "string")) {
119-
/** @type string */
120-
const subject = hyperjump.value(node);
121-
expect(subject).to.equal("foo");
122-
} else {
123-
expect.fail();
124-
}
98+
const subject = hyperjump.value(node);
99+
expect(subject).to.equal("foo");
125100
});
126101

127102
test("array", async () => {
128103
const node = await hyperjump.get(`${testDomain}/foo#/array`);
129-
expect(hyperjump.typeOf(node, "array")).to.equal(true);
130104
expect(() => hyperjump.value(node)).to.throw();
131105
});
132106

133107
test("object", async () => {
134108
const node = await hyperjump.get(`${testDomain}/foo#/object`);
135-
expect(hyperjump.typeOf(node, "object")).to.equal(true);
136109
expect(() => hyperjump.value(node)).to.throw();
137110
});
138111
});

src/json/jsonast-util.d.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
JsonNullNode,
88
JsonNumberNode,
99
JsonObjectNode,
10-
JsonStringNode,
11-
JsonType
10+
JsonStringNode
1211
} from "./jsonast.d.ts";
1312

1413
export type Reviver<A = JsonNode> = (node: JsonCompatible<NonNullable<A>>, key?: string) => A;
@@ -57,16 +56,6 @@ export const jsonValue: (
5756
(<A>(node: JsonCompatible<A>) => Json)
5857
);
5958

60-
export const jsonTypeOf: (
61-
(<A>(node: JsonCompatible<A>, type: "null") => node is JsonNullNode) &
62-
(<A>(node: JsonCompatible<A>, type: "boolean") => node is JsonBooleanNode) &
63-
(<A>(node: JsonCompatible<A>, type: "number") => node is JsonNumberNode) &
64-
(<A>(node: JsonCompatible<A>, type: "string") => node is JsonStringNode) &
65-
(<A>(node: JsonCompatible<A>, type: "array") => node is JsonArrayNode<A>) &
66-
(<A>(node: JsonCompatible<A>, type: "object") => node is JsonObjectNode<A>) &
67-
(<A>(node: JsonCompatible<A>, type: JsonType) => boolean)
68-
);
69-
7059
export const jsonObjectHas: <A>(key: string, node: JsonCompatible<A>) => boolean;
7160

7261
export const jsonArrayIter: <A>(node: JsonCompatible<A>) => Generator<A, void, unknown>;

src/json/jsonast-util.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,6 @@ export const jsonValue = /** @type API.jsonValue */ ((node) => {
387387
}
388388
});
389389

390-
// eslint-disable-next-line @stylistic/no-extra-parens
391-
export const jsonTypeOf = /** @type API.jsonTypeOf */ ((node, type) => {
392-
return node.jsonType === type;
393-
});
394-
395390
/** @type API.jsonObjectHas */
396391
export const jsonObjectHas = (key, node) => {
397392
if (node.jsonType === "object") {

src/json/jsonast-util.test.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
rejson,
99
rejsonStringify,
1010
jsonObjectHas,
11-
jsonTypeOf,
1211
jsonArrayIter,
1312
jsonObjectKeys,
1413
jsonObjectValues,
@@ -56,57 +55,35 @@ describe("jsonast-util", async () => {
5655
describe("type/value and type narrowing", () => {
5756
test("null", () => {
5857
const node = fromJson(`null`);
59-
if (jsonTypeOf(node, "null")) {
60-
/** @type null */
61-
const subject = jsonValue(node);
62-
expect(subject).to.equal(null);
63-
} else {
64-
expect.fail();
65-
}
58+
const subject = jsonValue(node);
59+
expect(subject).to.equal(null);
6660
});
6761

6862
test("boolean", () => {
6963
const node = fromJson(`true`);
70-
if (jsonTypeOf(node, "boolean")) {
71-
/** @type boolean */
72-
const subject = jsonValue(node);
73-
expect(subject).to.equal(true);
74-
} else {
75-
expect.fail();
76-
}
64+
const subject = jsonValue(node);
65+
expect(subject).to.equal(true);
7766
});
7867

7968
test("number", () => {
8069
const node = fromJson(`42`);
81-
if (jsonTypeOf(node, "number")) {
82-
/** @type number */
83-
const subject = jsonValue(node);
84-
expect(subject).to.equal(42);
85-
} else {
86-
expect.fail();
87-
}
70+
const subject = jsonValue(node);
71+
expect(subject).to.equal(42);
8872
});
8973

9074
test("string", () => {
9175
const node = fromJson(`"foo"`);
92-
if (jsonTypeOf(node, "string")) {
93-
/** @type string */
94-
const subject = jsonValue(node);
95-
expect(subject).to.equal("foo");
96-
} else {
97-
expect.fail();
98-
}
76+
const subject = jsonValue(node);
77+
expect(subject).to.equal("foo");
9978
});
10079

10180
test("array", () => {
10281
const node = fromJson(`["foo", 42]`);
103-
expect(jsonTypeOf(node, "array")).to.equal(true);
10482
expect(() => jsonValue(node)).to.throw();
10583
});
10684

10785
test("object", () => {
10886
const node = fromJson(`{ "foo": 42 }`);
109-
expect(jsonTypeOf(node, "object")).to.equal(true);
11087
expect(() => jsonValue(node)).to.throw();
11188
});
11289
});

0 commit comments

Comments
 (0)