@hidoo/data-from
v1.0.0
Published
Utility to get data from JSON, JSON5, and YAML.
Downloads
30
Readme
@hidoo/data-from
Utility to get data from JSON, JSON5, and YAML.
Installation
npm install @hidoo/data-from
Usage
Get data from a string:
import { fromString } from '@hidoo/data-from';
const data = fromString('{"test": {"hoge": "hoge", "fuga": "{{test.hoge}}');
// {test: {hoge: 'hoge', fuga: 'hoge'}}
Get data from Front Matter (wrapper of front-matter):
import { fromFrontMatter } from '@hidoo/data-from';
const data = fromFrontMatter(
`---
test:
hoge: hoge
fuga: "{{test.hoge}}"
---
`
);
// {body: '', attributes: {test: {hoge: 'hoge', fuga: 'hoge'}}, frontmatter: 'test:\n hoge: hoge\n fuga: "{{test.hoge}}"'}
Get data from files matched specified glob pattern:
// data.json5
{
data: {
hoge: 'hoge',
fuga: '{{validJSON5.hoge}}'
}
}
import { fromFiles, fromFilesSync } from '@hidoo/data-from';
const data = await fromFiles('/path/to/*.json5');
// {data: {hoge: 'hoge', fuga: 'hoge'}}
// By synchronously
const data = fromFilesSync('/path/to/*.json5');
Test
pnpm test
License
MIT