Socket
Socket
Sign inDemoInstall

tap-yaml

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tap-yaml - npm Package Compare versions

Comparing version 0.4.0 to 1.0.0

4

lib/parse.js

@@ -1,3 +0,3 @@

const tags = require('./types/index.js')
const customTags = require('./types/index.js')
const yaml = require('yaml')
module.exports = str => yaml.parse(str, { tags })
module.exports = str => yaml.parse(str, { customTags, prettyErrors: true })

@@ -1,3 +0,3 @@

const tags = require('./types/index.js')
const customTags = require('./types/index.js')
const yaml = require('yaml')
module.exports = obj => yaml.stringify(obj, { tags })
module.exports = obj => yaml.stringify(obj, { customTags, prettyErrors: true })

@@ -1,2 +0,2 @@

const {stringify} = require('yaml/schema')
const {stringifyString} = require('yaml/util')

@@ -15,4 +15,4 @@ module.exports = {

const value = item.value.toISOString()
return stringify({ value }, ctx, onComment, onChompKeep)
return stringifyString({ value }, ctx, onComment, onChompKeep)
}
}

@@ -1,10 +0,9 @@

const YAMLMap = require('yaml/dist/schema/Map').default
const parseMap = require('yaml/dist/schema/parseMap').default
const Pair = require('yaml/dist/schema/Pair').default
const { YAMLMap } = require('yaml/types')
const { parseMap } = require('yaml/util')
const tag = '!domain'
class YAMLDomain extends YAMLMap {
constructor () {
super()
this.tag = '!domain'
}
get tag () { return tag }
set tag (_) {}
toJSON(_, ctx) {

@@ -18,9 +17,4 @@ return require('domain').create()

const createNode = (schema, error, ctx) => {
return new YAMLDomain()
}
const createNode = (schema, error, ctx) => new YAMLDomain()
const stringify = (value, ctx, onComment, onChompKeep) =>
value.toString(ctx, onComment, onChompKeep)
module.exports = {

@@ -32,8 +26,5 @@ identify: value => value && typeof value === 'object' &&

: false,
tag: '!domain',
nodeClass: YAMLDomain,
default: false,
tag,
resolve,
createNode,
stringify,
}

@@ -1,26 +0,26 @@

const YAMLMap = require('yaml/dist/schema/Map').default
const parseMap = require('yaml/dist/schema/parseMap').default
const Pair = require('yaml/dist/schema/Pair').default
const { YAMLMap } = require('yaml/types')
const { parseMap } = require('yaml/util')
class YAMLError extends YAMLMap {
constructor () {
super()
this.tag = '!error'
}
const tag = '!error'
class JavaScriptError extends YAMLMap {
get tag () { return tag }
set tag (_) {}
toJSON(_, ctx) {
const obj = super.toJSON(_, {...ctx, mapAsMap: false})
const Cls = obj.name === 'EvalError' ? EvalError
: obj.name === 'RangeError' ? RangeError
: obj.name === 'ReferenceError' ? ReferenceError
: obj.name === 'SyntaxError' ? SyntaxError
: obj.name === 'TypeError' ? TypeError
: obj.name === 'URIError' ? URIError
: Error
const er = Object.assign(new Cls(obj.message), obj)
return er
const { name, message, ...rest } = super.toJSON(_, ctx, Object)
const Cls =
name === 'EvalError' ? EvalError
: name === 'RangeError' ? RangeError
: name === 'ReferenceError' ? ReferenceError
: name === 'SyntaxError' ? SyntaxError
: name === 'TypeError' ? TypeError
: name === 'URIError' ? URIError
: Error
if (Cls.name !== name)
rest.name = name
return Object.assign(new Cls(message), rest)
}
}
const resolve = (doc, cst) =>
Object.assign(new YAMLError(), parseMap(doc, cst))
const identify = er => er instanceof Error

@@ -32,3 +32,3 @@ // If the user cared to provide a custom inspect, then use

const createNode = (schema, error, ctx) => {
const ernode = new YAMLError()
const node = new JavaScriptError()
const ins = typeof error[inspect] === 'function' && error[inspect]()

@@ -39,3 +39,3 @@ for (const [key, value] of Object.entries({

stack: error.stack,
...(ins && typeof ins === 'object' ? ins : error)
...(ins && typeof ins === 'object' ? ins : error),
})) {

@@ -46,21 +46,11 @@ if (key === 'domain' ||

continue
const k = schema.createNode(key, ctx.wrapScalars, null, ctx)
const v = schema.createNode(value, ctx.wrapScalars, null, ctx)
ernode.items.push(new Pair(k, v))
const pair = schema.createPair(key, value, ctx)
node.items.push(pair)
}
return ernode
return node
}
const stringify = (value, ctx, onComment, onChompKeep) =>
value.toString(ctx, onComment, onChompKeep)
const resolve = (doc, cst) =>
Object.assign(new JavaScriptError(), parseMap(doc, cst))
module.exports = {
identify: value => value instanceof Error,
tag: '!error',
nodeClass: YAMLError,
default: false,
resolve,
createNode,
stringify,
}
module.exports = { tag, identify, createNode, resolve }

@@ -1,3 +0,2 @@

const { Type } = require('yaml/dist/cst/Node.js')
const {stringify} = require('yaml/schema')
const {stringifyString} = require('yaml/util')

@@ -16,3 +15,3 @@ module.exports = {

},
options: { defaultType: Type.BLOCK_LITERAL, lineWidth: 76 },
options: { defaultType: 'BLOCK_LITERAL', lineWidth: 76 },
stringify ({ comment, type, value }, ctx, onComment, onChompKeep) {

@@ -22,4 +21,5 @@ value = JSON.stringify(value.name) + '\n' + value.toString()

type = type || module.exports.options.defaultType
return stringify({ comment, type, value }, ctx, onComment, onChompKeep)
}
return stringifyString({ comment, type, value }, ctx, onComment, onChompKeep)
},
default: false,
}

@@ -0,1 +1,2 @@

const types = require('yaml/types')
module.exports = [

@@ -10,5 +11,5 @@ require('./error.js'),

require('./null-object.js'),
require('yaml/types/omap'),
require('yaml/types/set'),
require('yaml/types/binary').binary,
'omap',
'set',
'binary',
]

@@ -1,10 +0,9 @@

const YAMLMap = require('yaml/dist/schema/Map').default
const parseMap = require('yaml/dist/schema/parseMap').default
const Pair = require('yaml/dist/schema/Pair').default
const {YAMLMap} = require('yaml/types')
const {parseMap} = require('yaml/util')
const tag = '!nullobject'
class YAMLNullObject extends YAMLMap {
constructor () {
super()
this.tag = '!nullobject'
}
get tag () { return tag }
set tag (_) {}
toJSON(_, ctx) {

@@ -22,5 +21,3 @@ const obj = super.toJSON(_, {...ctx, mapAsMap: false})

for (const [key, value] of Object.entries(obj)) {
const k = schema.createNode(key, ctx.wrapScalars, null, ctx)
const v = schema.createNode(value, ctx.wrapScalars, null, ctx)
nullObjNode.items.push(new Pair(k, v))
nullObjNode.items.push(schema.createPair(key, value, ctx))
}

@@ -30,13 +27,4 @@ return nullObjNode

const stringify = (value, ctx, onComment, onChompKeep) =>
value.toString(ctx, onComment, onChompKeep)
const identify = v => typeof v === 'object' && v && !Object.getPrototypeOf(v)
module.exports = {
identify: v => typeof v === 'object' && v && !Object.getPrototypeOf(v),
tag: '!nullobject',
nodeClass: YAMLNullObject,
default: false,
resolve,
createNode,
stringify,
}
module.exports = { tag, identify, createNode, resolve }

@@ -1,2 +0,2 @@

const { stringify } = require('yaml/schema')
const {stringifyString} = require('yaml/util')

@@ -14,4 +14,4 @@ module.exports = {

const value = item.value.toString()
return stringify({ value }, ctx, onComment, onChompKeep)
return stringifyString({ value }, ctx, onComment, onChompKeep)
}
}

@@ -1,2 +0,2 @@

const { stringify } = require('yaml/schema')
const {stringifyString} = require('yaml/util')

@@ -16,4 +16,4 @@ module.exports = {

const src = `Symbol.for(${Symbol.keyFor(item.value)})`
return stringify({ value: src }, ctx, onComment, onChompKeep)
return stringifyString({ value: src }, ctx, onComment, onChompKeep)
}
}

@@ -1,2 +0,2 @@

const { stringify } = require('yaml/schema')
const {stringifyString} = require('yaml/util')

@@ -16,4 +16,4 @@ module.exports = {

const value = item.value.toString()
return stringify({ value }, ctx, onComment, onChompKeep)
return stringifyString({ value }, ctx, onComment, onChompKeep)
}
}
{
"name": "tap-yaml",
"version": "0.4.0",
"version": "1.0.0",
"description": "Yaml handling for TAP parsers and generators",

@@ -26,6 +26,6 @@ "main": "index.js",

"dependencies": {
"yaml": "github:isaacs/yaml#built"
"yaml": "^1.5.0"
},
"devDependencies": {
"tap": "^13.0.0-rc.11"
"tap": "^13.0.0-rc.21"
},

@@ -32,0 +32,0 @@ "files": [

@@ -15,19 +15,27 @@ # tap-yaml

This is essentially a re-export of the [yaml](http://npm.im/yaml)
package, with a few modifications to be more suitable for use in
[tap](https://www.node-tap.org).
package, with a few custom types and default properties to be more suitable for
use in [tap](https://www.node-tap.org).
1. Symbol and Function types are added, so that they don't throw.
Functions aren't parsed to actual functions, though, since that's
horribly unsafe, but they do parse to an empty function with a
`toString()` that contains the original string source.
2. An `Error` type is added.
3. Binary types are implicitly allowed in a standard way.
4. `omap` and `set` are configured to refer to Map and Set objects.
## Status
This is not yet ready for prime time. Work is underway to port
node-tap projects to use it, which will take a bit of time, and
probably flush out a lot of bugs and issues along the way.
If you'd like to help, get in touch!
1. Symbol types are added, so that they don't throw. Shared symbols will
(within the same process) retain the same Symbol identity through encoding
and decoding. Unshared symbols will not retain their object identity.
2. A "safe" `!function` type is added. Functions aren't parsed to actual
functions using `eval()`, since that's obviously a Bad Idea, but they do
parse to an empty function with a `toString()` that contains the original
string source.
3. An `Error` type is added, which does its best to maintain its properties,
and always shows message, stack, and name, even if these are non-enumerable.
If an Error has a custom inspect method that returns an object, then that is
used as the source of extra properties, so you may filter out what gets
dumped to your TAP stream.
4. Binary types are implicitly allowed in a standard way. In Node.js, this
means that a Buffer object is created, and Buffers can be dumped to YAML
without any weirdness.
5. `omap` and `set` are configured to refer to Map and Set objects.
6. Objects with a `null` prototype maintain their null-prototyped-ness.
7. `Domain` objects are stringified, but without their giant object graph,
since that's often a performance issue.
8. `Date` objects are given a non-default `!date` tag rather than the default
YAML 1.1 `!timestamp`, so that they maintain their explicit date object
nature through stringifying and re-parsing.
9. The `prettyErrors` option is always enabled.
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