Socket
Socket
Sign inDemoInstall

yaml

Package Overview
Dependencies
Maintainers
1
Versions
90
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-8 to 2.0.0-9

browser/dist/node_modules/tslib/tslib.es6.js

2

browser/dist/compose/compose-node.js

@@ -46,2 +46,4 @@ import { Alias } from '../nodes/Alias.js';

}
if (ctx.options.keepSourceTokens)
node.srcToken = token;
return node;

@@ -48,0 +50,0 @@ }

13

browser/dist/compose/resolve-block-map.js

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

let offset = bm.offset;
for (const { start, key, sep, value } of bm.items) {
for (const collItem of bm.items) {
const { start, key, sep, value } = collItem;
// key properties

@@ -75,3 +76,6 @@ const keyProps = resolveProps(start, {

offset = valueNode.range[2];
map.items.push(new Pair(keyNode, valueNode));
const pair = new Pair(keyNode, valueNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
map.items.push(pair);
}

@@ -88,3 +92,6 @@ else {

}
map.items.push(new Pair(keyNode));
const pair = new Pair(keyNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
map.items.push(pair);
}

@@ -91,0 +98,0 @@ }

@@ -21,3 +21,3 @@ import { Scalar } from '../nodes/Scalar.js';

if (!scalar.source || chompStart === 0) {
const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
const value = header.chomp === '+' ? '\n'.repeat(Math.max(0, lines.length - 1)) : '';
let end = start + header.length;

@@ -24,0 +24,0 @@ if (scalar.source)

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

for (let i = 0; i < fc.items.length; ++i) {
const { start, key, sep, value } = fc.items[i];
const collItem = fc.items[i];
const { start, key, sep, value } = collItem;
const props = resolveProps(start, {

@@ -149,2 +150,4 @@ flow: fcName,

const pair = new Pair(keyNode, valueNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
if (isMap) {

@@ -151,0 +154,0 @@ const map = coll;

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

@@ -10,2 +10,3 @@ import { toJS } from './toJS.js';

if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
value = isAlias(value) ? value.resolve(ctx.doc) : value;
if (isSeq(value))

@@ -12,0 +13,0 @@ for (const it of value.items)

@@ -77,3 +77,4 @@ import { createNode } from '../doc/createNode.js';

*/
deleteIn([key, ...rest]) {
deleteIn(path) {
const [key, ...rest] = path;
if (rest.length === 0)

@@ -92,3 +93,4 @@ return this.delete(key);

*/
getIn([key, ...rest], keepScalar) {
getIn(path, keepScalar) {
const [key, ...rest] = path;
const node = this.get(key, true);

@@ -117,3 +119,4 @@ if (rest.length === 0)

*/
hasIn([key, ...rest]) {
hasIn(path) {
const [key, ...rest] = path;
if (rest.length === 0)

@@ -128,3 +131,4 @@ return this.has(key);

*/
setIn([key, ...rest], value) {
setIn(path, value) {
const [key, ...rest] = path;
if (rest.length === 0) {

@@ -131,0 +135,0 @@ this.set(key, value);

@@ -10,2 +10,3 @@ /**

intAsBigInt: false,
keepSourceTokens: false,
logLevel: 'warn',

@@ -12,0 +13,0 @@ prettyErrors: true,

@@ -6,6 +6,2 @@ import { resolveBlockScalar } from '../compose/resolve-block-scalar.js';

/**
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
* Otherwise, return `null`.
*/
function resolveAsScalar(token, strict = true, onError) {

@@ -52,3 +48,3 @@ if (token) {

inFlow,
options: { lineWidth: -1 }
options: { blockQuote: true, lineWidth: -1 }
});

@@ -122,3 +118,3 @@ const end = (_a = context.end) !== null && _a !== void 0 ? _a : [

inFlow,
options: { lineWidth: -1 }
options: { blockQuote: true, lineWidth: -1 }
});

@@ -125,0 +121,0 @@ switch (source[0]) {

@@ -367,3 +367,3 @@ import { BOM, DOCUMENT, FLOW_END, SCALAR } from './cst.js';

return this.setNext('flow');
if ((indent !== -1 && indent < this.indentNext) ||
if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
(indent === 0 &&

@@ -386,4 +386,7 @@ (line.startsWith('---') || line.startsWith('...')) &&

let n = 0;
while (line[n] === ',')
n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
while (line[n] === ',') {
n += yield* this.pushCount(1);
n += yield* this.pushSpaces(true);
this.flowKey = false;
}
n += yield* this.pushIndicators();

@@ -390,0 +393,0 @@ switch (line[n]) {

@@ -53,7 +53,11 @@ import { map } from './common/map.js';

if (!tags) {
const keys = Object.keys(schemas)
.filter(key => key !== 'yaml11')
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys}`);
if (Array.isArray(customTags))
tags = [];
else {
const keys = Object.keys(schemas)
.filter(key => key !== 'yaml11')
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
}
}

@@ -60,0 +64,0 @@ if (Array.isArray(customTags)) {

@@ -11,2 +11,3 @@ import { anchorIsValid } from '../doc/anchors.js';

options: Object.assign({
blockQuote: true,
defaultKeyType: null,

@@ -23,3 +24,3 @@ defaultStringType: 'PLAIN',

simpleKeys: false,
singleQuote: false,
singleQuote: null,
trueStr: 'true',

@@ -26,0 +27,0 @@ verifyAliasOrder: true

@@ -88,3 +88,3 @@ import { isCollection, isNode, isScalar, isSeq } from '../nodes/Node.js';

if (vcb || keyComment) {
ws = `${vcb}\n${ctx.indent}`;
ws = valueStr === '' && !ctx.inFlow ? vcb : `${vcb}\n${ctx.indent}`;
}

@@ -96,3 +96,3 @@ else if (!explicitKey && isCollection(value)) {

}
else if (valueStr[0] === '\n')
else if (valueStr === '' || valueStr[0] === '\n')
ws = '';

@@ -99,0 +99,0 @@ if (ctx.inFlow) {

@@ -121,11 +121,7 @@ import { Scalar } from '../nodes/Scalar.js';

function singleQuotedString(value, ctx) {
if (ctx.implicitKey) {
if (/\n/.test(value))
return doubleQuotedString(value, ctx);
}
else {
// single quoted string can't have leading or trailing whitespace around newline
if (/[ \t]\n|\n[ \t]/.test(value))
return doubleQuotedString(value, ctx);
}
if (ctx.options.singleQuote === false ||
(ctx.implicitKey && value.includes('\n')) ||
/[ \t]\n|\n[ \t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline
)
return doubleQuotedString(value, ctx);
const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');

@@ -137,15 +133,35 @@ const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";

}
function quotedString(value, ctx) {
const { singleQuote } = ctx.options;
let qs;
if (singleQuote === false)
qs = doubleQuotedString;
else {
const hasDouble = value.includes('"');
const hasSingle = value.includes("'");
if (hasDouble && !hasSingle)
qs = singleQuotedString;
else if (hasSingle && !hasDouble)
qs = doubleQuotedString;
else
qs = singleQuote ? singleQuotedString : doubleQuotedString;
}
return qs(value, ctx);
}
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
const { lineWidth, blockQuote } = ctx.options;
// 1. Block can't end in whitespace unless the last line is non-empty.
// 2. Strings consisting of only whitespace are best rendered explicitly.
if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
return doubleQuotedString(value, ctx);
if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
return quotedString(value, ctx);
}
const indent = ctx.indent ||
(ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
const literal = type === Scalar.BLOCK_FOLDED
? false
: type === Scalar.BLOCK_LITERAL
? true
: !lineLengthOverLimit(value, ctx.options.lineWidth, indent.length);
const literal = blockQuote === 'literal'
? true
: blockQuote === 'folded' || type === Scalar.BLOCK_FOLDED
? false
: type === Scalar.BLOCK_LITERAL
? true
: !lineLengthOverLimit(value, lineWidth, indent.length);
if (!value)

@@ -223,21 +239,6 @@ return literal ? '|\n' : '>\n';

(inFlow && /[[\]{},]/.test(value))) {
return doubleQuotedString(value, ctx);
return quotedString(value, ctx);
}
if (!value ||
/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
const hasDouble = value.indexOf('"') !== -1;
const hasSingle = value.indexOf("'") !== -1;
let quotedString;
if (hasDouble && !hasSingle) {
quotedString = singleQuotedString;
}
else if (hasSingle && !hasDouble) {
quotedString = doubleQuotedString;
}
else if (ctx.options.singleQuote) {
quotedString = singleQuotedString;
}
else {
quotedString = doubleQuotedString;
}
// not allowed:

@@ -273,3 +274,3 @@ // - empty string, '-' or '?'

((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)))
return doubleQuotedString(value, ctx);
return quotedString(value, ctx);
}

@@ -297,3 +298,3 @@ }

return implicitKey || inFlow
? doubleQuotedString(ss.value, ctx) // blocks are not valid inside flow containers
? quotedString(ss.value, ctx) // blocks are not valid inside flow containers
: blockString(ss, ctx, onComment, onChompKeep);

@@ -300,0 +301,0 @@ case Scalar.QUOTE_DOUBLE:

export { debug, warn } from './log.js';
export { findPair } from './nodes/YAMLMap.js';
export { toJS } from './nodes/toJS.js';
export { map as mapTag } from './schema/common/map.js';
export { seq as seqTag } from './schema/common/seq.js';
export { string as stringTag } from './schema/common/string.js';
export { foldFlowLines } from './stringify/foldFlowLines.js';
export { stringifyNumber } from './stringify/stringifyNumber.js';
export { stringifyString } from './stringify/stringifyString.js';

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

}
if (ctx.options.keepSourceTokens)
node.srcToken = token;
return node;

@@ -50,0 +52,0 @@ }

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

let offset = bm.offset;
for (const { start, key, sep, value } of bm.items) {
for (const collItem of bm.items) {
const { start, key, sep, value } = collItem;
// key properties

@@ -77,3 +78,6 @@ const keyProps = resolveProps.resolveProps(start, {

offset = valueNode.range[2];
map.items.push(new Pair.Pair(keyNode, valueNode));
const pair = new Pair.Pair(keyNode, valueNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
map.items.push(pair);
}

@@ -90,3 +94,6 @@ else {

}
map.items.push(new Pair.Pair(keyNode));
const pair = new Pair.Pair(keyNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
map.items.push(pair);
}

@@ -93,0 +100,0 @@ }

@@ -23,3 +23,3 @@ 'use strict';

if (!scalar.source || chompStart === 0) {
const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
const value = header.chomp === '+' ? '\n'.repeat(Math.max(0, lines.length - 1)) : '';
let end = start + header.length;

@@ -26,0 +26,0 @@ if (scalar.source)

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

for (let i = 0; i < fc.items.length; ++i) {
const { start, key, sep, value } = fc.items[i];
const collItem = fc.items[i];
const { start, key, sep, value } = collItem;
const props = resolveProps.resolveProps(start, {

@@ -151,2 +152,4 @@ flow: fcName,

const pair = new Pair.Pair(keyNode, valueNode);
if (ctx.options.keepSourceTokens)
pair.srcToken = collItem;
if (isMap) {

@@ -153,0 +156,0 @@ const map = coll;

export { Composer } from './compose/composer.js';
export { Document } from './doc/Document.js';
export { Schema } from './schema/Schema.js';
export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
export { Alias } from './nodes/Alias.js';
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode } from './nodes/Node.js';
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.js';
export { Pair } from './nodes/Pair.js';

@@ -8,0 +8,0 @@ export { Scalar } from './nodes/Scalar.js';

@@ -12,2 +12,3 @@ 'use strict';

if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
if (Node.isSeq(value))

@@ -14,0 +15,0 @@ for (const it of value.items)

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

import type { Document } from '../doc/Document';
import type { Document } from '../doc/Document.js';
import type { FlowScalar } from '../parse/cst.js';
import type { StringifyContext } from '../stringify/stringify.js';

@@ -6,7 +7,10 @@ import { NodeBase, Range } from './Node.js';

import type { ToJSContext } from './toJS.js';
import type { YAMLMap } from './YAMLMap';
import type { YAMLSeq } from './YAMLSeq';
import type { YAMLMap } from './YAMLMap.js';
import type { YAMLSeq } from './YAMLSeq.js';
export declare namespace Alias {
interface Parsed extends Alias {
range: Range;
srcToken?: FlowScalar & {
type: 'alias';
};
}

@@ -13,0 +17,0 @@ }

@@ -56,3 +56,3 @@ import type { Schema } from '../schema/Schema.js';

*/
deleteIn([key, ...rest]: Iterable<unknown>): boolean;
deleteIn(path: Iterable<unknown>): boolean;
/**

@@ -63,3 +63,3 @@ * Returns item at `key`, or `undefined` if not found. By default unwraps

*/
getIn([key, ...rest]: Iterable<unknown>, keepScalar?: boolean): unknown;
getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
hasAllNullValues(allowScalar?: boolean): boolean;

@@ -69,3 +69,3 @@ /**

*/
hasIn([key, ...rest]: Iterable<unknown>): boolean;
hasIn(path: Iterable<unknown>): boolean;
/**

@@ -75,3 +75,3 @@ * Sets a value in this collection. For `!!set`, `value` needs to be a

*/
setIn([key, ...rest]: Iterable<unknown>, value: unknown): void;
setIn(path: Iterable<unknown>, value: unknown): void;
}

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

*/
deleteIn([key, ...rest]) {
deleteIn(path) {
const [key, ...rest] = path;
if (rest.length === 0)

@@ -94,3 +95,4 @@ return this.delete(key);

*/
getIn([key, ...rest], keepScalar) {
getIn(path, keepScalar) {
const [key, ...rest] = path;
const node = this.get(key, true);

@@ -119,3 +121,4 @@ if (rest.length === 0)

*/
hasIn([key, ...rest]) {
hasIn(path) {
const [key, ...rest] = path;
if (rest.length === 0)

@@ -130,3 +133,4 @@ return this.has(key);

*/
setIn([key, ...rest], value) {
setIn(path, value) {
const [key, ...rest] = path;
if (rest.length === 0) {

@@ -133,0 +137,0 @@ this.set(key, value);

import type { Document } from '../doc/Document.js';
import { Token } from '../parse/cst.js';
import type { StringifyContext } from '../stringify/stringify.js';

@@ -42,2 +43,4 @@ import type { Alias } from './Alias.js';

spaceBefore?: boolean;
/** The CST token that was composed into this node. */
srcToken?: Token;
/** A fully qualified tag, if required */

@@ -44,0 +47,0 @@ tag?: string;

import { CreateNodeContext } from '../doc/createNode.js';
import type { CollectionItem } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';

@@ -14,2 +15,4 @@ import type { StringifyContext } from '../stringify/stringify.js';

value: V | null;
/** The CST token that was composed into this pair. */
srcToken?: CollectionItem;
constructor(key: K, value?: V | null);

@@ -16,0 +19,0 @@ clone(schema?: Schema): Pair<K, V>;

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

import type { BlockScalar, FlowScalar } from '../parse/cst.js';
import { NodeBase, Range } from './Node.js';

@@ -8,2 +9,3 @@ import { ToJSContext } from './toJS.js';

source: string;
srcToken?: FlowScalar | BlockScalar;
}

@@ -10,0 +12,0 @@ type BLOCK_FOLDED = 'BLOCK_FOLDED';

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

import type { BlockMap, FlowCollection } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';

@@ -12,2 +13,3 @@ import type { StringifyContext } from '../stringify/stringify.js';

range: Range;
srcToken?: BlockMap | FlowCollection;
}

@@ -14,0 +16,0 @@ }

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

import type { BlockSequence, FlowCollection } from '../parse/cst.js';
import type { Schema } from '../schema/Schema.js';

@@ -11,2 +12,3 @@ import type { StringifyContext } from '../stringify/stringify.js';

range: Range;
srcToken?: BlockSequence | FlowCollection;
}

@@ -13,0 +15,0 @@ }

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

/**
* Include a `srcToken` value on each parsed `Node`, containing the CST token
* that was composed into this node.
*
* Default: `false`
*/
keepSourceTokens?: boolean;
/**
* If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`

@@ -166,2 +173,9 @@ * to provide the `{ line, col }` positions within the input.

/**
* Use block quote styles for scalar values where applicable.
* Set to `false` to disable block quotes completely.
*
* Default: `true`
*/
blockQuote?: boolean | 'folded' | 'literal';
/**
* The default type of string literal used to stringify implicit key values.

@@ -259,7 +273,8 @@ * Output may use other types if required to fully represent the value.

/**
* Prefer 'single quote' rather than "double quote" where applicable.
* Use 'single quote' rather than "double quote" where applicable.
* Set to `false` to disable single quotes completely.
*
* Default: `false`
* Default: `null`
*/
singleQuote?: boolean;
singleQuote?: boolean | null;
/**

@@ -266,0 +281,0 @@ * String representation for `true`.

@@ -12,2 +12,3 @@ 'use strict';

intAsBigInt: false,
keepSourceTokens: false,
logLevel: 'warn',

@@ -14,0 +15,0 @@ prettyErrors: true,

@@ -9,2 +9,8 @@ import { ErrorCode } from '../errors.js';

*/
export declare function resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
value: string;
type: Scalar.Type | null;
comment: string;
range: Range;
};
export declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {

@@ -11,0 +17,0 @@ value: string;

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

/**
* If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
* Otherwise, return `null`.
*/
function resolveAsScalar(token, strict = true, onError) {

@@ -54,3 +50,3 @@ if (token) {

inFlow,
options: { lineWidth: -1 }
options: { blockQuote: true, lineWidth: -1 }
});

@@ -124,3 +120,3 @@ const end = (_a = context.end) !== null && _a !== void 0 ? _a : [

inFlow,
options: { lineWidth: -1 }
options: { blockQuote: true, lineWidth: -1 }
});

@@ -127,0 +123,0 @@ switch (source[0]) {

@@ -369,3 +369,3 @@ 'use strict';

return this.setNext('flow');
if ((indent !== -1 && indent < this.indentNext) ||
if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
(indent === 0 &&

@@ -388,4 +388,7 @@ (line.startsWith('---') || line.startsWith('...')) &&

let n = 0;
while (line[n] === ',')
n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
while (line[n] === ',') {
n += yield* this.pushCount(1);
n += yield* this.pushSpaces(true);
this.flowKey = false;
}
n += yield* this.pushIndicators();

@@ -392,0 +395,0 @@ switch (line[n]) {

@@ -55,7 +55,11 @@ 'use strict';

if (!tags) {
const keys = Object.keys(schemas)
.filter(key => key !== 'yaml11')
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys}`);
if (Array.isArray(customTags))
tags = [];
else {
const keys = Object.keys(schemas)
.filter(key => key !== 'yaml11')
.map(key => JSON.stringify(key))
.join(', ');
throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
}
}

@@ -62,0 +66,0 @@ if (Array.isArray(customTags)) {

@@ -13,2 +13,3 @@ 'use strict';

options: Object.assign({
blockQuote: true,
defaultKeyType: null,

@@ -25,3 +26,3 @@ defaultStringType: 'PLAIN',

simpleKeys: false,
singleQuote: false,
singleQuote: null,
trueStr: 'true',

@@ -28,0 +29,0 @@ verifyAliasOrder: true

@@ -90,3 +90,3 @@ 'use strict';

if (vcb || keyComment) {
ws = `${vcb}\n${ctx.indent}`;
ws = valueStr === '' && !ctx.inFlow ? vcb : `${vcb}\n${ctx.indent}`;
}

@@ -98,3 +98,3 @@ else if (!explicitKey && Node.isCollection(value)) {

}
else if (valueStr[0] === '\n')
else if (valueStr === '' || valueStr[0] === '\n')
ws = '';

@@ -101,0 +101,0 @@ if (ctx.inFlow) {

@@ -123,11 +123,7 @@ 'use strict';

function singleQuotedString(value, ctx) {
if (ctx.implicitKey) {
if (/\n/.test(value))
return doubleQuotedString(value, ctx);
}
else {
// single quoted string can't have leading or trailing whitespace around newline
if (/[ \t]\n|\n[ \t]/.test(value))
return doubleQuotedString(value, ctx);
}
if (ctx.options.singleQuote === false ||
(ctx.implicitKey && value.includes('\n')) ||
/[ \t]\n|\n[ \t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline
)
return doubleQuotedString(value, ctx);
const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');

@@ -139,15 +135,35 @@ const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";

}
function quotedString(value, ctx) {
const { singleQuote } = ctx.options;
let qs;
if (singleQuote === false)
qs = doubleQuotedString;
else {
const hasDouble = value.includes('"');
const hasSingle = value.includes("'");
if (hasDouble && !hasSingle)
qs = singleQuotedString;
else if (hasSingle && !hasDouble)
qs = doubleQuotedString;
else
qs = singleQuote ? singleQuotedString : doubleQuotedString;
}
return qs(value, ctx);
}
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
const { lineWidth, blockQuote } = ctx.options;
// 1. Block can't end in whitespace unless the last line is non-empty.
// 2. Strings consisting of only whitespace are best rendered explicitly.
if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
return doubleQuotedString(value, ctx);
if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
return quotedString(value, ctx);
}
const indent = ctx.indent ||
(ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
const literal = type === Scalar.Scalar.BLOCK_FOLDED
? false
: type === Scalar.Scalar.BLOCK_LITERAL
? true
: !lineLengthOverLimit(value, ctx.options.lineWidth, indent.length);
const literal = blockQuote === 'literal'
? true
: blockQuote === 'folded' || type === Scalar.Scalar.BLOCK_FOLDED
? false
: type === Scalar.Scalar.BLOCK_LITERAL
? true
: !lineLengthOverLimit(value, lineWidth, indent.length);
if (!value)

@@ -225,21 +241,6 @@ return literal ? '|\n' : '>\n';

(inFlow && /[[\]{},]/.test(value))) {
return doubleQuotedString(value, ctx);
return quotedString(value, ctx);
}
if (!value ||
/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
const hasDouble = value.indexOf('"') !== -1;
const hasSingle = value.indexOf("'") !== -1;
let quotedString;
if (hasDouble && !hasSingle) {
quotedString = singleQuotedString;
}
else if (hasSingle && !hasDouble) {
quotedString = doubleQuotedString;
}
else if (ctx.options.singleQuote) {
quotedString = singleQuotedString;
}
else {
quotedString = doubleQuotedString;
}
// not allowed:

@@ -275,3 +276,3 @@ // - empty string, '-' or '?'

((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)))
return doubleQuotedString(value, ctx);
return quotedString(value, ctx);
}

@@ -299,3 +300,3 @@ }

return implicitKey || inFlow
? doubleQuotedString(ss.value, ctx) // blocks are not valid inside flow containers
? quotedString(ss.value, ctx) // blocks are not valid inside flow containers
: blockString(ss, ctx, onComment, onChompKeep);

@@ -302,0 +303,0 @@ case Scalar.Scalar.QUOTE_DOUBLE:

export declare function testEvents(src: string): {
events: string[];
error: any;
error: unknown;
};
export { debug, LogLevelId, warn } from './log.js';
export { findPair } from './nodes/YAMLMap.js';
export { toJS, ToJSContext } from './nodes/toJS.js';
export { map as mapTag } from './schema/common/map.js';
export { seq as seqTag } from './schema/common/seq.js';
export { string as stringTag } from './schema/common/string.js';
export { foldFlowLines } from './stringify/foldFlowLines';
export { stringifyNumber } from './stringify/stringifyNumber.js';
export { stringifyString } from './stringify/stringifyString.js';

@@ -6,2 +6,5 @@ 'use strict';

var toJS = require('./nodes/toJS.js');
var map = require('./schema/common/map.js');
var seq = require('./schema/common/seq.js');
var string = require('./schema/common/string.js');
var foldFlowLines = require('./stringify/foldFlowLines.js');

@@ -17,4 +20,7 @@ var stringifyNumber = require('./stringify/stringifyNumber.js');

exports.toJS = toJS.toJS;
exports.mapTag = map.map;
exports.seqTag = seq.seq;
exports.stringTag = string.string;
exports.foldFlowLines = foldFlowLines.foldFlowLines;
exports.stringifyNumber = stringifyNumber.stringifyNumber;
exports.stringifyString = stringifyString.stringifyString;
{
"name": "yaml",
"version": "2.0.0-8",
"version": "2.0.0-9",
"license": "ISC",

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

"dist/",
"util.d.ts",
"util.js"

@@ -72,6 +73,6 @@ ],

"@rollup/plugin-babel": "^5.2.3",
"@rollup/plugin-replace": "^2.3.4",
"@rollup/plugin-replace": "^3.0.0",
"@rollup/plugin-typescript": "^8.1.1",
"@types/jest": "^27.0.1",
"@types/node": "^15.6.1",
"@types/node": "^16.9.1",
"@typescript-eslint/eslint-plugin": "^4.15.2",

@@ -78,0 +79,0 @@ "@typescript-eslint/parser": "^4.15.2",

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