# yaml-fs

> YAML File parser that preserves comments and styling

Latest version **1.0.4** (published 2018-09-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install yaml-fs
pnpm add yaml-fs
yarn add yaml-fs
bun add yaml-fs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-09-09 |
| First published | 2018-09-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | bluelovers |

## Links

- npm: https://www.npmjs.com/package/yaml-fs
- Repository: https://github.com/bluelovers/yaml-fs
- Homepage: https://github.com/bluelovers/yaml-fs#readme
- Issues: https://github.com/bluelovers/yaml-fs/issues
- npm.io page: https://npm.io/package/yaml-fs

## Dependencies (5)

- [yaml](https://npm.io/package/yaml.md) ^1.0.0-rc.8
- [bluebird](https://npm.io/package/bluebird.md) ^3.5.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^7.0.0
- [yawn-yaml](https://npm.io/package/yawn-yaml.md) ^1.3.4
- [crlf-normalize](https://npm.io/package/crlf-normalize.md) ^1.0.2

## Recent versions

- 1.0.4 (latest) — 2018-09-09
- 1.0.3 — 2018-09-09
- 1.0.2 — 2018-09-09
- 1.0.1 — 2018-09-08
- 1.0.0 — 2018-09-08

## README

# yaml-fs

    YAML File parser that preserves comments and styling

## install

```nodemon
npm install yaml-fs
```

## Demo

[API](index.d.ts)

```ts
import YAML from 'yaml';
import deepEql = require('deep-eql');
import { parseYAML, readYAML, outputYAML } from 'yaml-fs';

let str = `
# my comment
value: 1 # the value is here!
cache:
  directories:
    - ".cache"
    - dist_novel
    - dist_epub
  directories2:
  - ".cache"
  - dist_novel
  - dist_epub
`;

let y1 = YAML.parse(str);
let y2 = parseYAML(str);

console.log('deepEql:', deepEql(y1, y2.json));

console.dir(y2.json, {
	depth: null,
	colors: true,
});

console.log('deepEql2:', deepEql(str, y2.yaml));

console.log(y2.yaml);

// keep comments and styling
outputYAML('./temp/demo1.yml', y2);
// will not keep comments and styling
outputYAML('./temp/demo2.yml', y2.json);


/*
readYAML('.travis.yml')
	.then(function (ls)
	{
		console.log(ls);
	})
;
*/
```

## important

every time get `data.json` will re-parse `data.yaml`

so should set a var for `data.json`

```ts
let dd = data.json;
```

and if wanna update object

```ts
	dd.env = dd.env || {};
	dd.env.global = dd.env.global || [];
	dd.env.global.push(ret);

	// now `data.json` and `data.yaml` is updated
	// this will still preserves comments and styling
	data.json = dd;
```

or use

```ts
	let dd = data.json;

	dd.env = dd.env || {};
	dd.env.global = dd.env.global || [];
	dd.env.global.push(ret);

	return overwriteYAML(dd, data);
```

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