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 /README.md | |
| parent | fb04f7fdf55a6f70a54f116ceecbdfbaa592375f (diff) | |
bump
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -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"} +``` |
