load-yaml-file
Advanced tools
Comparing version 0.2.0 to 1.0.0
20
index.js
@@ -1,11 +0,15 @@ | ||
'use strict' | ||
import fs from 'graceful-fs' | ||
import stripBom from 'strip-bom' | ||
import yaml from 'js-yaml' | ||
const fs = require('graceful-fs') | ||
const pify = require('pify') | ||
const stripBom = require('strip-bom') | ||
const yaml = require('js-yaml') | ||
function parse (data) { | ||
return yaml.load(stripBom(data)) | ||
} | ||
const parse = data => yaml.safeLoad(stripBom(data)) | ||
export async function loadYamlFile (path) { | ||
return parse(await fs.promises.readFile(path, 'utf8')) | ||
} | ||
module.exports = fp => pify(fs.readFile)(fp, 'utf8').then(data => parse(data)) | ||
module.exports.sync = fp => parse(fs.readFileSync(fp, 'utf8')) | ||
export function loadYamlFileSync (path) { | ||
return parse(fs.readFileSync(path, 'utf8')) | ||
} |
{ | ||
"name": "load-yaml-file", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"repository": "LinusU/load-yaml-file", | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"scripts": { | ||
"test": "standard && mocha" | ||
"test": "standard && mocha && ts-readme-generator --check" | ||
}, | ||
"dependencies": { | ||
"graceful-fs": "^4.1.5", | ||
"js-yaml": "^3.13.0", | ||
"pify": "^4.0.1", | ||
"strip-bom": "^3.0.0" | ||
"graceful-fs": "^4.2.8", | ||
"js-yaml": "^4.1.0", | ||
"strip-bom": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^6.0.2", | ||
"standard": "^12.0.1" | ||
"mocha": "^9.1.0", | ||
"standard": "^16.0.3", | ||
"ts-readme-generator": "^0.6.1" | ||
}, | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
} | ||
} |
@@ -14,19 +14,30 @@ # Load YAML file | ||
```js | ||
const loadYamlFile = require('load-yaml-file') | ||
import { loadYamlFile } from 'load-yaml-file' | ||
loadYamlFile('foo.yml').then(data => { | ||
console.log(data) | ||
//=> {foo: true} | ||
}) | ||
const data = await loadYamlFile('foo.yml') | ||
console.log(data) | ||
//=> {foo: true} | ||
``` | ||
### Sync | ||
```js | ||
import { loadYamlFileSync } from 'load-yaml-file' | ||
const data = loadYamlFileSync('foo.yml') | ||
console.log(data) | ||
//=> {foo: true} | ||
``` | ||
## API | ||
### loadYamlFile(filepath) | ||
### `loadYamlFile(path)` | ||
Returns a promise for the parsed YAML. | ||
- `path` (`string | Buffer | URL`, required) | ||
- returns `Promise<unknown>` - a promise for the parsed YAML | ||
### loadYamlFile.sync(filepath) | ||
### `loadYamlFileSync(path)` | ||
Returns the parsed YAML. | ||
- `path` (`string | Buffer | URL`, required) | ||
- returns `unknown` - the parsed YAML | ||
@@ -33,0 +44,0 @@ ## Related |
15
test.js
/* eslint-env mocha */ | ||
const assert = require('assert') | ||
const loadYamlFile = require('./') | ||
import assert from 'assert' | ||
import { loadYamlFile, loadYamlFileSync } from './index.js' | ||
describe('load-yaml-file', () => { | ||
it('loadYamlFile()', () => { | ||
return loadYamlFile('foo.yml').then(data => { | ||
assert.deepStrictEqual(data, { foo: true }) | ||
}) | ||
it('loadYamlFile', async () => { | ||
const data = await loadYamlFile('foo.yml') | ||
assert.deepStrictEqual(data, { foo: true }) | ||
}) | ||
it('loadYamlFile.sync()', () => { | ||
const data = loadYamlFile.sync('foo.yml') | ||
it('loadYamlFileSync', () => { | ||
const data = loadYamlFileSync('foo.yml') | ||
assert.deepStrictEqual(data, { foo: true }) | ||
}) | ||
}) |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
3974
3
8
29
1
47
Yes
3
+ Addedargparse@2.0.1(transitive)
+ Addedjs-yaml@4.1.0(transitive)
+ Addedstrip-bom@5.0.0(transitive)
- Removedpify@^4.0.1
- Removedargparse@1.0.10(transitive)
- Removedesprima@4.0.1(transitive)
- Removedjs-yaml@3.14.1(transitive)
- Removedpify@4.0.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedstrip-bom@3.0.0(transitive)
Updatedgraceful-fs@^4.2.8
Updatedjs-yaml@^4.1.0
Updatedstrip-bom@^5.0.0