New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

yaml-loader

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml-loader - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

59

index.js

@@ -1,28 +0,59 @@

var loaderUtils = require('loader-utils')
var YAML = require('yaml')
const { getOptions } = require('loader-utils')
const { stringify } = require('javascript-stringify')
const YAML = require('yaml')
const makeIdIterator = (prefix = 'v', i = 1) => ({ next: () => prefix + i++ })
module.exports = function yamlLoader(src) {
const { asStream, namespace, ...options } = Object.assign(
const { asJSON, asStream, namespace, ...options } = Object.assign(
{ prettyErrors: true },
loaderUtils.getOptions(this)
getOptions(this)
)
// keep track of repeated object references
const refs = new Map()
const idIter = makeIdIterator()
function addRef(ref, count) {
if (ref && typeof ref === 'object' && count > 1)
refs.set(ref, { id: idIter.next(), seen: false })
}
const stringifyWithRefs = (value) =>
stringify(value, (value, space, next) => {
const v = refs.get(value)
if (v) {
if (v.seen) return v.id
v.seen = true
}
return next(value)
})
const jsOpt = Object.assign({}, options, { onAnchor: addRef })
if (asJSON) {
jsOpt.json = true
jsOpt.mapAsMap = false
}
let res
if (asStream) {
const stream = YAML.parseAllDocuments(src, options)
const res = []
res = []
for (const doc of stream) {
for (const warn of doc.warnings) this.emitWarning(warn)
for (const err of doc.errors) throw err
res.push(doc.toJSON())
res.push(doc.toJS(jsOpt))
}
return JSON.stringify(res)
} else {
const doc = YAML.parseDocument(src, options)
for (const warn of doc.warnings) this.emitWarning(warn)
for (const err of doc.errors) throw err
if (namespace) doc.contents = doc.getIn(namespace.split('.'))
res = doc.toJS(jsOpt)
}
let res = YAML.parse(src, options)
if (namespace) {
res = namespace.split('.').reduce(function(acc, name) {
return acc[name]
}, res)
}
return JSON.stringify(res)
if (asJSON) return JSON.stringify(res)
let str = ''
for (const [obj, { id }] of refs.entries())
str += `var ${id} = ${stringifyWithRefs(obj)};\n`
str += `export default ${stringifyWithRefs(res)};`
return str
}
{
"name": "yaml-loader",
"version": "0.6.0",
"version": "0.7.0",
"license": "MIT",

@@ -29,20 +29,22 @@ "description": "YAML loader for Webpack",

"scripts": {
"prettier": "prettier --write '**/*.{js,md}'",
"test": "jest"
"prettier": "prettier --ignore-path .gitignore --write .",
"test": "jest --coverage"
},
"prettier": {
"semi": false,
"singleQuote": true
"singleQuote": true,
"trailingComma": "none"
},
"dependencies": {
"loader-utils": "^1.4.0",
"yaml": "^1.8.3"
"javascript-stringify": "^2.0.1",
"loader-utils": "^2.0.0",
"yaml": "^2.0.0"
},
"devDependencies": {
"jest": "^25.1.0",
"prettier": "^1.19.1"
"jest": "^27.5.1",
"prettier": "^2.1.1"
},
"engines": {
"node": ">= 6"
"node": ">= 10.14.2"
}
}

@@ -20,3 +20,2 @@ # yaml-loader for Webpack

test: /\.ya?ml$/,
type: 'json', // Required by Webpack v4
use: 'yaml-loader'

@@ -47,4 +46,9 @@ }

In addition to all [`yaml` options](https://eemeli.org/yaml/#options), the loader supports the following additional options:
In addition to all [`yaml` options](https://eemeli.org/yaml/#options) used by its parsing methods,
the loader supports the following additional options:
### `asJSON`
If enabled, the loader output is stringified JSON rather than stringified JavaScript. For Webpack v4, you'll need to set the rule to have `type: "json"`. Also useful for chaining with other loaders that expect JSON input.
### `asStream`

@@ -51,0 +55,0 @@

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