Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

load-yaml-file

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

load-yaml-file - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

.github/workflows/test.yml

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'))
}

24

package.json
{
"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

/* 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 })
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc