# @hidoo/data-from

> Utility to get data from JSON, JSON5, and YAML.

Latest version **1.0.0** (published 2024-03-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install @hidoo/data-from
pnpm add @hidoo/data-from
yarn add @hidoo/data-from
bun add @hidoo/data-from
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-03-21 |
| First published | 2018-08-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=18.0.0 |
| Dependencies | 6 |
| Unpacked size | 11 KB |
| Known vulnerabilities | 0 (+18 in 3 direct dependencies) |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | hidoo |
| Maintainers | hidoo |
| Keywords | data, yaml, json5 |

## Links

- npm: https://www.npmjs.com/package/@hidoo/data-from
- Repository: https://github.com/hidoo/data-from
- Homepage: https://github.com/hidoo/data-from#readme
- Issues: https://github.com/hidoo/data-from/issues
- npm.io page: https://npm.io/package/@hidoo/data-from

## Dependencies (6)

- [glob](https://npm.io/package/glob.md) 10.3.10
- [json5](https://npm.io/package/json5.md) 2.2.3
- [js-yaml](https://npm.io/package/js-yaml.md) 4.1.0
- [handlebars](https://npm.io/package/handlebars.md) 4.7.8
- [front-matter](https://npm.io/package/front-matter.md) 4.0.2
- [lodash.merge](https://npm.io/package/lodash.merge.md) 4.6.2

## Alternatives

- [monaco-yaml](https://npm.io/package/monaco-yaml.md) — 420.1K weekly downloads
- [@crewx/workflow](https://npm.io/package/@crewx/workflow.md) — 3.1K weekly downloads
- [yaml-cat](https://npm.io/package/yaml-cat.md) — 38 weekly downloads
- [nunjucks-in-yaml](https://npm.io/package/nunjucks-in-yaml.md) — 9 weekly downloads
- [shopify-symlinks](https://npm.io/package/shopify-symlinks.md) — 3 weekly downloads

## Recent versions

- 1.0.0 (latest) — 2024-03-21
- 0.3.1 — 2021-03-29
- 0.3.0 — 2020-05-07
- 0.2.0 — 2020-03-03
- 0.1.3 — 2019-11-12
- 0.1.2 — 2019-06-10
- 0.1.1 — 2018-08-28
- 0.1.0 — 2018-08-28

## README

# @hidoo/data-from

[![Test](https://github.com/hidoo/data-from/actions/workflows/test.yml/badge.svg)](https://github.com/hidoo/data-from/actions/workflows/test.yml)

> Utility to get data from JSON, JSON5, and YAML.

## Installation

```sh
npm install @hidoo/data-from
```

## Usage

Get data from a string:

```js
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](https://www.npmjs.com/package/front-matter)):

```js
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:

```json5
// data.json5
{
  data: {
    hoge: 'hoge',
    fuga: '{{validJSON5.hoge}}'
  }
}
```

```js
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

```sh
pnpm test
```

## License

MIT

---
_Source: https://npm.io/package/@hidoo/data-from · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
