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

yaml

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml - npm Package Compare versions

Comparing version 2.0.0-7 to 2.0.0-8

3

browser/dist/compose/compose-scalar.js

@@ -22,3 +22,4 @@ import { isScalar, SCALAR } from '../nodes/Node.js';

catch (error) {
onError(tagToken || token, 'TAG_RESOLVE_FAILED', error.message);
const msg = error instanceof Error ? error.message : String(error);
onError(tagToken || token, 'TAG_RESOLVE_FAILED', msg);
scalar = new Scalar(value);

@@ -25,0 +26,0 @@ }

@@ -138,2 +138,8 @@ import { Scalar } from '../nodes/Scalar.js';

}
else if (next === '\r' && source[i + 1] === '\n') {
// skip escaped CRLF newlines, but still trim the following line
next = source[++i + 1];
while (next === ' ' || next === '\t')
next = source[++i + 1];
}
else if (next === 'x' || next === 'u' || next === 'U') {

@@ -156,3 +162,3 @@ const length = { x: 2, u: 4, U: 8 }[next];

next = source[++i + 1];
if (next !== '\n')
if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
res += i > wsStart ? source.slice(wsStart, i + 1) : ch;

@@ -159,0 +165,0 @@ }

import { Alias } from '../nodes/Alias.js';
import { isNode, isPair, MAP, SEQ } from '../nodes/Node.js';
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js';
import { Scalar } from '../nodes/Scalar.js';

@@ -18,2 +18,4 @@

var _a, _b;
if (isDocument(value))
value = value.contents;
if (isNode(value))

