diff options
| author | Asko Nõmm <asko@nmm.ee> | 2025-01-13 01:15:52 +0200 |
|---|---|---|
| committer | Asko Nõmm <asko@nmm.ee> | 2025-01-13 01:15:52 +0200 |
| commit | 64c537957b068f9dbee5223f9c35581bef079557 (patch) | |
| tree | 9c6e758cac905cd720849333a07e52f5f697c9ba /src/serializers | |
| parent | fb04f7fdf55a6f70a54f116ceecbdfbaa592375f (diff) | |
bump
Diffstat (limited to 'src/serializers')
| -rw-r--r-- | src/serializers/to_json.ts | 10 | ||||
| -rw-r--r-- | src/serializers/to_object.test.ts | 32 | ||||
| -rw-r--r-- | src/serializers/to_object.ts | 10 |
3 files changed, 34 insertions, 18 deletions
diff --git a/src/serializers/to_json.ts b/src/serializers/to_json.ts index 9f7b59b..f915a88 100644 --- a/src/serializers/to_json.ts +++ b/src/serializers/to_json.ts @@ -1,7 +1,7 @@ -import {Matter, Serializer} from '../flatmatter.ts'; +import type { Matter, Serializer } from "../flatmatter.ts"; export default class ToJson implements Serializer { - serialize(parsedConfig: Matter): string { - return JSON.stringify(parsedConfig); - } -}
\ No newline at end of file + serialize(parsedConfig: Matter): string { + return JSON.stringify(parsedConfig); + } +} diff --git a/src/serializers/to_object.test.ts b/src/serializers/to_object.test.ts index 98b165a..9f13987 100644 --- a/src/serializers/to_object.test.ts +++ b/src/serializers/to_object.test.ts @@ -1,13 +1,12 @@ -import { assertEquals } from "jsr:@std/assert"; -import FlatMatter from "../flatmatter.ts"; +import FlatMatter, {type FlatMatterFn} from "../flatmatter.ts"; import ToObject from "./to_object.ts"; -Deno.test("Single-level configuration", () => { +test("Single-level configuration", () => { const fm = new FlatMatter( - 'a: true\nb: false\nc: 1\nd: 12.5\nf: "some string"', + 'a: true\nb: false\nc: 1\nd: 12.5\nf: "some string"' ); - assertEquals(fm.serialize(new ToObject()), { + expect(fm.serialize(new ToObject())).toStrictEqual({ a: true, b: false, c: 1, @@ -16,12 +15,12 @@ Deno.test("Single-level configuration", () => { }); }); -Deno.test("Two-level configuration", () => { +test("Two-level configuration", () => { const fm = new FlatMatter( - 'a.a: true\nb.b: false\nc.c: 1\nd.d: 12.5\nf.f: "some string"', + 'a.a: true\nb.b: false\nc.c: 1\nd.d: 12.5\nf.f: "some string"' ); - assertEquals(fm.serialize(new ToObject()), { + expect(fm.serialize(new ToObject())).toStrictEqual({ a: { a: true, }, @@ -39,3 +38,20 @@ Deno.test("Two-level configuration", () => { }, }); }); + +test("Simple function usage", () => { + class ToUpper implements FlatMatterFn { + name = "to-upper"; + + compute(input: string): unknown { + return input.toUpperCase(); + } + } + + const fm = new FlatMatter('a: (to-upper "value")', [new ToUpper()]); + const config = fm.serialize(new ToObject()); + + expect(config).toStrictEqual({ + a: "VALUE", + }); +}); diff --git a/src/serializers/to_object.ts b/src/serializers/to_object.ts index eb21d2f..1b07144 100644 --- a/src/serializers/to_object.ts +++ b/src/serializers/to_object.ts @@ -1,7 +1,7 @@ -import {Matter, Serializer} from '../flatmatter.ts'; +import type { Matter, Serializer } from "../flatmatter.ts"; export default class ToObject implements Serializer { - serialize(parsedConfig: Matter): Matter { - return parsedConfig; - } -}
\ No newline at end of file + serialize(parsedConfig: Matter): Matter { + return parsedConfig; + } +} |
