Skip to content

Commit fc525b8

Browse files
committed
Strings are inferred last for better performance
1 parent 97eedca commit fc525b8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/index.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export {
3535
} from "./@types";
3636

3737
export function inferType(value: unknown): JSONValueType {
38-
if (value === null) {
39-
return { name: "null", value };
38+
if (value == null) {
39+
return { name: "null", value: null };
4040
}
4141

4242
if (typeof value === "boolean") {
@@ -51,14 +51,6 @@ export function inferType(value: unknown): JSONValueType {
5151
}
5252
}
5353

54-
if (typeof value === "string") {
55-
return {
56-
name: "string",
57-
value,
58-
format: inferFormat(value),
59-
};
60-
}
61-
6254
if (typeof value === "object") {
6355
if (Array.isArray(value)) {
6456
return {
@@ -74,5 +66,13 @@ export function inferType(value: unknown): JSONValueType {
7466
};
7567
}
7668

69+
if (typeof value === "string") {
70+
return {
71+
name: "string",
72+
value,
73+
format: inferFormat(value),
74+
};
75+
}
76+
7777
return { name: "null", value: null };
7878
}

0 commit comments

Comments
 (0)