Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kristian/js-yaml-concat-seqs
js-yaml concatenate / merge sequences / arrays
https://github.com/kristian/js-yaml-concat-seqs
Last synced: 22 days ago
JSON representation
js-yaml concatenate / merge sequences / arrays
- Host: GitHub
- URL: https://github.com/kristian/js-yaml-concat-seqs
- Owner: kristian
- License: mit
- Created: 2024-04-05T08:47:01.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-04-05T19:43:56.000Z (10 months ago)
- Last Synced: 2024-12-12T12:18:12.605Z (about 2 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
js-yaml-concat-seqs
===================[![CI](https://github.com/kristian/js-yaml-concat-seqs/actions/workflows/ci.yml/badge.svg)](https://github.com/kristian/js-yaml-concat-seqs/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/js-yaml-concat-seqs.svg)](https://www.npmjs.org/package/js-yaml-concat-seqs)This `js-yaml` type is inspired by [Ingy döt Net](https://github.com/ingydotnet) comment in the original [`Yaml Issue #48`](https://github.com/yaml/yaml/issues/48#issuecomment-974998500) discussing merging sequences. He suggested that a tag is a valid option to denote merging of sequences, or how he called it `!concat-seqs`. I took the type system from the original `js-yaml` library and extended it with a one-line extension for the `concat-seqs` function as proposed.
This is a lightweight library (literally [5 lines of code](index.js)), without any external dependencies other than `js-yaml`. Requires Node 11 for [`Array.prototype.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) to be available.
> js-yaml extra type:
>
> - !!concat-seqs [*seq1, ..., *seq2]Installation
------------```sh
npm install js-yaml-concat-seqs
```Usage
-----```js
import yaml from "js-yaml";
import type from "js-yaml-concat-seqs";const schema = yaml.DEFAULT_SCHEMA.extend([ type ]);
const src = `
- &seq1
- qux
- qox
- &seq2
- qix
- qax
- !!concat-seqs
- *seq1
- - foo
- bar
- *seq2
`;console.log(yaml.load(src, { schema }));
```