diff options
Diffstat (limited to 'src/serializers')
| -rw-r--r-- | src/serializers/to_json.test.ts | 12 | ||||
| -rw-r--r-- | src/serializers/to_json.ts | 6 | ||||
| -rw-r--r-- | src/serializers/to_object.test.ts | 31 | ||||
| -rw-r--r-- | src/serializers/to_object.ts | 8 |
4 files changed, 31 insertions, 26 deletions
diff --git a/src/serializers/to_json.test.ts b/src/serializers/to_json.test.ts index 22f7ba8..4184ab1 100644 --- a/src/serializers/to_json.test.ts +++ b/src/serializers/to_json.test.ts @@ -2,11 +2,11 @@ import FlatMatter from "../flatmatter.ts"; import ToJson from "./to_json.ts"; test("Single-level configuration", () => { - const fm = new FlatMatter( - 'a: true\nb: false\nc: 1\nd: 12.5\nf: "some string"' - ); + const fm = new FlatMatter( + 'a: true\nb: false\nc: 1\nd: 12.5\nf: "some string"' + ); - const equal = "{\"a\":true,\"b\":false,\"c\":1,\"d\":12.5,\"f\":\"some string\"}"; - - expect(fm.serialize(new ToJson())).toStrictEqual(equal); + const equal = '{"a":true,"b":false,"c":1,"d":12.5,"f":"some string"}'; + + expect(fm.serialize(new ToJson())).toStrictEqual(equal); }); diff --git a/src/serializers/to_json.ts b/src/serializers/to_json.ts index 76148db..30cf417 100644 --- a/src/serializers/to_json.ts +++ b/src/serializers/to_json.ts @@ -1,7 +1,7 @@ import type { Serializer } from "../flatmatter.ts"; -export default class ToJson implements Serializer { - serialize(parsedConfig: Record<string, unknown>): string { - return JSON.stringify(parsedConfig); +export default class ToJson implements Serializer<string> { + serialize(config: Record<string, unknown>): string { + return JSON.stringify(config); } } diff --git a/src/serializers/to_object.test.ts b/src/serializers/to_object.test.ts index 7059458..28cb78e 100644 --- a/src/serializers/to_object.test.ts +++ b/src/serializers/to_object.test.ts @@ -1,4 +1,4 @@ -import FlatMatter, {type FlatMatterFn} from "../flatmatter.ts"; +import FlatMatter, { type FlatMatterFn } from "../flatmatter.ts"; import ToObject from "./to_object.ts"; test("Single-level configuration", () => { @@ -48,7 +48,7 @@ test("Simple function usage", () => { } } - const fm = new FlatMatter('a: (to-upper "value")', [new ToUpper]); + const fm = new FlatMatter('a: (to-upper "value")', [new ToUpper()]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ @@ -65,7 +65,7 @@ test("Piped function by reference usage", () => { } } - const fm = new FlatMatter('a: "value" / to-upper', [new ToUpper]); + const fm = new FlatMatter('a: "value" / to-upper', [new ToUpper()]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ @@ -82,7 +82,7 @@ test("Piped function by call usage", () => { } } - const fm = new FlatMatter('a: "value" / (to-upper 123)', [new ToUpper]); + const fm = new FlatMatter('a: "value" / (to-upper 123)', [new ToUpper()]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ @@ -95,16 +95,16 @@ test("Invalid value in pipe", () => { const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({}); -}) +}); test("Invalid value in pipe, 2", () => { const fm = new FlatMatter('a: "value" / asd'); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ - a: "value" + a: "value", }); -}) +}); test("Only piped functions", () => { class FirstFn implements FlatMatterFn { @@ -123,11 +123,14 @@ test("Only piped functions", () => { } } - const fm = new FlatMatter('a: (first-fn "value / here") / second-fn', [new FirstFn, new SecondFn]); + const fm = new FlatMatter('a: (first-fn "value / here") / second-fn', [ + new FirstFn(), + new SecondFn(), + ]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ - a: "VALUE / HERE-passed-by-second" + a: "VALUE / HERE-passed-by-second", }); }); @@ -140,13 +143,13 @@ test("Function call without any args", () => { } } - const fm = new FlatMatter('a: "value" / (to-upper)', [new ToUpper]); + const fm = new FlatMatter('a: "value" / (to-upper)', [new ToUpper()]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ a: "VALUE", }); -}) +}); test("Function call using multiple strings with spaces as arg", () => { class ToUpper implements FlatMatterFn { @@ -157,10 +160,12 @@ test("Function call using multiple strings with spaces as arg", () => { } } - const fm = new FlatMatter('a: (to-upper "value goes here" "and here")', [new ToUpper]); + const fm = new FlatMatter('a: (to-upper "value goes here" "and here")', [ + new ToUpper(), + ]); const config = fm.serialize(new ToObject()); expect(config).toStrictEqual({ a: "VALUE GOES HERE", }); -})
\ No newline at end of file +}); diff --git a/src/serializers/to_object.ts b/src/serializers/to_object.ts index a7161cc..79b2886 100644 --- a/src/serializers/to_object.ts +++ b/src/serializers/to_object.ts @@ -1,7 +1,7 @@ -import type {Serializer} from "../flatmatter.ts"; +import type { Serializer } from "../flatmatter.ts"; -export default class ToObject implements Serializer { - serialize(parsedConfig: Record<string, unknown>): Record<string, unknown> { - return parsedConfig; +export default class ToObject implements Serializer<Record<string, unknown>> { + serialize(config: Record<string, unknown>): Record<string, unknown> { + return config; } } |
