npm run format -ws

This commit is contained in:
Josh Gross
2023-01-09 19:02:19 -05:00
parent 3df70b2491
commit c49981ec64
113 changed files with 3252 additions and 4573 deletions
+1 -6
View File
@@ -1,9 +1,4 @@
import {
ExpressionData,
ExpressionDataInterface,
Kind,
kindStr,
} from "./expressiondata";
import {ExpressionData, ExpressionDataInterface, Kind, kindStr} from "./expressiondata";
export class Array implements ExpressionDataInterface {
private v: ExpressionData[] = [];
+1 -1
View File
@@ -1,4 +1,4 @@
import { ExpressionDataInterface, Kind } from "./expressiondata";
import {ExpressionDataInterface, Kind} from "./expressiondata";
export class BooleanData implements ExpressionDataInterface {
constructor(public readonly value: boolean) {}
@@ -1,12 +1,12 @@
import { Dictionary } from "./dictionary";
import { StringData } from "./string";
import {Dictionary} from "./dictionary";
import {StringData} from "./string";
describe("dictionary", () => {
it("pairs contains all values", () => {
const d = new Dictionary();
d.add("ABC", new StringData("val"));
expect(d.pairs()).toEqual([{ key: "ABC", value: new StringData("val") }]);
expect(d.pairs()).toEqual([{key: "ABC", value: new StringData("val")}]);
});
it("does not add duplicate entries", () => {
@@ -14,6 +14,6 @@ describe("dictionary", () => {
d.add("ABC", new StringData("val1"));
d.add("abc", new StringData("val2"));
expect(d.pairs()).toEqual([{ key: "ABC", value: new StringData("val1") }]);
expect(d.pairs()).toEqual([{key: "ABC", value: new StringData("val1")}]);
});
});
+3 -9
View File
@@ -1,15 +1,9 @@
import {
ExpressionData,
ExpressionDataInterface,
Kind,
kindStr,
Pair,
} from "./expressiondata";
import {ExpressionData, ExpressionDataInterface, Kind, kindStr, Pair} from "./expressiondata";
export class Dictionary implements ExpressionDataInterface {
private keys: string[] = [];
private v: ExpressionData[] = [];
private indexMap: { [key: string]: number } = {};
private indexMap: {[key: string]: number} = {};
constructor(...pairs: Pair[]) {
for (const p of pairs) {
@@ -56,7 +50,7 @@ export class Dictionary implements ExpressionDataInterface {
const result: Pair[] = [];
for (const key of this.keys) {
result.push({ key, value: this.v[this.indexMap[key.toLowerCase()]] });
result.push({key, value: this.v[this.indexMap[key.toLowerCase()]]});
}
return result;
+8 -14
View File
@@ -1,9 +1,9 @@
import { Dictionary } from "./dictionary";
import { Null } from "./null";
import { Array } from "./array";
import { StringData } from "./string";
import { NumberData } from "./number";
import { BooleanData } from "./boolean";
import {Dictionary} from "./dictionary";
import {Null} from "./null";
import {Array} from "./array";
import {StringData} from "./string";
import {NumberData} from "./number";
import {BooleanData} from "./boolean";
export enum Kind {
String = 0,
@@ -12,7 +12,7 @@ export enum Kind {
Boolean,
Number,
CaseSensitiveDictionary,
Null,
Null
}
export function kindStr(k: Kind): string {
@@ -43,13 +43,7 @@ export interface ExpressionDataInterface {
number(): number;
}
export type ExpressionData =
| Array
| Dictionary
| StringData
| BooleanData
| NumberData
| Null;
export type ExpressionData = Array | Dictionary | StringData | BooleanData | NumberData | Null;
export type Pair = {
key: string;
+9 -9
View File
@@ -1,9 +1,9 @@
export { Array } from "./array";
export { BooleanData } from "./boolean";
export { Dictionary } from "./dictionary";
export { ExpressionData, Kind } from "./expressiondata";
export { Null } from "./null";
export { NumberData } from "./number";
export { replacer } from "./replacer";
export { reviver } from "./reviver";
export { StringData } from "./string";
export {Array} from "./array";
export {BooleanData} from "./boolean";
export {Dictionary} from "./dictionary";
export {ExpressionData, Kind} from "./expressiondata";
export {Null} from "./null";
export {NumberData} from "./number";
export {replacer} from "./replacer";
export {reviver} from "./reviver";
export {StringData} from "./string";
+1 -5
View File
@@ -1,8 +1,4 @@
import {
ExpressionData,
ExpressionDataInterface,
Kind,
} from "./expressiondata";
import {ExpressionData, ExpressionDataInterface, Kind} from "./expressiondata";
export class Null implements ExpressionDataInterface {
constructor() {}
+1 -1
View File
@@ -1,4 +1,4 @@
import { ExpressionDataInterface, Kind } from "./expressiondata";
import {ExpressionDataInterface, Kind} from "./expressiondata";
export class NumberData implements ExpressionDataInterface {
constructor(public readonly value: number) {}
+12 -20
View File
@@ -1,9 +1,9 @@
import { Array } from "./array";
import { Dictionary } from "./dictionary";
import { Null } from "./null";
import { NumberData } from "./number";
import { replacer } from "./replacer";
import { StringData } from "./string";
import {Array} from "./array";
import {Dictionary} from "./dictionary";
import {Null} from "./null";
import {NumberData} from "./number";
import {replacer} from "./replacer";
import {StringData} from "./string";
describe("replacer", () => {
it("null", () => {
@@ -11,22 +11,14 @@ describe("replacer", () => {
});
it("array", () => {
expect(
JSON.stringify(
new Array(new StringData("a"), new StringData("b")),
replacer,
" "
)
).toEqual('[\n "a",\n "b"\n]');
expect(JSON.stringify(new Array(new StringData("a"), new StringData("b")), replacer, " ")).toEqual(
'[\n "a",\n "b"\n]'
);
});
it("dictionary", () => {
expect(
JSON.stringify(
new Dictionary({ key: "a", value: new NumberData(42) }),
replacer,
" "
)
).toEqual('{\n "a": 42\n}');
expect(JSON.stringify(new Dictionary({key: "a", value: new NumberData(42)}), replacer, " ")).toEqual(
'{\n "a": 42\n}'
);
});
});
+6 -6
View File
@@ -1,9 +1,9 @@
import { Array } from "./array";
import { BooleanData } from "./boolean";
import { Dictionary } from "./dictionary";
import { Null } from "./null";
import { NumberData } from "./number";
import { StringData } from "./string";
import {Array} from "./array";
import {BooleanData} from "./boolean";
import {Dictionary} from "./dictionary";
import {Null} from "./null";
import {NumberData} from "./number";
import {StringData} from "./string";
/**
* Replacer can be passed to JSON.stringify to convert an ExpressionData object into plain JSON
+25 -28
View File
@@ -1,11 +1,11 @@
import { Array } from "./array";
import { BooleanData } from "./boolean";
import { Dictionary } from "./dictionary";
import { ExpressionData } from "./expressiondata";
import { Null } from "./null";
import { NumberData } from "./number";
import { reviver } from "./reviver";
import { StringData } from "./string";
import {Array} from "./array";
import {BooleanData} from "./boolean";
import {Dictionary} from "./dictionary";
import {ExpressionData} from "./expressiondata";
import {Null} from "./null";
import {NumberData} from "./number";
import {reviver} from "./reviver";
import {StringData} from "./string";
describe("reviver", () => {
const tests: {
@@ -16,32 +16,32 @@ describe("reviver", () => {
{
name: "null",
data: "null",
want: new Null(),
want: new Null()
},
{
name: "number",
data: "1",
want: new NumberData(1),
want: new NumberData(1)
},
{
name: "string",
data: `"a"`,
want: new StringData("a"),
want: new StringData("a")
},
{
name: "true boolean",
data: "true",
want: new BooleanData(true),
want: new BooleanData(true)
},
{
name: "false boolean",
data: "false",
want: new BooleanData(false),
want: new BooleanData(false)
},
{
name: "array",
data: `[1,2,3]`,
want: new Array(new NumberData(1), new NumberData(2), new NumberData(3)),
want: new Array(new NumberData(1), new NumberData(2), new NumberData(3))
},
{
name: "nested array",
@@ -51,7 +51,7 @@ describe("reviver", () => {
new NumberData(2),
new Array(new NumberData(3), new NumberData(4)),
new NumberData(5)
),
)
},
{
name: "complex array",
@@ -59,26 +59,23 @@ describe("reviver", () => {
want: new Array(
new Dictionary({
key: "a",
value: new Array(new BooleanData(true), new NumberData(2)),
value: new Array(new BooleanData(true), new NumberData(2))
}),
new Dictionary({ key: "b", value: new StringData("three") }),
new Dictionary({ key: "c", value: new Null() })
),
new Dictionary({key: "b", value: new StringData("three")}),
new Dictionary({key: "c", value: new Null()})
)
},
{
name: "dictionary",
data: `{ "object1": {} }`,
want: new Dictionary({
key: "object1",
value: new Dictionary(),
}),
},
value: new Dictionary()
})
}
];
test.each(tests)(
"$name",
({ data, want }: { data: string; want: ExpressionData }) => {
expect(JSON.parse(data, reviver)).toEqual(want);
}
);
test.each(tests)("$name", ({data, want}: {data: string; want: ExpressionData}) => {
expect(JSON.parse(data, reviver)).toEqual(want);
});
});
+9 -9
View File
@@ -1,10 +1,10 @@
import { Array as dArray } from "./array";
import { BooleanData } from "./boolean";
import { Dictionary } from "./dictionary";
import { ExpressionData, Pair } from "./expressiondata";
import { Null } from "./null";
import { NumberData } from "./number";
import { StringData } from "./string";
import {Array as dArray} from "./array";
import {BooleanData} from "./boolean";
import {Dictionary} from "./dictionary";
import {ExpressionData, Pair} from "./expressiondata";
import {Null} from "./null";
import {NumberData} from "./number";
import {StringData} from "./string";
/**
* Reviver can be passed to `JSON.parse` to convert plain JSON into an `ExpressionData` object.
@@ -35,10 +35,10 @@ export function reviver(key: string, val: any): ExpressionData {
if (typeof val === "object") {
return new Dictionary(
...Object.keys(val).map(
(k) =>
k =>
({
key: k,
value: val[k],
value: val[k]
} as Pair)
)
);
+1 -1
View File
@@ -1,4 +1,4 @@
import { ExpressionDataInterface, Kind } from "./expressiondata";
import {ExpressionDataInterface, Kind} from "./expressiondata";
export class StringData implements ExpressionDataInterface {
constructor(public readonly value: string) {}