From 64c537957b068f9dbee5223f9c35581bef079557 Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Mon, 13 Jan 2025 01:15:52 +0200 Subject: bump --- README.md | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 69bac52..e85ec81 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,48 @@ of the next function, and so on, to produce an end result. ## Install -To be written ... +```shell +npm i flatmatter +``` ## Usage -To be written ... +The most basic usage looks like this: + +```typescript +import FlatMatter, {ToObject} from "flatmatter"; + +const fm = new FlatMatter('key: "value"'); +const config = fm.serialize(new ToObject()); + +// {key: "value"} +``` + +However, you most likely want to use it with functions. Those you have to create yourself. An example function looks +like this: + +```typescript +import {FlatMatterFn} from "flatmatter"; + +class ToUpper implements FlatMatterFn { + name = "to-upper"; + + compute(input: string): unknown { + return input.toUpperCase(); + } +} +``` + +A FlatMatter function has to implement the `FlatMatterFn` interface. And like I mentioned before, a thing to keep in +mind is that if the function is piped, the first argument passed to it will be the result of the previous operation. + +Once you have your functions, simply pass them to FlatMatter like this: + +```typescript +import FlatMatter, {ToObject} from "flatmatter"; + +const fm = new FlatMatter('key: "value" / to-upper', [new MyFunction()]); +const config = fm.serialize(new ToObject()); + +// {key: "VALUE"} +``` -- cgit v1.2.3