@@ -34,7 +36,7 @@ return value;

}
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
// Detect duplicate references to the same object & use Alias nodes for all
// after first. The `ref` wrapper allows for circular references to resolve.
let ref = undefined;
if (value && typeof value === 'object') {
if (aliasDuplicateObjects && value && typeof value === 'object') {
ref = sourceObjects.get(value);

@@ -41,0 +43,0 @@ if (ref) {

@@ -23,2 +23,7 @@ import { isNode } from '../nodes/Node.js';

}
clone() {
const copy = new Directives(this.yaml, this.tags);
copy.marker = this.marker;
return copy;
}
/**

@@ -25,0 +30,0 @@ * During parsing, get a Directives instance for the current document and

import { Alias } from '../nodes/Alias.js';
import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js';
import { NODE_TYPE, DOC, isCollection, isScalar } from '../nodes/Node.js';
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/Node.js';
import { Pair } from '../nodes/Pair.js';

@@ -51,2 +51,25 @@ import { toJS } from '../nodes/toJS.js';

}
/**
* Create a deep copy of this Document and its contents.
*
* Custom Node values that inherit from `Object` still refer to their original instances.
*/
clone() {
const copy = Object.create(Document.prototype, {
[NODE_TYPE]: { value: DOC }
});
copy.commentBefore = this.commentBefore;
copy.comment = this.comment;
copy.errors = this.errors.slice();
copy.warnings = this.warnings.slice();
copy.options = Object.assign({}, this.options);
copy.directives = this.directives.clone();
copy.schema = this.schema.clone();
copy.contents = isNode(this.contents)
? this.contents.clone(copy.schema)
: this.contents;
if (this.range)
copy.range = this.range.slice();
return copy;
}
/** Adds a value to the document. */

@@ -96,5 +119,6 @@ add(value) {

}
const { anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(this, anchorPrefix || 'a');
const ctx = {
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,

@@ -101,0 +125,0 @@ onAnchor,

import { warn } from '../log.js';
import { createStringifyContext } from '../stringify/stringify.js';
import { isScalar, isSeq, isAlias, isMap, isNode } from './Node.js';
import { isSeq, isScalar, isAlias, isMap, isNode } from './Node.js';
import { Scalar } from './Scalar.js';

@@ -5,0 +5,0 @@ import { toJS } from './toJS.js';

import { createNode } from '../doc/createNode.js';
import { NodeBase, isCollection, isScalar, isPair } from './Node.js';
import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js';

@@ -14,15 +14,10 @@ function collectionFromPath(schema, path, value) {

else {
const o = {};
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
value: v,
writable: true,
enumerable: true,
configurable: true
});
v = o;
v = new Map([[k, v]]);
}
}
return createNode(v, undefined, {
onAnchor() {
throw new Error('Repeated objects are not supported here');
aliasDuplicateObjects: false,
keepUndefined: false,
onAnchor: () => {
throw new Error('This should not happen, please report a bug.');
},

@@ -47,2 +42,16 @@ schema,

/**
* Create a copy of this collection.
*
* @param schema - If defined, overwrites the original's schema
*/
clone(schema) {
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
if (schema)
copy.schema = schema;
copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);
if (this.range)
copy.range = this.range.slice();
return copy;
}
/**
* Adds a value to the collection. For `!!map` and `!!omap` the value must

@@ -49,0 +58,0 @@ * be a Pair instance or a `{ key, value }` object, which may not have a key

@@ -39,4 +39,11 @@ const ALIAS = Symbol.for('yaml.alias');

}
/** Create a copy of this node. */
clone() {
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
if (this.range)
copy.range = this.range.slice();
return copy;
}
}
export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
import { createNode } from '../doc/createNode.js';
import { stringifyPair } from '../stringify/stringifyPair.js';
import { addPairToJSMap } from './addPairToJSMap.js';
import { NODE_TYPE, PAIR } from './Node.js';
import { NODE_TYPE, PAIR, isNode } from './Node.js';

@@ -17,2 +17,10 @@ function createPair(key, value, ctx) {

}
clone(schema) {
let { key, value } = this;
if (isNode(key))
key = key.clone(schema);
if (isNode(value))
value = value.clone(schema);
return new Pair(key, value);
}
toJSON(_, ctx) {

@@ -19,0 +27,0 @@ const pair = ctx && ctx.mapAsMap ? new Map() : {};

@@ -137,2 +137,4 @@ import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';

this.indentValue = 0;
/** Position of the next \n character. */
this.lineEndPos = null;
/** Stores the state of the lexer if reaching the end of incpomplete input */

@@ -150,4 +152,6 @@ this.next = null;

*lex(source, incomplete = false) {
if (source)
if (source) {
this.buffer = this.buffer ? this.buffer + source : source;
this.lineEndPos = null;
}
this.atEnd = !incomplete;

@@ -195,3 +199,7 @@ let next = this.next || 'stream';

getLine() {
let end = this.buffer.indexOf('\n', this.pos);
let end = this.lineEndPos;
if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
end = this.buffer.indexOf('\n', this.pos);
this.lineEndPos = end;
}
if (end === -1)

@@ -209,2 +217,3 @@ return this.atEnd ? this.buffer.substring(this.pos) : null;

this.pos = 0;
this.lineEndPos = null;
this.next = state;

@@ -440,13 +449,15 @@ return null;

}
let nl = this.buffer.indexOf('\n', this.pos);
if (nl !== -1 && nl < end) {
while (nl !== -1 && nl < end) {
// Only looking for newlines within the quotes
const qb = this.buffer.substring(0, end);
let nl = qb.indexOf('\n', this.pos);
if (nl !== -1) {
while (nl !== -1) {
const cs = this.continueScalar(nl + 1);
if (cs === -1)
break;
nl = this.buffer.indexOf('\n', cs);
nl = qb.indexOf('\n', cs);
}
if (nl !== -1 && nl < end) {
if (nl !== -1) {
// this is an error caused by an unexpected unindent
end = nl - 1;
end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
}

@@ -551,5 +562,3 @@ }

else if (isEmpty(ch)) {
const next = this.buffer[i + 1];
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
break;
let next = this.buffer[i + 1];
if (ch === '\r') {

@@ -559,2 +568,3 @@ if (next === '\n') {

ch = '\n';
next = this.buffer[i + 1];
}

@@ -564,2 +574,4 @@ else

}
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
break;
if (ch === '\n') {

@@ -566,0 +578,0 @@ const cs = this.continueScalar(i + 1);

@@ -21,4 +21,9 @@ import { MAP, SCALAR, SEQ } from '../nodes/Node.js';

}
clone() {
const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
copy.tags = this.tags.slice();
return copy;
}
}
export { Schema };

@@ -24,3 +24,4 @@ 'use strict';

catch (error) {
onError(tagToken || token, 'TAG_RESOLVE_FAILED', error.message);
const msg = error instanceof Error ? error.message : String(error);
onError(tagToken || token, 'TAG_RESOLVE_FAILED', msg);
scalar = new Scalar.Scalar(value);

@@ -27,0 +28,0 @@ }

@@ -140,2 +140,8 @@ 'use strict';

}
else if (next === '\r' && source[i + 1] === '\n') {
// skip escaped CRLF newlines, but still trim the following line
next = source[++i + 1];
while (next === ' ' || next === '\t')
next = source[++i + 1];
}
else if (next === 'x' || next === 'u' || next === 'U') {

@@ -158,3 +164,3 @@ const length = { x: 2, u: 4, U: 8 }[next];

next = source[++i + 1];
if (next !== '\n')
if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
res += i > wsStart ? source.slice(wsStart, i + 1) : ch;

@@ -161,0 +167,0 @@ }

@@ -6,3 +6,4 @@ import { Node } from '../nodes/Node.js';

export interface CreateNodeContext {
keepUndefined?: boolean;
aliasDuplicateObjects: boolean;
keepUndefined: boolean;
onAnchor(source: unknown): string;

@@ -9,0 +10,0 @@ onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;

@@ -20,2 +20,4 @@ 'use strict';

var _a, _b;
if (Node.isDocument(value))
value = value.contents;
if (Node.isNode(value))

@@ -36,7 +38,7 @@ return value;

}
const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
// Detect duplicate references to the same object & use Alias nodes for all
// after first. The `ref` wrapper allows for circular references to resolve.
let ref = undefined;
if (value && typeof value === 'object') {
if (aliasDuplicateObjects && value && typeof value === 'object') {
ref = sourceObjects.get(value);

@@ -43,0 +45,0 @@ if (ref) {

@@ -23,2 +23,3 @@ import type { Document } from './Document.js';

constructor(yaml?: Directives['yaml'], tags?: Directives['tags']);
clone(): Directives;
/**

@@ -25,0 +26,0 @@ * During parsing, get a Directives instance for the current document and

@@ -25,2 +25,7 @@ 'use strict';

}
clone() {
const copy = new Directives(this.yaml, this.tags);
copy.marker = this.marker;
return copy;
}
/**

@@ -27,0 +32,0 @@ * During parsing, get a Directives instance for the current document and

@@ -46,2 +46,8 @@ import type { YAMLError, YAMLWarning } from '../errors.js';

constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
/**
* Create a deep copy of this Document and its contents.
*
* Custom Node values that inherit from `Object` still refer to their original instances.
*/
clone(): Document<T>;
/** Adds a value to the document. */

@@ -48,0 +54,0 @@ add(value: any): void;

@@ -53,2 +53,25 @@ 'use strict';

}
/**
* Create a deep copy of this Document and its contents.
*
* Custom Node values that inherit from `Object` still refer to their original instances.
*/
clone() {
const copy = Object.create(Document.prototype, {
[Node.NODE_TYPE]: { value: Node.DOC }
});
copy.commentBefore = this.commentBefore;
copy.comment = this.comment;
copy.errors = this.errors.slice();
copy.warnings = this.warnings.slice();
copy.options = Object.assign({}, this.options);
copy.directives = this.directives.clone();
copy.schema = this.schema.clone();
copy.contents = Node.isNode(this.contents)
? this.contents.clone(copy.schema)
: this.contents;
if (this.range)
copy.range = this.range.slice();
return copy;
}
/** Adds a value to the document. */

@@ -98,5 +121,6 @@ add(value) {

}
const { anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this, anchorPrefix || 'a');
const ctx = {
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,

@@ -103,0 +127,0 @@ onAnchor,

@@ -18,2 +18,8 @@ import type { Schema } from '../schema/Schema.js';

constructor(type: symbol, schema?: Schema);
/**
* Create a copy of this collection.
*
* @param schema - If defined, overwrites the original's schema
*/
clone(schema?: Schema): Collection;
/** Adds a value to the collection. */

@@ -20,0 +26,0 @@ abstract add(value: unknown): void;

@@ -16,15 +16,10 @@ 'use strict';

else {
const o = {};
Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
value: v,
writable: true,
enumerable: true,
configurable: true
});
v = o;
v = new Map([[k, v]]);
}
}
return createNode.createNode(v, undefined, {
onAnchor() {
throw new Error('Repeated objects are not supported here');
aliasDuplicateObjects: false,
keepUndefined: false,
onAnchor: () => {
throw new Error('This should not happen, please report a bug.');
},

@@ -49,2 +44,16 @@ schema,

/**
* Create a copy of this collection.
*
* @param schema - If defined, overwrites the original's schema
*/
clone(schema) {
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
if (schema)
copy.schema = schema;
copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it);
if (this.range)
copy.range = this.range.slice();
return copy;
}
/**
* Adds a value to the collection. For `!!map` and `!!omap` the value must

@@ -51,0 +60,0 @@ * be a Pair instance or a `{ key, value }` object, which may not have a key

@@ -26,3 +26,3 @@ import type { Document } from '../doc/Document.js';

export declare function isNode(node: any): node is Node;
export declare const hasAnchor: (node: unknown) => node is YAMLMap<unknown, unknown> | YAMLSeq<unknown> | Scalar<unknown>;
export declare const hasAnchor: (node: unknown) => node is Scalar<unknown> | YAMLMap<unknown, unknown> | YAMLSeq<unknown>;
export declare abstract class NodeBase {

@@ -49,2 +49,4 @@ readonly [NODE_TYPE]: symbol;

constructor(type: symbol);
/** Create a copy of this node. */
clone(): NodeBase;
}

@@ -41,2 +41,9 @@ 'use strict';

}
/** Create a copy of this node. */
clone() {
const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
if (this.range)
copy.range = this.range.slice();
return copy;
}
}

@@ -43,0 +50,0 @@

import { CreateNodeContext } from '../doc/createNode.js';
import { StringifyContext } from '../stringify/stringify.js';
import type { Schema } from '../schema/Schema.js';
import type { StringifyContext } from '../stringify/stringify.js';
import { addPairToJSMap } from './addPairToJSMap.js';
import { NODE_TYPE } from './Node.js';
import { ToJSContext } from './toJS.js';
import type { ToJSContext } from './toJS.js';
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;

@@ -14,4 +15,5 @@ export declare class Pair<K = unknown, V = unknown> {

constructor(key: K, value?: V | null);
clone(schema?: Schema): Pair<K, V>;
toJSON(_?: unknown, ctx?: ToJSContext): ReturnType<typeof addPairToJSMap>;
toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
}

@@ -19,2 +19,10 @@ 'use strict';

}
clone(schema) {
let { key, value } = this;
if (Node.isNode(key))
key = key.clone(schema);
if (Node.isNode(value))
value = value.clone(schema);
return new Pair(key, value);
}
toJSON(_, ctx) {

@@ -21,0 +29,0 @@ const pair = ctx && ctx.mapAsMap ? new Map() : {};

@@ -109,2 +109,9 @@ import type { Reviver } from './doc/applyReviver.js';

/**
* During node construction, use anchors and aliases to keep strictly equal
* non-null objects as equivalent in YAML.
*
* Default: `true`
*/
aliasDuplicateObjects?: boolean;
/**
* Default prefix for anchors.

@@ -111,0 +118,0 @@ *

@@ -50,2 +50,4 @@ /**

private indentValue;
/** Position of the next \n character. */
private lineEndPos;
/** Stores the state of the lexer if reaching the end of incpomplete input */

@@ -52,0 +54,0 @@ private next;

@@ -139,2 +139,4 @@ 'use strict';

this.indentValue = 0;
/** Position of the next \n character. */
this.lineEndPos = null;
/** Stores the state of the lexer if reaching the end of incpomplete input */

@@ -152,4 +154,6 @@ this.next = null;

*lex(source, incomplete = false) {
if (source)
if (source) {
this.buffer = this.buffer ? this.buffer + source : source;
this.lineEndPos = null;
}
this.atEnd = !incomplete;

@@ -197,3 +201,7 @@ let next = this.next || 'stream';

getLine() {
let end = this.buffer.indexOf('\n', this.pos);
let end = this.lineEndPos;
if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
end = this.buffer.indexOf('\n', this.pos);
this.lineEndPos = end;
}
if (end === -1)

@@ -211,2 +219,3 @@ return this.atEnd ? this.buffer.substring(this.pos) : null;

this.pos = 0;
this.lineEndPos = null;
this.next = state;

@@ -442,13 +451,15 @@ return null;

}
let nl = this.buffer.indexOf('\n', this.pos);
if (nl !== -1 && nl < end) {
while (nl !== -1 && nl < end) {
// Only looking for newlines within the quotes
const qb = this.buffer.substring(0, end);
let nl = qb.indexOf('\n', this.pos);
if (nl !== -1) {
while (nl !== -1) {
const cs = this.continueScalar(nl + 1);
if (cs === -1)
break;
nl = this.buffer.indexOf('\n', cs);
nl = qb.indexOf('\n', cs);
}
if (nl !== -1 && nl < end) {
if (nl !== -1) {
// this is an error caused by an unexpected unindent
end = nl - 1;
end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
}

@@ -553,5 +564,3 @@ }

else if (isEmpty(ch)) {
const next = this.buffer[i + 1];
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
break;
let next = this.buffer[i + 1];
if (ch === '\r') {

@@ -561,2 +570,3 @@ if (next === '\n') {

ch = '\n';
next = this.buffer[i + 1];
}

@@ -566,2 +576,4 @@ else

}
if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
break;
if (ch === '\n') {

@@ -568,0 +580,0 @@ const cs = this.continueScalar(i + 1);

@@ -16,2 +16,3 @@ import { MAP, SCALAR, SEQ } from '../nodes/Node.js';

constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }: SchemaOptions);
clone(): Schema;
}

@@ -23,4 +23,9 @@ 'use strict';

}
clone() {
const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
copy.tags = this.tags.slice();
return copy;
}
}
exports.Schema = Schema;
{
"name": "yaml",
"version": "2.0.0-7",
"version": "2.0.0-8",
"license": "ISC",

@@ -73,3 +73,3 @@ "author": "Eemeli Aro <eemeli@gmail.com>",

"@rollup/plugin-typescript": "^8.1.1",
"@types/jest": "^26.0.20",
"@types/jest": "^27.0.1",
"@types/node": "^15.6.1",

@@ -88,3 +88,3 @@ "@typescript-eslint/eslint-plugin": "^4.15.2",

"tslib": "^2.1.0",
"typescript": "^4.1.3"
"typescript": "^4.3.5"
},

@@ -91,0 +91,0 @@ "engines": {

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