Socket
Socket
Sign inDemoInstall

yaml

Package Overview
Dependencies
0
Maintainers
1
Versions
88
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.1 to 2.1.0

dist/schema/json-schema.d.ts

2

browser/dist/compose/compose-collection.js

@@ -54,3 +54,3 @@ import { isNode, isMap } from '../nodes/Node.js';

node.tag = tagName;
if (tag === null || tag === void 0 ? void 0 : tag.format)
if (tag?.format)
node.format = tag.format;

@@ -57,0 +57,0 @@ return node;

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

function composeDoc(options, directives, { offset, start, value, end }, onError) {
const opts = Object.assign({ directives }, options);
const opts = Object.assign({ _directives: directives }, options);
const doc = new Document(undefined, opts);

@@ -18,3 +18,3 @@ const ctx = {

indicator: 'doc-start',
next: value !== null && value !== void 0 ? value : end === null || end === void 0 ? void 0 : end[0],
next: value ?? end?.[0],
offset,

@@ -21,0 +21,0 @@ onError,

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

try {
const res = tag.resolve(value, msg => onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
scalar = isScalar(res) ? res : new Scalar(res);

@@ -26,3 +26,3 @@ }

const msg = error instanceof Error ? error.message : String(error);
onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg);
onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
scalar = new Scalar(value);

@@ -43,3 +43,2 @@ }

function findScalarTagByName(schema, value, tagName, tagToken, onError) {
var _a;
if (tagName === '!')

@@ -57,3 +56,3 @@ return schema[SCALAR]; // non-specific tag

for (const tag of matchWithTest)
if ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value))
if (tag.test?.test(value))
return tag;

@@ -71,6 +70,6 @@ const kt = schema.knownTags[tagName];

