@hidoo/data-from

1.0.0 • Public • Published

@hidoo/data-from

Test

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

Readme

Keywords

Package Sidebar

Install

npm i @hidoo/data-from

Weekly Downloads

14

Version

1.0.0

License

MIT

Unpacked Size

11.3 kB

Total Files

10

Last publish

Collaborators

  • hidoo