-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e3bc87
commit b8db91d
Showing
10 changed files
with
3,440 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# EditorConfig helps developers define and maintain consistent | ||
# coding styles between different editors and IDEs | ||
# editorconfig.org | ||
|
||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules/ | ||
._* | ||
.env | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
coverage/** | ||
node_modules/** | ||
dist/** | ||
build/** | ||
.nyc_output/** | ||
LICENSE | ||
*.html | ||
*.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"overrides": [ | ||
{ | ||
"files": ["**/*.js"], | ||
"options": { | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"bracketSpacing": true | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 geneasy | ||
Copyright (c) 2021 Pipecraft <[email protected]> (https://www.pipecraft.net) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,37 @@ | ||
# geneasy-yaml | ||
|
||
[![NPM Version][npm-version-image]][npm-url] | ||
[![LICENSE][license-image]][license-url] | ||
[![code style: prettier][code-style-prettier-image]][code-style-prettier-url] | ||
|
||
A plugin that enables geneasy to use dafa files in YAML format. | ||
|
||
## Installation | ||
|
||
```sh | ||
npm i -g geneasy-yaml | ||
``` | ||
|
||
## Related | ||
|
||
- [geneasy](https://github.com/geneasy/geneasy) - A command line tool that can easily generate HTML, Markdown documents, etc. | ||
- [geneasy-handlebars](https://github.com/geneasy/geneasy-handlebars) - A plugin that enables geneasy to use the Handlebars templates. | ||
- [js-yaml](https://github.com/nodeca/js-yaml) - JavaScript YAML parser and dumper. Very fast. | ||
|
||
## License | ||
|
||
Copyright (c) 2021 [Pipecraft][my-url]. Licensed under the [MIT license][license-url]. | ||
|
||
## >\_ | ||
|
||
[![Pipecraft](https://img.shields.io/badge/site-pipecraft-brightgreen)](https://www.pipecraft.net) | ||
[![PZWD](https://img.shields.io/badge/site-pzwd-brightgreen)](https://pzwd.net) | ||
|
||
[my-url]: https://www.pipecraft.net | ||
[npm-url]: https://www.npmjs.com/package/geneasy-yaml | ||
[license-url]: LICENSE | ||
[code-style-prettier-url]: https://github.com/prettier/prettier | ||
[npm-downloads-image]: https://img.shields.io/npm/dm/geneasy-yaml | ||
[npm-version-image]: https://img.shields.io/npm/v/geneasy-yaml | ||
[license-image]: https://img.shields.io/npm/l/geneasy-yaml | ||
[code-style-prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import yaml from 'js-yaml'; | ||
|
||
export default function parse(data) { | ||
if (!data) { | ||
return {}; | ||
} | ||
|
||
const result = yaml.load(data); | ||
if (typeof result !== 'object') { | ||
throw new TypeError('Invalid data format, requires YAML format.'); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
export function register(geneasy) { | ||
geneasy.register({ | ||
parsingEngine: { type: 'yaml', engine: parse } | ||
}); | ||
geneasy.register({ | ||
parsingEngine: { type: 'yml', engine: parse } | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "geneasy-yaml", | ||
"version": "0.0.1", | ||
"description": "A plugin that enables geneasy to use dafa files in YAML format.", | ||
"type": "module", | ||
"exports": "./lib/index.js", | ||
"scripts": { | ||
"lint": "prettier --write . && xo", | ||
"lint:fix": "prettier --write . && xo --fix", | ||
"test": "mocha test/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/geneasy/geneasy-handlebars.git" | ||
}, | ||
"keywords": [ | ||
"geneasy", | ||
"yaml", | ||
"json" | ||
], | ||
"author": "Pipecraft <[email protected]> (https://www.pipecraft.net)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/geneasy/geneasy-yaml/issues" | ||
}, | ||
"homepage": "https://github.com/geneasy/geneasy-yaml#readme", | ||
"dependencies": { | ||
"js-yaml": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^4.3.4", | ||
"mocha": "^9.1.1", | ||
"prettier": "^2.4.1", | ||
"xo": "^0.44.0" | ||
}, | ||
"files": [ | ||
"lib/", | ||
"LICENSE", | ||
"README.md" | ||
], | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"xo": { | ||
"space": 2, | ||
"prettier": true, | ||
"rules": {}, | ||
"overrides": [ | ||
{ | ||
"files": "test/*.js", | ||
"envs": [ | ||
"node", | ||
"mocha" | ||
] | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect } from 'chai'; | ||
import parse, { register } from '../lib/index.js'; | ||
|
||
describe('geneasy-yaml', () => { | ||
it('`parse` should to be a function', () => { | ||
expect(parse).to.be.a('function'); | ||
}); | ||
|
||
it('should `parse` return empty object when data not provided', () => { | ||
const result = parse(); | ||
// eslint-disable-next-line no-unused-expressions | ||
expect(result).to.be.an('object').that.is.empty; | ||
}); | ||
|
||
it('should `parse` return parsed object when a yaml data provided', () => { | ||
const result = parse(` | ||
--- | ||
YAML: YAML Ain't Markup Language™ | ||
What It Is: | ||
YAML is a human friendly data serialization | ||
language for all programming languages. | ||
`); | ||
expect(result).to.be.an('object'); | ||
expect(result).have.own.property('YAML'); | ||
expect(result).have.own.property('What It Is'); | ||
}); | ||
|
||
it('should `parse` return parsed object when a json data provided', () => { | ||
const result = parse(`{"foo": "bar"}`); | ||
expect(result).to.be.an('object'); | ||
expect(result).have.own.property('foo'); | ||
}); | ||
|
||
it('should `parse` throw an error when data with invalid format', () => { | ||
try { | ||
parse('123'); | ||
expect.fail('was not supposed to succeed'); | ||
} catch (error) { | ||
expect(error).to.be.an('error'); | ||
} | ||
}); | ||
|
||
it('`register` should to be a function', () => { | ||
expect(register).to.be.a('function'); | ||
}); | ||
}); |
Oops, something went wrong.