function findScalarTagByTest({ directives, schema }, value, token, onError) {
var _a;
const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[SCALAR];
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[SCALAR];
if (schema.compat) {
const compat = (_a = schema.compat.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); })) !== null && _a !== void 0 ? _a : schema[SCALAR];
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
schema[SCALAR];
if (tag.tag !== compat.tag) {

@@ -77,0 +76,0 @@ const ts = directives.tagString(tag.tag);

@@ -17,3 +17,2 @@ import { Directives } from '../doc/directives.js';

function parsePrelude(prelude) {
var _a;
let comment = '';

@@ -33,3 +32,3 @@ let atComment = false;

case '%':
if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
if (prelude[i + 1]?.[0] !== '#')
i += 1;

@@ -209,3 +208,3 @@ atComment = false;

else if (forceDoc) {
const opts = Object.assign({ directives: this.directives }, this.options);
const opts = Object.assign({ _directives: this.directives }, this.options);
const doc = new Document(undefined, opts);

@@ -212,0 +211,0 @@ if (this.atDirectives)

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

function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
var _a;
const map = new YAMLMap(ctx.schema);

@@ -21,3 +20,3 @@ if (ctx.atRoot)

indicator: 'explicit-key-ind',
next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
next: key ?? sep?.[0],
offset,

@@ -46,6 +45,6 @@ onError,

if (keyProps.hasNewlineAfterProp || containsNewline(key)) {
onError(key !== null && key !== void 0 ? key : start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
}
}
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent) {
else if (keyProps.found?.indent !== bm.indent) {
onError(offset, 'BAD_INDENT', startColMsg);

@@ -63,3 +62,3 @@ }

// value properties
const valueProps = resolveProps(sep !== null && sep !== void 0 ? sep : [], {
const valueProps = resolveProps(sep ?? [], {
indicator: 'map-value-ind',

@@ -74,3 +73,3 @@ next: value,

if (implicitKey) {
if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
if (value?.type === 'block-map' && !valueProps.hasNewline)
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');

@@ -77,0 +76,0 @@ if (ctx.options.strict &&

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

const m = first.match(/^( *)/);
const line0 = (m === null || m === void 0 ? void 0 : m[1])
const line0 = m?.[1]
? [m[1], first.slice(m[1].length)]

@@ -188,0 +188,0 @@ : ['', first];

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

function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
var _a;
const isMap = fc.start.source === '{';

@@ -31,3 +30,3 @@ const fcName = isMap ? 'flow map' : 'flow sequence';

indicator: 'explicit-key-ind',
next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
next: key ?? sep?.[0],
offset,

@@ -80,3 +79,3 @@ onError,

if (isPair(prev))
prev = (_a = prev.value) !== null && _a !== void 0 ? _a : prev.key;
prev = prev.value ?? prev.key;
if (prev.comment)

@@ -111,3 +110,3 @@ prev.comment += '\n' + prevItemComment;

// value properties
const valueProps = resolveProps(sep !== null && sep !== void 0 ? sep : [], {
const valueProps = resolveProps(sep ?? [], {
flow: fcName,

@@ -114,0 +113,0 @@ indicator: 'map-value-ind',

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

function foldLines(source) {
var _a;
/**

@@ -116,3 +115,3 @@ * The negative lookbehind here and in the `re` RegExp is to

match = last.exec(source);
return res + sep + ((_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : '');
return res + sep + (match?.[1] ?? '');
}

@@ -119,0 +118,0 @@ function doubleQuotedValue(source, onError) {

@@ -90,3 +90,3 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) {

if (found)
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow !== null && flow !== void 0 ? flow : 'collection'}`);
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
found = token;

@@ -131,3 +131,3 @@ atNewline = false;

end,
start: start !== null && start !== void 0 ? start : end
start: start ?? end
};

@@ -134,0 +134,0 @@ }

@@ -17,3 +17,3 @@ function emptyScalarPosition(offset, before, pos) {

st = before[++i];
while ((st === null || st === void 0 ? void 0 : st.type) === 'space') {
while (st?.type === 'space') {
offset += st.source.length;

@@ -20,0 +20,0 @@ st = before[++i];

import { containsNewline } from './util-contains-newline.js';
function flowIndentCheck(indent, fc, onError) {
if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
if (fc?.type === 'flow-collection') {
const end = fc.end[0];

@@ -6,0 +6,0 @@ if (end.indent === indent &&

@@ -7,6 +7,5 @@ import { Alias } from '../nodes/Alias.js';

function findTagObject(value, tagName, tags) {
var _a;
if (tagName) {
const match = tags.filter(t => t.tag === tagName);
const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
const tagObj = match.find(t => !t.format) ?? match[0];
if (!tagObj)

@@ -16,6 +15,5 @@ throw new Error(`Tag ${tagName} not found`);

}
return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
return tags.find(t => t.identify?.(value) && !t.format);
}
function createNode(value, tagName, ctx) {
var _a, _b;
if (isDocument(value))

@@ -26,3 +24,3 @@ value = value.contents;

if (isPair(value)) {
const map = (_b = (_a = ctx.schema[MAP]).createNode) === null || _b === void 0 ? void 0 : _b.call(_a, ctx.schema, null, ctx);
const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);
map.items.push(value);

@@ -55,3 +53,3 @@ return map;

}
if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
if (tagName?.startsWith('!!'))
tagName = defaultTagPrefix + tagName.slice(2);

@@ -81,3 +79,3 @@ let tagObj = findTagObject(value, tagName, schema.tags);

}
const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
const node = tagObj?.createNode
? tagObj.createNode(ctx.schema, value, ctx)

@@ -84,0 +82,0 @@ : new Scalar(value);

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

let { version } = opt;
if (options === null || options === void 0 ? void 0 : options.directives) {
this.directives = options.directives.atDocument();
if (options?._directives) {
this.directives = options._directives.atDocument();
if (this.directives.yaml.explicit)

@@ -128,3 +128,3 @@ version = this.directives.yaml.version;

}
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options !== null && options !== void 0 ? options : {};
const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(this,

@@ -134,4 +134,4 @@ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

const ctx = {
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
aliasDuplicateObjects: aliasDuplicateObjects ?? true,
keepUndefined: keepUndefined ?? false,
onAnchor,

@@ -300,3 +300,3 @@ onTagObj,

};
const res = toJS(this.contents, jsonArg !== null && jsonArg !== void 0 ? jsonArg : '', ctx);
const res = toJS(this.contents, jsonArg ?? '', ctx);
if (typeof onAnchor === 'function')

@@ -303,0 +303,0 @@ for (const { count, res } of ctx.anchors.values())

@@ -9,3 +9,3 @@ import { warn } from '../log.js';

function addPairToJSMap(ctx, map, { key, value }) {
if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
if (ctx?.doc.schema.merge && isMergeKey(key)) {
value = isAlias(value) ? value.resolve(ctx.doc) : value;

@@ -12,0 +12,0 @@ if (isSeq(value))

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

}
// null, undefined, or an empty non-string iterable (e.g. [])
// Type guard is intentionally a little wrong so as to be more useful,
// as it does not cover untypable empty non-string iterables (e.g. []).
const isEmptyPath = (path) => path == null ||

@@ -30,0 +31,0 @@ (typeof path === 'object' && !!path[Symbol.iterator]().next().done);

@@ -26,7 +26,7 @@ import { createNode } from '../doc/createNode.js';

toJSON(_, ctx) {
const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
const pair = ctx?.mapAsMap ? new Map() : {};
return addPairToJSMap(ctx, pair, this);
}
toString(ctx, onComment, onChompKeep) {
return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
return ctx?.doc
? stringifyPair(this, ctx, onComment, onChompKeep)

@@ -33,0 +33,0 @@ : JSON.stringify(this);

@@ -11,3 +11,3 @@ import { NodeBase, SCALAR } from './Node.js';

toJSON(arg, ctx) {
return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
return ctx?.keep ? this.value : toJS(this.value, arg, ctx);
}

@@ -14,0 +14,0 @@ toString() {

@@ -32,3 +32,3 @@ import { hasAnchor } from './Node.js';

}
if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
if (typeof value === 'bigint' && !ctx?.keep)
return Number(value);

@@ -35,0 +35,0 @@ return value;

@@ -35,3 +35,2 @@ import { stringifyCollection } from '../stringify/stringifyCollection.js';

add(pair, overwrite) {
var _a;
let _pair;

@@ -42,3 +41,3 @@ if (isPair(pair))

// In TypeScript, this never happens.
_pair = new Pair(pair, pair.value);
_pair = new Pair(pair, pair?.value);
}

@@ -48,3 +47,3 @@ else

const prev = findPair(this.items, _pair.key);
const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
const sortEntries = this.schema?.sortMapEntries;
if (prev) {

@@ -79,4 +78,4 @@ if (!overwrite)

const it = findPair(this.items, key);
const node = it === null || it === void 0 ? void 0 : it.value;
return !keepScalar && isScalar(node) ? node.value : node;
const node = it?.value;
return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;
}

@@ -95,4 +94,4 @@ has(key) {

toJSON(_, ctx, Type) {
const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
if (ctx?.onCreate)
ctx.onCreate(map);

@@ -99,0 +98,0 @@ for (const item of this.items)

@@ -33,10 +33,2 @@ import { stringifyCollection } from '../stringify/stringifyCollection.js';

}
/**
* Returns item at `key`, or `undefined` if not found. By default unwraps
* scalar values from their surrounding node; to disable set `keepScalar` to
* `true` (collections are always returned intact).
*
* `key` must contain a representation of an integer for this to succeed.
* It may be wrapped in a `Scalar`.
*/
get(key, keepScalar) {

@@ -78,3 +70,3 @@ const idx = asItemIndex(key);

const seq = [];
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
if (ctx?.onCreate)
ctx.onCreate(seq);

@@ -81,0 +73,0 @@ let i = 0;

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

function createScalarToken(value, context) {
var _a;
const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;

@@ -50,3 +49,3 @@ const source = stringifyString({ type, value }, {

});
const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
const end = context.end ?? [
{ type: 'newline', offset: -1, indent, source: '\n' }

@@ -53,0 +52,0 @@ ];

@@ -50,3 +50,3 @@ const BREAK = Symbol('break visit');

for (const [field, index] of path) {
const tok = item === null || item === void 0 ? void 0 : item[field];
const tok = item?.[field];
if (tok && 'items' in tok) {

@@ -68,3 +68,3 @@ item = tok.items[index];

const field = path[path.length - 1][0];
const coll = parent === null || parent === void 0 ? void 0 : parent[field];
const coll = parent?.[field];
if (coll && 'items' in coll)

@@ -71,0 +71,0 @@ return coll;

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

*lex(source, incomplete = false) {
var _a;
if (source) {

@@ -158,3 +157,3 @@ this.buffer = this.buffer ? this.buffer + source : source;

this.atEnd = !incomplete;
let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
let next = this.next ?? 'stream';
while (next && (incomplete || this.hasChars(1)))

@@ -161,0 +160,0 @@ next = yield* this.parseNext(next);

@@ -24,3 +24,3 @@ import { tokenType } from './cst.js';

function isFlowToken(token) {
switch (token === null || token === void 0 ? void 0 : token.type) {
switch (token?.type) {
case 'alias':

@@ -37,3 +37,2 @@ case 'scalar':

function getPrevProps(parent) {
var _a;
switch (parent.type) {

@@ -44,3 +43,3 @@ case 'document':

const it = parent.items[parent.items.length - 1];
return (_a = it.sep) !== null && _a !== void 0 ? _a : it.start;
return it.sep ?? it.start;
}

@@ -56,3 +55,2 @@ case 'block-seq':

function getFirstKeyStartProps(prev) {
var _a;
if (prev.length === 0)

@@ -71,3 +69,3 @@ return [];

}
while (((_a = prev[++i]) === null || _a === void 0 ? void 0 : _a.type) === 'space') {
while (prev[++i]?.type === 'space') {
/* loop */

@@ -274,3 +272,3 @@ }

*pop(error) {
const token = error !== null && error !== void 0 ? error : this.stack.pop();
const token = error ?? this.stack.pop();
/* istanbul ignore if should not happen */

@@ -480,3 +478,2 @@ if (!token) {

*blockMap(map) {
var _a;
const it = map.items[map.items.length - 1];

@@ -490,4 +487,4 @@ // it.sep is true-ish if pair already has key or : separator

const last = Array.isArray(end) ? end[end.length - 1] : undefined;
if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
if (last?.type === 'comment')
end?.push(this.sourceToken);
else

@@ -514,3 +511,3 @@ map.items.push({ start: [this.sourceToken] });

const prev = map.items[map.items.length - 2];
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
const end = prev?.value?.end;
if (Array.isArray(end)) {

@@ -692,3 +689,2 @@ Array.prototype.push.apply(end, it.start);

*blockSequence(seq) {
var _a;
const it = seq.items[seq.items.length - 1];

@@ -700,4 +696,4 @@ switch (this.type) {

const last = Array.isArray(end) ? end[end.length - 1] : undefined;
if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
if (last?.type === 'comment')
end?.push(this.sourceToken);
else

@@ -716,3 +712,3 @@ seq.items.push({ start: [this.sourceToken] });

const prev = seq.items[seq.items.length - 2];
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
const end = prev?.value?.end;
if (Array.isArray(end)) {

@@ -719,0 +715,0 @@ Array.prototype.push.apply(end, it.start);

@@ -24,3 +24,3 @@ import { Composer } from './compose/composer.js';

const { lineCounter, prettyErrors } = parseOptions(options);
const parser = new Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
const parser = new Parser(lineCounter?.addNewLine);
const composer = new Composer(options);

@@ -40,3 +40,3 @@ const docs = Array.from(composer.compose(parser.parse(source)));

const { lineCounter, prettyErrors } = parseOptions(options);
const parser = new Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
const parser = new Parser(lineCounter?.addNewLine);
const composer = new Composer(options);

@@ -80,3 +80,2 @@ // `doc` is always set by compose.end(true) at the very latest

function stringify(value, replacer, options) {
var _a;
let _replacer = null;

@@ -96,3 +95,3 @@ if (typeof replacer === 'function' || Array.isArray(replacer)) {

if (value === undefined) {
const { keepUndefined } = (_a = options !== null && options !== void 0 ? options : replacer) !== null && _a !== void 0 ? _a : {};
const { keepUndefined } = options ?? replacer ?? {};
if (!keepUndefined)

@@ -99,0 +98,0 @@ return undefined;

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

this.tags = getTags(customTags, this.name);
this.toStringOptions = toStringDefaults !== null && toStringDefaults !== void 0 ? toStringDefaults : null;
this.toStringOptions = toStringDefaults ?? null;
Object.defineProperty(this, MAP, { value: map });

@@ -22,0 +22,0 @@ Object.defineProperty(this, SCALAR, { value: string });

@@ -25,3 +25,3 @@ import { YAMLSeq } from '../../nodes/YAMLSeq.js';

const map = new Map();
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
if (ctx?.onCreate)
ctx.onCreate(map);

@@ -28,0 +28,0 @@ for (const pair of this.items) {

@@ -7,3 +7,2 @@ import { isSeq, isPair, isMap } from '../../nodes/Node.js';

function resolvePairs(seq, onError) {
var _a;
if (isSeq(seq)) {

@@ -23,3 +22,3 @@ for (let i = 0; i < seq.items.length; ++i) {

if (item.comment) {
const cn = (_a = pair.value) !== null && _a !== void 0 ? _a : pair.key;
const cn = pair.value ?? pair.key;
cn.comment = cn.comment

@@ -26,0 +25,0 @@ ? `${item.comment}\n${cn.comment}`

@@ -25,2 +25,6 @@ import { isMap, isPair, isScalar } from '../../nodes/Node.js';

}
/**
* If `keepPair` is `true`, returns the Pair matching `key`.
* Otherwise, returns the value of that Pair's key.
*/
get(key, keepPair) {

@@ -27,0 +31,0 @@ const pair = findPair(this.items, key);

@@ -46,7 +46,6 @@ import { anchorIsValid } from '../doc/anchors.js';

function getTagObject(tags, item) {
var _a, _b, _c, _d;
if (item.tag) {
const match = tags.filter(t => t.tag === item.tag);
if (match.length > 0)
return (_a = match.find(t => t.format === item.format)) !== null && _a !== void 0 ? _a : match[0];
return match.find(t => t.format === item.format) ?? match[0];
}

@@ -57,5 +56,5 @@ let tagObj = undefined;

obj = item.value;
const match = tags.filter(t => { var _a; return (_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, obj); });
const match = tags.filter(t => t.identify?.(obj));
tagObj =
(_b = match.find(t => t.format === item.format)) !== null && _b !== void 0 ? _b : match.find(t => !t.format);
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
}

@@ -67,3 +66,3 @@ else {

if (!tagObj) {
const name = (_d = (_c = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : typeof obj;
const name = obj?.constructor?.name ?? typeof obj;
throw new Error(`Tag not resolved for ${name} value`);

@@ -89,3 +88,2 @@ }

function stringify(item, ctx, onComment, onChompKeep) {
var _a, _b;
if (isPair(item))

@@ -96,3 +94,3 @@ return item.toString(ctx, onComment, onChompKeep);

return item.toString(ctx);
if ((_a = ctx.resolvedAliases) === null || _a === void 0 ? void 0 : _a.has(item)) {
if (ctx.resolvedAliases?.has(item)) {
throw new TypeError(`Cannot stringify circular structure without alias nodes`);

@@ -116,3 +114,3 @@ }

if (props.length > 0)
ctx.indentAtStart = ((_b = ctx.indentAtStart) !== null && _b !== void 0 ? _b : 0) + props.length + 1;
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
const str = typeof tagObj.stringify === 'function'

@@ -119,0 +117,0 @@ ? tagObj.stringify(node, ctx, onComment, onChompKeep)

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

function stringifyCollection(collection, ctx, options) {
var _a;
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
const flow = ctx.inFlow ?? collection.flow;
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;

@@ -11,0 +10,0 @@ return stringify(collection, ctx, options);

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

function stringifyDocument(doc, options) {
var _a;
const lines = [];

@@ -59,3 +58,3 @@ let hasDirectives = options.directives === true;

}
if ((_a = doc.directives) === null || _a === void 0 ? void 0 : _a.docEnd) {
if (doc.directives?.docEnd) {
if (doc.comment) {

@@ -62,0 +61,0 @@ const cs = commentString(doc.comment);

@@ -266,5 +266,5 @@ import { Scalar } from '../nodes/Scalar.js';

if (actualString) {
const test = (tag) => { var _a; return tag.default && tag.tag !== 'tag:yaml.org,2002:str' && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)); };
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
const { compat, tags } = ctx.doc.schema;
if (tags.some(test) || (compat === null || compat === void 0 ? void 0 : compat.some(test)))
if (tags.some(test) || compat?.some(test))
return quotedString(value, ctx);

@@ -271,0 +271,0 @@ }

@@ -199,15 +199,14 @@ import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js';

function callVisitor(key, node, visitor, path) {
var _a, _b, _c, _d, _e;
if (typeof visitor === 'function')
return visitor(key, node, path);
if (isMap(node))
return (_a = visitor.Map) === null || _a === void 0 ? void 0 : _a.call(visitor, key, node, path);
return visitor.Map?.(key, node, path);
if (isSeq(node))
return (_b = visitor.Seq) === null || _b === void 0 ? void 0 : _b.call(visitor, key, node, path);
return visitor.Seq?.(key, node, path);
if (isPair(node))
return (_c = visitor.Pair) === null || _c === void 0 ? void 0 : _c.call(visitor, key, node, path);
return visitor.Pair?.(key, node, path);
if (isScalar(node))
return (_d = visitor.Scalar) === null || _d === void 0 ? void 0 : _d.call(visitor, key, node, path);
return visitor.Scalar?.(key, node, path);
if (isAlias(node))
return (_e = visitor.Alias) === null || _e === void 0 ? void 0 : _e.call(visitor, key, node, path);
return visitor.Alias?.(key, node, path);
return undefined;

@@ -214,0 +213,0 @@ }

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

node.tag = tagName;
if (tag === null || tag === void 0 ? void 0 : tag.format)
if (tag?.format)
node.format = tag.format;

@@ -59,0 +59,0 @@ return node;

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

function composeDoc(options, directives, { offset, start, value, end }, onError) {
const opts = Object.assign({ directives }, options);
const opts = Object.assign({ _directives: directives }, options);
const doc = new Document.Document(undefined, opts);

@@ -20,3 +20,3 @@ const ctx = {

indicator: 'doc-start',
next: value !== null && value !== void 0 ? value : end === null || end === void 0 ? void 0 : end[0],
next: value ?? end?.[0],
offset,

@@ -23,0 +23,0 @@ onError,

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

try {
const res = tag.resolve(value, msg => onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);

@@ -28,3 +28,3 @@ }

const msg = error instanceof Error ? error.message : String(error);
onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg);
onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
scalar = new Scalar.Scalar(value);

@@ -45,3 +45,2 @@ }

function findScalarTagByName(schema, value, tagName, tagToken, onError) {
var _a;
if (tagName === '!')

@@ -59,3 +58,3 @@ return schema[Node.SCALAR]; // non-specific tag

for (const tag of matchWithTest)
if ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value))
if (tag.test?.test(value))
return tag;

@@ -73,6 +72,6 @@ const kt = schema.knownTags[tagName];

function findScalarTagByTest({ directives, schema }, value, token, onError) {
var _a;
const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[Node.SCALAR];
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
if (schema.compat) {
const compat = (_a = schema.compat.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); })) !== null && _a !== void 0 ? _a : schema[Node.SCALAR];
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
schema[Node.SCALAR];
if (tag.tag !== compat.tag) {

@@ -79,0 +78,0 @@ const ts = directives.tagString(tag.tag);

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

function parsePrelude(prelude) {
var _a;
let comment = '';

@@ -35,3 +34,3 @@ let atComment = false;

case '%':
if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
if (prelude[i + 1]?.[0] !== '#')
i += 1;

@@ -213,3 +212,3 @@ atComment = false;

else if (forceDoc) {
const opts = Object.assign({ directives: this.directives }, this.options);
const opts = Object.assign({ _directives: this.directives }, this.options);
const doc = new Document.Document(undefined, opts);

@@ -216,0 +215,0 @@ if (this.atDirectives)

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

function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
var _a;
const map = new YAMLMap.YAMLMap(ctx.schema);

@@ -23,3 +22,3 @@ if (ctx.atRoot)

indicator: 'explicit-key-ind',
next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
next: key ?? sep?.[0],
offset,

@@ -48,6 +47,6 @@ onError,

if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
onError(key !== null && key !== void 0 ? key : start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
}
}
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent) {
else if (keyProps.found?.indent !== bm.indent) {
onError(offset, 'BAD_INDENT', startColMsg);

@@ -65,3 +64,3 @@ }

// value properties
const valueProps = resolveProps.resolveProps(sep !== null && sep !== void 0 ? sep : [], {
const valueProps = resolveProps.resolveProps(sep ?? [], {
indicator: 'map-value-ind',

@@ -76,3 +75,3 @@ next: value,

if (implicitKey) {
if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
if (value?.type === 'block-map' && !valueProps.hasNewline)
onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');

@@ -79,0 +78,0 @@ if (ctx.options.strict &&

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

const m = first.match(/^( *)/);
const line0 = (m === null || m === void 0 ? void 0 : m[1])
const line0 = m?.[1]
? [m[1], first.slice(m[1].length)]

@@ -190,0 +190,0 @@ : ['', first];

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

function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
var _a;
const isMap = fc.start.source === '{';

@@ -33,3 +32,3 @@ const fcName = isMap ? 'flow map' : 'flow sequence';

indicator: 'explicit-key-ind',
next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
next: key ?? sep?.[0],
offset,

@@ -82,3 +81,3 @@ onError,

if (Node.isPair(prev))
prev = (_a = prev.value) !== null && _a !== void 0 ? _a : prev.key;
prev = prev.value ?? prev.key;
if (prev.comment)

@@ -113,3 +112,3 @@ prev.comment += '\n' + prevItemComment;

// value properties
const valueProps = resolveProps.resolveProps(sep !== null && sep !== void 0 ? sep : [], {
const valueProps = resolveProps.resolveProps(sep ?? [], {
flow: fcName,

@@ -116,0 +115,0 @@ indicator: 'map-value-ind',

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

function foldLines(source) {
var _a;
/**

@@ -118,3 +117,3 @@ * The negative lookbehind here and in the `re` RegExp is to

match = last.exec(source);
return res + sep + ((_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : '');
return res + sep + (match?.[1] ?? '');
}

@@ -121,0 +120,0 @@ function doubleQuotedValue(source, onError) {

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

if (found)
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow !== null && flow !== void 0 ? flow : 'collection'}`);
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
found = token;

@@ -133,3 +133,3 @@ atNewline = false;

end,
start: start !== null && start !== void 0 ? start : end
start: start ?? end
};

@@ -136,0 +136,0 @@ }

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

st = before[++i];
while ((st === null || st === void 0 ? void 0 : st.type) === 'space') {
while (st?.type === 'space') {
offset += st.source.length;

@@ -22,0 +22,0 @@ st = before[++i];

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

function flowIndentCheck(indent, fc, onError) {
if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
if (fc?.type === 'flow-collection') {
const end = fc.end[0];

@@ -9,0 +9,0 @@ if (end.indent === indent &&

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

anchor: string | null;
node: Node | null;
node: Node<unknown> | null;
}>;
};

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

function findTagObject(value, tagName, tags) {
var _a;
if (tagName) {
const match = tags.filter(t => t.tag === tagName);
const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
const tagObj = match.find(t => !t.format) ?? match[0];
if (!tagObj)

@@ -18,6 +17,5 @@ throw new Error(`Tag ${tagName} not found`);

}
return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
return tags.find(t => t.identify?.(value) && !t.format);
}
function createNode(value, tagName, ctx) {
var _a, _b;
if (Node.isDocument(value))

@@ -28,3 +26,3 @@ value = value.contents;

if (Node.isPair(value)) {
const map = (_b = (_a = ctx.schema[Node.MAP]).createNode) === null || _b === void 0 ? void 0 : _b.call(_a, ctx.schema, null, ctx);
const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx);
map.items.push(value);

@@ -57,3 +55,3 @@ return map;

}
if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
if (tagName?.startsWith('!!'))
tagName = defaultTagPrefix + tagName.slice(2);

@@ -83,3 +81,3 @@ let tagObj = findTagObject(value, tagName, schema.tags);

}
const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
const node = tagObj?.createNode
? tagObj.createNode(ctx.schema, value, ctx)

@@ -86,0 +84,0 @@ : new Scalar.Scalar(value);

import type { YAMLError, YAMLWarning } from '../errors.js';
import { Alias } from '../nodes/Alias.js';
import { Node, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
import { Pair } from '../nodes/Pair.js';

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

}
export declare class Document<T = unknown> {
export declare class Document<T extends Node = Node> {
readonly [NODE_TYPE]: symbol;

@@ -30,3 +30,3 @@ /** A comment before this Document */

errors: YAMLError[];
options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
options: Required<Omit<ParseOptions & DocumentOptions, '_directives' | 'lineCounter' | 'version'>>;
/**

@@ -73,4 +73,4 @@ * The `[start, value-end, node-end]` character offsets for the part of the

*/
createNode(value: unknown, options?: CreateNodeOptions): Node;
createNode(value: unknown, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): Node;
createNode<T = unknown>(value: T, options?: CreateNodeOptions): NodeType<T>;
createNode<T = unknown>(value: T, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): NodeType<T>;
/**

@@ -85,3 +85,3 @@ * Convert a key and a value into a `Pair` using the current schema,

*/
delete(key: any): boolean;
delete(key: unknown): boolean;
/**

@@ -91,3 +91,3 @@ * Removes a value from the document.

*/
deleteIn(path: Iterable<unknown>): boolean;
deleteIn(path: Iterable<unknown> | null): boolean;
/**

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

*/
getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
getIn(path: Iterable<unknown> | null, keepScalar?: boolean): unknown;
/**

@@ -113,3 +113,3 @@ * Checks if the document includes a value with the key `key`.

*/
hasIn(path: Iterable<unknown>): boolean;
hasIn(path: Iterable<unknown> | null): boolean;
/**

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

*/
setIn(path: Iterable<unknown>, value: unknown): void;
setIn(path: Iterable<unknown> | null, value: unknown): void;
/**

@@ -127,0 +127,0 @@ * Change the YAML version and schema used by the document.

@@ -46,4 +46,4 @@ 'use strict';

let { version } = opt;
if (options === null || options === void 0 ? void 0 : options.directives) {
this.directives = options.directives.atDocument();
if (options?._directives) {
this.directives = options._directives.atDocument();
if (this.directives.yaml.explicit)

@@ -130,3 +130,3 @@ version = this.directives.yaml.version;

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

@@ -136,4 +136,4 @@ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing

const ctx = {
aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
aliasDuplicateObjects: aliasDuplicateObjects ?? true,
keepUndefined: keepUndefined ?? false,
onAnchor,

@@ -302,3 +302,3 @@ onTagObj,

};
const res = toJS.toJS(this.contents, jsonArg !== null && jsonArg !== void 0 ? jsonArg : '', ctx);
const res = toJS.toJS(this.contents, jsonArg ?? '', ctx);
if (typeof onAnchor === 'function')

@@ -305,0 +305,0 @@ for (const { count, res } of ctx.anchors.values())

@@ -19,2 +19,4 @@ export { Composer } from './compose/composer.js';

export type { CollectionTag, ScalarTag } from './schema/types';
export type { YAMLOMap } from './schema/yaml-1.1/omap';
export type { YAMLSet } from './schema/yaml-1.1/set';
export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';

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

function addPairToJSMap(ctx, map, { key, value }) {
if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
if (ctx?.doc.schema.merge && isMergeKey(key)) {
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;

@@ -14,0 +14,0 @@ if (Node.isSeq(value))

import type { Schema } from '../schema/Schema.js';
import { NodeBase, NODE_TYPE } from './Node.js';
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node;
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => boolean;
export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node<unknown>;
export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
export declare abstract class Collection extends NodeBase {

@@ -6,0 +6,0 @@ static maxFlowStringSingleLineLength: number;

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

}
// null, undefined, or an empty non-string iterable (e.g. [])
// Type guard is intentionally a little wrong so as to be more useful,
// as it does not cover untypable empty non-string iterables (e.g. []).
const isEmptyPath = (path) => path == null ||

@@ -32,0 +33,0 @@ (typeof path === 'object' && !!path[Symbol.iterator]().next().done);

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

import type { YAMLSeq } from './YAMLSeq.js';
export declare type Node = Alias | Scalar | YAMLMap | YAMLSeq;
export declare type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
/** Utility type mapper */
export declare type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
[key: string | number]: any;
} ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
export declare type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
export declare type Range = [number, number, number];
export declare type Range = [start: number, valueEnd: number, nodeEnd: number];
export declare const ALIAS: unique symbol;

@@ -21,10 +25,10 @@ export declare const DOC: unique symbol;

export declare const isAlias: (node: any) => node is Alias;
export declare const isDocument: (node: any) => node is Document<unknown>;
export declare const isMap: (node: any) => node is YAMLMap<unknown, unknown>;
export declare const isPair: (node: any) => node is Pair<unknown, unknown>;
export declare const isScalar: (node: any) => node is Scalar<unknown>;
export declare const isSeq: (node: any) => node is YAMLSeq<unknown>;
export declare function isCollection(node: any): node is YAMLMap | YAMLSeq;
export declare function isNode(node: any): node is Node;
export declare const hasAnchor: (node: unknown) => node is Scalar<unknown> | YAMLMap<unknown, unknown> | YAMLSeq<unknown>;
export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
export declare function isNode<T = unknown>(node: any): node is Node<T>;
export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
export declare abstract class NodeBase {

@@ -31,0 +35,0 @@ readonly [NODE_TYPE]: symbol;

@@ -8,3 +8,3 @@ import { CreateNodeContext } from '../doc/createNode.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>>;
export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node<unknown>, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
export declare class Pair<K = unknown, V = unknown> {

@@ -11,0 +11,0 @@ readonly [NODE_TYPE]: symbol;

@@ -28,7 +28,7 @@ 'use strict';

toJSON(_, ctx) {
const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
const pair = ctx?.mapAsMap ? new Map() : {};
return addPairToJSMap.addPairToJSMap(ctx, pair, this);
}
toString(ctx, onComment, onChompKeep) {
return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
return ctx?.doc
? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)

@@ -35,0 +35,0 @@ : JSON.stringify(this);

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

toJSON(arg, ctx) {
return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS.toJS(this.value, arg, ctx);
return ctx?.keep ? this.value : toJS.toJS(this.value, arg, ctx);
}

@@ -16,0 +16,0 @@ toString() {

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

}
if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
if (typeof value === 'bigint' && !ctx?.keep)
return Number(value);

@@ -37,0 +37,0 @@ return value;

@@ -7,2 +7,3 @@ import type { BlockMap, FlowCollection } from '../parse/cst.js';

import { Pair } from './Pair.js';
import { Scalar } from './Scalar.js';
import type { ToJSContext } from './toJS.js';

@@ -31,5 +32,7 @@ export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;

}, overwrite?: boolean): void;
delete(key: K): boolean;
get(key: K, keepScalar?: boolean): unknown;
has(key: K): boolean;
delete(key: unknown): boolean;
get(key: unknown, keepScalar: true): Scalar<V> | undefined;
get(key: unknown, keepScalar?: false): V | undefined;
get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
has(key: unknown): boolean;
set(key: K, value: V): void;

@@ -36,0 +39,0 @@ /**

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

add(pair, overwrite) {
var _a;
let _pair;

@@ -44,3 +43,3 @@ if (Node.isPair(pair))

// In TypeScript, this never happens.
_pair = new Pair.Pair(pair, pair.value);
_pair = new Pair.Pair(pair, pair?.value);
}

@@ -50,3 +49,3 @@ else

const prev = findPair(this.items, _pair.key);
const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
const sortEntries = this.schema?.sortMapEntries;
if (prev) {

@@ -81,4 +80,4 @@ if (!overwrite)

const it = findPair(this.items, key);
const node = it === null || it === void 0 ? void 0 : it.value;
return !keepScalar && Node.isScalar(node) ? node.value : node;
const node = it?.value;
return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
}

@@ -97,4 +96,4 @@ has(key) {

toJSON(_, ctx, Type) {
const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
if (ctx?.onCreate)
ctx.onCreate(map);

@@ -101,0 +100,0 @@ for (const item of this.items)

@@ -7,2 +7,3 @@ import type { BlockSequence, FlowCollection } from '../parse/cst.js';

import type { Pair } from './Pair.js';
import { Scalar } from './Scalar.js';
import { ToJSContext } from './toJS.js';

@@ -38,3 +39,5 @@ export declare namespace YAMLSeq {

*/
get(key: unknown, keepScalar?: boolean): unknown;
get(key: unknown, keepScalar: true): Scalar<T> | undefined;
get(key: unknown, keepScalar?: false): T | undefined;
get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
/**

@@ -41,0 +44,0 @@ * Checks if the collection includes a value with the key `key`.

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

}
/**
* Returns item at `key`, or `undefined` if not found. By default unwraps
* scalar values from their surrounding node; to disable set `keepScalar` to
* `true` (collections are always returned intact).
*
* `key` must contain a representation of an integer for this to succeed.
* It may be wrapped in a `Scalar`.
*/
get(key, keepScalar) {

@@ -80,3 +72,3 @@ const idx = asItemIndex(key);

const seq = [];
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
if (ctx?.onCreate)
ctx.onCreate(seq);

@@ -83,0 +75,0 @@ let i = 0;

@@ -61,6 +61,7 @@ import type { Reviver } from './doc/applyReviver.js';

/**
* @internal
* Used internally by Composer. If set and includes an explicit version,
* that overrides the `version` option.
*/
directives?: Directives;
_directives?: Directives;
/**

@@ -67,0 +68,0 @@ * Control the logging level during parsing

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

function createScalarToken(value, context) {
var _a;
const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;

@@ -52,3 +51,3 @@ const source = stringifyString.stringifyString({ type, value }, {

});
const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
const end = context.end ?? [
{ type: 'newline', offset: -1, indent, source: '\n' }

@@ -55,0 +54,0 @@ ];

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

for (const [field, index] of path) {
const tok = item === null || item === void 0 ? void 0 : item[field];
const tok = item?.[field];
if (tok && 'items' in tok) {

@@ -70,3 +70,3 @@ item = tok.items[index];

const field = path[path.length - 1][0];
const coll = parent === null || parent === void 0 ? void 0 : parent[field];
const coll = parent?.[field];
if (coll && 'items' in coll)

@@ -73,0 +73,0 @@ return coll;

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

*lex(source, incomplete = false) {
var _a;
if (source) {

@@ -160,3 +159,3 @@ this.buffer = this.buffer ? this.buffer + source : source;

this.atEnd = !incomplete;
let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
let next = this.next ?? 'stream';
while (next && (incomplete || this.hasChars(1)))

@@ -163,0 +162,0 @@ next = yield* this.parseNext(next);

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

function isFlowToken(token) {
switch (token === null || token === void 0 ? void 0 : token.type) {
switch (token?.type) {
case 'alias':

@@ -39,3 +39,2 @@ case 'scalar':

function getPrevProps(parent) {
var _a;
switch (parent.type) {

@@ -46,3 +45,3 @@ case 'document':

const it = parent.items[parent.items.length - 1];
return (_a = it.sep) !== null && _a !== void 0 ? _a : it.start;
return it.sep ?? it.start;
}

@@ -58,3 +57,2 @@ case 'block-seq':

function getFirstKeyStartProps(prev) {
var _a;
if (prev.length === 0)

@@ -73,3 +71,3 @@ return [];

}
while (((_a = prev[++i]) === null || _a === void 0 ? void 0 : _a.type) === 'space') {
while (prev[++i]?.type === 'space') {
/* loop */

@@ -278,3 +276,3 @@ }

*pop(error) {
const token = error !== null && error !== void 0 ? error : this.stack.pop();
const token = error ?? this.stack.pop();
/* istanbul ignore if should not happen */

@@ -484,3 +482,2 @@ if (!token) {

*blockMap(map) {
var _a;
const it = map.items[map.items.length - 1];

@@ -494,4 +491,4 @@ // it.sep is true-ish if pair already has key or : separator

const last = Array.isArray(end) ? end[end.length - 1] : undefined;
if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
if (last?.type === 'comment')
end?.push(this.sourceToken);
else

@@ -518,3 +515,3 @@ map.items.push({ start: [this.sourceToken] });

const prev = map.items[map.items.length - 2];
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
const end = prev?.value?.end;
if (Array.isArray(end)) {

@@ -696,3 +693,2 @@ Array.prototype.push.apply(end, it.start);

*blockSequence(seq) {
var _a;
const it = seq.items[seq.items.length - 1];

@@ -704,4 +700,4 @@ switch (this.type) {

const last = Array.isArray(end) ? end[end.length - 1] : undefined;
if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
if (last?.type === 'comment')
end?.push(this.sourceToken);
else

@@ -720,3 +716,3 @@ seq.items.push({ start: [this.sourceToken] });

const prev = seq.items[seq.items.length - 2];
const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
const end = prev?.value?.end;
if (Array.isArray(end)) {

@@ -723,0 +719,0 @@ Array.prototype.push.apply(end, it.start);

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

const { lineCounter, prettyErrors } = parseOptions(options);
const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
const composer$1 = new composer.Composer(options);

@@ -42,3 +42,3 @@ const docs = Array.from(composer$1.compose(parser$1.parse(source)));

const { lineCounter, prettyErrors } = parseOptions(options);
const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
const parser$1 = new parser.Parser(lineCounter?.addNewLine);
const composer$1 = new composer.Composer(options);

@@ -82,3 +82,2 @@ // `doc` is always set by compose.end(true) at the very latest

function stringify(value, replacer, options) {
var _a;
let _replacer = null;

@@ -98,3 +97,3 @@ if (typeof replacer === 'function' || Array.isArray(replacer)) {

if (value === undefined) {
const { keepUndefined } = (_a = options !== null && options !== void 0 ? options : replacer) !== null && _a !== void 0 ? _a : {};
const { keepUndefined } = options ?? replacer ?? {};
if (!keepUndefined)

@@ -101,0 +100,0 @@ return undefined;

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

this.tags = tags.getTags(customTags, this.name);
this.toStringOptions = toStringDefaults !== null && toStringDefaults !== void 0 ? toStringDefaults : null;
this.toStringOptions = toStringDefaults ?? null;
Object.defineProperty(this, Node.MAP, { value: map.map });

@@ -24,0 +24,0 @@ Object.defineProperty(this, Node.SCALAR, { value: string.string });

@@ -11,5 +11,9 @@ import { YAMLSeq } from '../../nodes/YAMLSeq.js';

}, overwrite?: boolean | undefined) => void;
delete: (key: any) => boolean;
get: (key: any, keepScalar?: boolean | undefined) => unknown;
has: (key: any) => boolean;
delete: (key: unknown) => boolean;
get: {
(key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
(key: unknown, keepScalar?: false | undefined): any;
(key: unknown, keepScalar?: boolean | undefined): any;
};
has: (key: unknown) => boolean;
set: (key: any, value: any) => void;

@@ -16,0 +20,0 @@ /**

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

const map = new Map();
if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
if (ctx?.onCreate)
ctx.onCreate(map);

@@ -30,0 +30,0 @@ for (const pair of this.items) {

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

function resolvePairs(seq, onError) {
var _a;
if (Node.isSeq(seq)) {

@@ -25,3 +24,3 @@ for (let i = 0; i < seq.items.length; ++i) {

if (item.comment) {
const cn = (_a = pair.value) !== null && _a !== void 0 ? _a : pair.key;
const cn = pair.value ?? pair.key;
cn.comment = cn.comment

@@ -28,0 +27,0 @@ ? `${item.comment}\n${cn.comment}`

@@ -15,5 +15,9 @@ import type { Schema } from '../../schema/Schema.js';

}): void;
get(key?: T, keepPair?: boolean): unknown;
/**
* If `keepPair` is `true`, returns the Pair matching `key`.
* Otherwise, returns the value of that Pair's key.
*/
get(key: unknown, keepPair?: boolean): any;
set(key: T, value: boolean): void;
/** Will throw; `value` must be boolean */
/** @deprecated Will throw; `value` must be boolean */
set(key: T, value: null): void;

@@ -20,0 +24,0 @@ toJSON(_?: unknown, ctx?: ToJSContext): any;

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

}
/**
* If `keepPair` is `true`, returns the Pair matching `key`.
* Otherwise, returns the value of that Pair's key.
*/
get(key, keepPair) {

@@ -29,0 +33,0 @@ const pair = YAMLMap.findPair(this.items, key);

@@ -48,7 +48,6 @@ 'use strict';

function getTagObject(tags, item) {
var _a, _b, _c, _d;
if (item.tag) {
const match = tags.filter(t => t.tag === item.tag);
if (match.length > 0)
return (_a = match.find(t => t.format === item.format)) !== null && _a !== void 0 ? _a : match[0];
return match.find(t => t.format === item.format) ?? match[0];
}

@@ -59,5 +58,5 @@ let tagObj = undefined;

obj = item.value;
const match = tags.filter(t => { var _a; return (_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, obj); });
const match = tags.filter(t => t.identify?.(obj));
tagObj =
(_b = match.find(t => t.format === item.format)) !== null && _b !== void 0 ? _b : match.find(t => !t.format);
match.find(t => t.format === item.format) ?? match.find(t => !t.format);
}

@@ -69,3 +68,3 @@ else {

if (!tagObj) {
const name = (_d = (_c = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : typeof obj;
const name = obj?.constructor?.name ?? typeof obj;
throw new Error(`Tag not resolved for ${name} value`);

@@ -91,3 +90,2 @@ }

function stringify(item, ctx, onComment, onChompKeep) {
var _a, _b;
if (Node.isPair(item))

@@ -98,3 +96,3 @@ return item.toString(ctx, onComment, onChompKeep);

return item.toString(ctx);
if ((_a = ctx.resolvedAliases) === null || _a === void 0 ? void 0 : _a.has(item)) {
if (ctx.resolvedAliases?.has(item)) {
throw new TypeError(`Cannot stringify circular structure without alias nodes`);

@@ -118,3 +116,3 @@ }

if (props.length > 0)
ctx.indentAtStart = ((_b = ctx.indentAtStart) !== null && _b !== void 0 ? _b : 0) + props.length + 1;
ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
const str = typeof tagObj.stringify === 'function'

@@ -121,0 +119,0 @@ ? tagObj.stringify(node, ctx, onComment, onChompKeep)

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

function stringifyCollection(collection, ctx, options) {
var _a;
const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
const flow = ctx.inFlow ?? collection.flow;
const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;

@@ -13,0 +12,0 @@ return stringify(collection, ctx, options);

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

function stringifyDocument(doc, options) {
var _a;
const lines = [];

@@ -61,3 +60,3 @@ let hasDirectives = options.directives === true;

}
if ((_a = doc.directives) === null || _a === void 0 ? void 0 : _a.docEnd) {
if (doc.directives?.docEnd) {
if (doc.comment) {

@@ -64,0 +63,0 @@ const cs = commentString(doc.comment);

@@ -268,5 +268,5 @@ 'use strict';

if (actualString) {
const test = (tag) => { var _a; return tag.default && tag.tag !== 'tag:yaml.org,2002:str' && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)); };
const test = (tag) => tag.default && tag.tag !== 'tag:yaml.org,2002:str' && tag.test?.test(str);
const { compat, tags } = ctx.doc.schema;
if (tags.some(test) || (compat === null || compat === void 0 ? void 0 : compat.some(test)))
if (tags.some(test) || compat?.some(test))
return quotedString(value, ctx);

@@ -273,0 +273,0 @@ }

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

function testEvents(src) {
var _a;
const docs = publicApi.parseAllDocuments(src);

@@ -53,3 +52,3 @@ const errDoc = docs.find(doc => doc.errors.length > 0);

events.push(docStart);
addEvents(events, doc, (_a = error === null || error === void 0 ? void 0 : error.pos[0]) !== null && _a !== void 0 ? _a : -1, root);
addEvents(events, doc, error?.pos[0] ?? -1, root);
let docEnd = '-DOC';

@@ -62,3 +61,3 @@ if (doc.directives.docEnd)

catch (e) {
return { events, error: error !== null && error !== void 0 ? error : e };
return { events, error: error ?? e };
}

@@ -65,0 +64,0 @@ events.push('-STR');

@@ -201,15 +201,14 @@ 'use strict';

function callVisitor(key, node, visitor, path) {
var _a, _b, _c, _d, _e;
if (typeof visitor === 'function')
return visitor(key, node, path);
if (Node.isMap(node))
return (_a = visitor.Map) === null || _a === void 0 ? void 0 : _a.call(visitor, key, node, path);
return visitor.Map?.(key, node, path);
if (Node.isSeq(node))
return (_b = visitor.Seq) === null || _b === void 0 ? void 0 : _b.call(visitor, key, node, path);
return visitor.Seq?.(key, node, path);
if (Node.isPair(node))
return (_c = visitor.Pair) === null || _c === void 0 ? void 0 : _c.call(visitor, key, node, path);
return visitor.Pair?.(key, node, path);
if (Node.isScalar(node))
return (_d = visitor.Scalar) === null || _d === void 0 ? void 0 : _d.call(visitor, key, node, path);
return visitor.Scalar?.(key, node, path);
if (Node.isAlias(node))
return (_e = visitor.Alias) === null || _e === void 0 ? void 0 : _e.call(visitor, key, node, path);
return visitor.Alias?.(key, node, path);
return undefined;

@@ -216,0 +215,0 @@ }

{
"name": "yaml",
"version": "2.0.1",
"version": "2.1.0",
"license": "ISC",

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

"@typescript-eslint/parser": "^5.3.1",
"babel-jest": "^27.0.1",
"babel-jest": "^28.1.0",
"cross-env": "^7.0.3",

@@ -85,3 +85,3 @@ "eslint": "^8.2.0",

"fast-check": "^2.12.0",
"jest": "^27.0.1",
"jest": "^28.1.0",
"jest-ts-webcompat-resolver": "^1.0.0",

@@ -88,0 +88,0 @@ "prettier": "^2.2.1",

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc