Comparing version 2.3.0-0 to 2.3.0-1
@@ -1,2 +0,2 @@ | ||
import { isNode, isMap } from '../nodes/Node.js'; | ||
import { isNode, isMap } from '../nodes/identity.js'; | ||
import { Scalar } from '../nodes/Scalar.js'; | ||
@@ -3,0 +3,0 @@ import { resolveBlockMap } from './resolve-block-map.js'; |
@@ -1,2 +0,2 @@ | ||
import { SCALAR, isScalar } from '../nodes/Node.js'; | ||
import { SCALAR, isScalar } from '../nodes/identity.js'; | ||
import { Scalar } from '../nodes/Scalar.js'; | ||
@@ -3,0 +3,0 @@ import { resolveBlockScalar } from './resolve-block-scalar.js'; |
import { Directives } from '../doc/directives.js'; | ||
import { Document } from '../doc/Document.js'; | ||
import { YAMLWarning, YAMLParseError } from '../errors.js'; | ||
import { isCollection, isPair } from '../nodes/Node.js'; | ||
import { isCollection, isPair } from '../nodes/identity.js'; | ||
import { composeDoc } from './compose-doc.js'; | ||
@@ -6,0 +6,0 @@ import { resolveEnd } from './resolve-end.js'; |
@@ -1,2 +0,2 @@ | ||
import { isPair } from '../nodes/Node.js'; | ||
import { isPair } from '../nodes/identity.js'; | ||
import { Pair } from '../nodes/Pair.js'; | ||
@@ -3,0 +3,0 @@ import { YAMLMap } from '../nodes/YAMLMap.js'; |
@@ -1,2 +0,2 @@ | ||
import { isScalar } from '../nodes/Node.js'; | ||
import { isScalar } from '../nodes/identity.js'; | ||
@@ -3,0 +3,0 @@ function mapIncludes(ctx, items, search) { |
@@ -1,2 +0,2 @@ | ||
import { isScalar, isCollection } from '../nodes/Node.js'; | ||
import { isScalar, isCollection } from '../nodes/identity.js'; | ||
import { visit } from '../visit.js'; | ||
@@ -3,0 +3,0 @@ |
import { Alias } from '../nodes/Alias.js'; | ||
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js'; | ||
import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js'; | ||
import { Scalar } from '../nodes/Scalar.js'; | ||
@@ -4,0 +4,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { isNode } from '../nodes/Node.js'; | ||
import { isNode } from '../nodes/identity.js'; | ||
import { visit } from '../visit.js'; | ||
@@ -3,0 +3,0 @@ |
import { Alias } from '../nodes/Alias.js'; | ||
import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js'; | ||
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/Node.js'; | ||
import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/identity.js'; | ||
import { Pair } from '../nodes/Pair.js'; | ||
import { toJS } from '../nodes/toJS.js'; | ||
import { Schema } from '../schema/Schema.js'; | ||
import { stringify } from '../stringify/stringify.js'; | ||
import { stringifyDocument } from '../stringify/stringifyDocument.js'; | ||
@@ -298,4 +297,3 @@ import { anchorNames, findNewAnchor, createNodeAnchors } from './anchors.js'; | ||
mapKeyWarned: false, | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100, | ||
stringify | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 | ||
}; | ||
@@ -302,0 +300,0 @@ const res = toJS(this.contents, jsonArg ?? '', ctx); |
@@ -6,3 +6,3 @@ export { Composer } from './compose/composer.js'; | ||
export { Alias } from './nodes/Alias.js'; | ||
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/Node.js'; | ||
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js'; | ||
export { Pair } from './nodes/Pair.js'; | ||
@@ -9,0 +9,0 @@ export { Scalar } from './nodes/Scalar.js'; |
import { warn } from '../log.js'; | ||
import { createStringifyContext } from '../stringify/stringify.js'; | ||
import { isAlias, isSeq, isScalar, isMap, isNode } from './Node.js'; | ||
import { isAlias, isSeq, isScalar, isMap, isNode } from './identity.js'; | ||
import { Scalar } from './Scalar.js'; | ||
@@ -5,0 +5,0 @@ import { toJS } from './toJS.js'; |
import { anchorIsValid } from '../doc/anchors.js'; | ||
import { visit } from '../visit.js'; | ||
import { NodeBase, ALIAS, isAlias, isCollection, isPair } from './Node.js'; | ||
import { ALIAS, isAlias, isCollection, isPair } from './identity.js'; | ||
import { NodeBase } from './Node.js'; | ||
import { toJS } from './toJS.js'; | ||
@@ -40,3 +42,8 @@ class Alias extends NodeBase { | ||
} | ||
const data = anchors.get(source); | ||
let data = anchors.get(source); | ||
if (!data) { | ||
// Resolve anchors for Node.prototype.toJS() | ||
toJS(source, null, ctx); | ||
data = anchors.get(source); | ||
} | ||
/* istanbul ignore if */ | ||
@@ -43,0 +50,0 @@ if (!data || data.res === undefined) { |
import { createNode } from '../doc/createNode.js'; | ||
import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js'; | ||
import { isNode, isPair, isCollection, isScalar } from './identity.js'; | ||
import { NodeBase } from './Node.js'; | ||
@@ -4,0 +5,0 @@ function collectionFromPath(schema, path, value) { |
@@ -1,35 +0,5 @@ | ||
const ALIAS = Symbol.for('yaml.alias'); | ||
const DOC = Symbol.for('yaml.document'); | ||
const MAP = Symbol.for('yaml.map'); | ||
const PAIR = Symbol.for('yaml.pair'); | ||
const SCALAR = Symbol.for('yaml.scalar'); | ||
const SEQ = Symbol.for('yaml.seq'); | ||
const NODE_TYPE = Symbol.for('yaml.node.type'); | ||
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS; | ||
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC; | ||
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP; | ||
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR; | ||
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR; | ||
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ; | ||
function isCollection(node) { | ||
if (node && typeof node === 'object') | ||
switch (node[NODE_TYPE]) { | ||
case MAP: | ||
case SEQ: | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isNode(node) { | ||
if (node && typeof node === 'object') | ||
switch (node[NODE_TYPE]) { | ||
case ALIAS: | ||
case MAP: | ||
case SCALAR: | ||
case SEQ: | ||
return true; | ||
} | ||
return false; | ||
} | ||
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor; | ||
import { applyReviver } from '../doc/applyReviver.js'; | ||
import { NODE_TYPE } from './identity.js'; | ||
import { toJS } from './toJS.js'; | ||
class NodeBase { | ||
@@ -46,4 +16,22 @@ constructor(type) { | ||
} | ||
/** A plain JavaScript representation of this node. */ | ||
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) { | ||
const ctx = { | ||
anchors: new Map(), | ||
doc, | ||
keep: true, | ||
mapAsMap: mapAsMap === true, | ||
mapKeyWarned: false, | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 | ||
}; | ||
const res = toJS(this, '', ctx); | ||
if (typeof onAnchor === 'function') | ||
for (const { count, res } of ctx.anchors.values()) | ||
onAnchor(res, count); | ||
return typeof reviver === 'function' | ||
? applyReviver(reviver, { '': res }, '', res) | ||
: res; | ||
} | ||
} | ||
export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq }; | ||
export { NodeBase }; |
import { createNode } from '../doc/createNode.js'; | ||
import { stringifyPair } from '../stringify/stringifyPair.js'; | ||
import { addPairToJSMap } from './addPairToJSMap.js'; | ||
import { NODE_TYPE, PAIR, isNode } from './Node.js'; | ||
import { NODE_TYPE, PAIR, isNode } from './identity.js'; | ||
@@ -6,0 +6,0 @@ function createPair(key, value, ctx) { |
@@ -1,2 +0,3 @@ | ||
import { NodeBase, SCALAR } from './Node.js'; | ||
import { SCALAR } from './identity.js'; | ||
import { NodeBase } from './Node.js'; | ||
import { toJS } from './toJS.js'; | ||
@@ -3,0 +4,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { hasAnchor } from './Node.js'; | ||
import { hasAnchor } from './identity.js'; | ||
@@ -3,0 +3,0 @@ /** |
import { stringifyCollection } from '../stringify/stringifyCollection.js'; | ||
import { addPairToJSMap } from './addPairToJSMap.js'; | ||
import { Collection } from './Collection.js'; | ||
import { isPair, isScalar, MAP } from './Node.js'; | ||
import { isPair, isScalar, MAP } from './identity.js'; | ||
import { Pair } from './Pair.js'; | ||
@@ -6,0 +6,0 @@ import { isScalarValue } from './Scalar.js'; |
import { stringifyCollection } from '../stringify/stringifyCollection.js'; | ||
import { Collection } from './Collection.js'; | ||
import { SEQ, isScalar } from './Node.js'; | ||
import { SEQ, isScalar } from './identity.js'; | ||
import { isScalarValue } from './Scalar.js'; | ||
@@ -5,0 +5,0 @@ import { toJS } from './toJS.js'; |
@@ -1,2 +0,2 @@ | ||
import { isMap } from '../../nodes/Node.js'; | ||
import { isMap } from '../../nodes/identity.js'; | ||
import { createPair } from '../../nodes/Pair.js'; | ||
@@ -3,0 +3,0 @@ import { YAMLMap } from '../../nodes/YAMLMap.js'; |
import { createNode } from '../../doc/createNode.js'; | ||
import { isSeq } from '../../nodes/Node.js'; | ||
import { isSeq } from '../../nodes/identity.js'; | ||
import { YAMLSeq } from '../../nodes/YAMLSeq.js'; | ||
@@ -4,0 +4,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { MAP, SCALAR, SEQ } from '../nodes/Node.js'; | ||
import { MAP, SCALAR, SEQ } from '../nodes/identity.js'; | ||
import { map } from './common/map.js'; | ||
@@ -3,0 +3,0 @@ import { seq } from './common/seq.js'; |
@@ -1,5 +0,5 @@ | ||
import { YAMLSeq } from '../../nodes/YAMLSeq.js'; | ||
import { isScalar, isPair } from '../../nodes/identity.js'; | ||
import { toJS } from '../../nodes/toJS.js'; | ||
import { isScalar, isPair } from '../../nodes/Node.js'; | ||
import { YAMLMap } from '../../nodes/YAMLMap.js'; | ||
import { YAMLSeq } from '../../nodes/YAMLSeq.js'; | ||
import { resolvePairs, createPairs } from './pairs.js'; | ||
@@ -6,0 +6,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { isSeq, isPair, isMap } from '../../nodes/Node.js'; | ||
import { isSeq, isPair, isMap } from '../../nodes/identity.js'; | ||
import { Pair, createPair } from '../../nodes/Pair.js'; | ||
@@ -3,0 +3,0 @@ import { Scalar } from '../../nodes/Scalar.js'; |
@@ -1,2 +0,2 @@ | ||
import { isMap, isPair, isScalar } from '../../nodes/Node.js'; | ||
import { isMap, isPair, isScalar } from '../../nodes/identity.js'; | ||
import { createPair, Pair } from '../../nodes/Pair.js'; | ||
@@ -3,0 +3,0 @@ import { YAMLMap, findPair } from '../../nodes/YAMLMap.js'; |
import { anchorIsValid } from '../doc/anchors.js'; | ||
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/Node.js'; | ||
import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js'; | ||
import { stringifyComment } from './stringifyComment.js'; | ||
@@ -4,0 +4,0 @@ import { stringifyString } from './stringifyString.js'; |
import { Collection } from '../nodes/Collection.js'; | ||
import { isNode, isPair } from '../nodes/Node.js'; | ||
import { isNode, isPair } from '../nodes/identity.js'; | ||
import { stringify } from './stringify.js'; | ||
@@ -4,0 +4,0 @@ import { lineComment, indentComment } from './stringifyComment.js'; |
@@ -1,2 +0,2 @@ | ||
import { isNode } from '../nodes/Node.js'; | ||
import { isNode } from '../nodes/identity.js'; | ||
import { createStringifyContext, stringify } from './stringify.js'; | ||
@@ -3,0 +3,0 @@ import { indentComment, lineComment } from './stringifyComment.js'; |
@@ -1,2 +0,2 @@ | ||
import { isCollection, isNode, isScalar, isSeq } from '../nodes/Node.js'; | ||
import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js'; | ||
import { Scalar } from '../nodes/Scalar.js'; | ||
@@ -3,0 +3,0 @@ import { stringify } from './stringify.js'; |
import { Scalar } from '../nodes/Scalar.js'; | ||
import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js'; | ||
const getFoldOptions = (ctx) => ({ | ||
indentAtStart: ctx.indentAtStart, | ||
const getFoldOptions = (ctx, isBlock) => ({ | ||
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart, | ||
lineWidth: ctx.options.lineWidth, | ||
@@ -118,3 +118,3 @@ minContentWidth: ctx.options.minContentWidth | ||
? str | ||
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx)); | ||
: foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false)); | ||
} | ||
@@ -131,3 +131,3 @@ function singleQuotedString(value, ctx) { | ||
? res | ||
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx)); | ||
: foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false)); | ||
} | ||
@@ -239,3 +239,3 @@ function quotedString(value, ctx) { | ||
.replace(/\n+/g, `$&${indent}`); | ||
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx)); | ||
const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true)); | ||
return `${header}\n${indent}${body}`; | ||
@@ -290,3 +290,3 @@ } | ||
? str | ||
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx)); | ||
: foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false)); | ||
} | ||
@@ -293,0 +293,0 @@ function stringifyString(item, ctx, onComment, onChompKeep) { |
@@ -0,2 +1,4 @@ | ||
export { createNode } from './doc/createNode.js'; | ||
export { debug, warn } from './log.js'; | ||
export { createPair } from './nodes/Pair.js'; | ||
export { findPair } from './nodes/YAMLMap.js'; | ||
@@ -3,0 +5,0 @@ export { toJS } from './nodes/toJS.js'; |
@@ -1,2 +0,2 @@ | ||
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js'; | ||
import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js'; | ||
@@ -3,0 +3,0 @@ const BREAK = Symbol('break visit'); |
@@ -1,2 +0,2 @@ | ||
import { ParsedNode } from '../nodes/Node.js'; | ||
import type { ParsedNode } from '../nodes/Node.js'; | ||
import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js'; | ||
@@ -3,0 +3,0 @@ import type { ComposeContext, ComposeNode } from './compose-node.js'; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Scalar = require('../nodes/Scalar.js'); | ||
@@ -36,3 +36,3 @@ var resolveBlockMap = require('./resolve-block-map.js'); | ||
} | ||
const expType = Node.isMap(coll) ? 'map' : 'seq'; | ||
const expType = identity.isMap(coll) ? 'map' : 'seq'; | ||
let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName); | ||
@@ -52,3 +52,3 @@ if (!tag) { | ||
const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options); | ||
const node = Node.isNode(res) | ||
const node = identity.isNode(res) | ||
? res | ||
@@ -55,0 +55,0 @@ : new Scalar.Scalar(res); |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Scalar = require('../nodes/Scalar.js'); | ||
@@ -19,7 +19,7 @@ var resolveBlockScalar = require('./resolve-block-scalar.js'); | ||
? findScalarTagByTest(ctx, value, token, onError) | ||
: ctx.schema[Node.SCALAR]; | ||
: ctx.schema[identity.SCALAR]; | ||
let scalar; | ||
try { | ||
const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options); | ||
scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res); | ||
scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res); | ||
} | ||
@@ -45,3 +45,3 @@ catch (error) { | ||
if (tagName === '!') | ||
return schema[Node.SCALAR]; // non-specific tag | ||
return schema[identity.SCALAR]; // non-specific tag | ||
const matchWithTest = []; | ||
@@ -67,9 +67,9 @@ for (const tag of schema.tags) { | ||
onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str'); | ||
return schema[Node.SCALAR]; | ||
return schema[identity.SCALAR]; | ||
} | ||
function findScalarTagByTest({ directives, schema }, value, token, onError) { | ||
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR]; | ||
const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR]; | ||
if (schema.compat) { | ||
const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ?? | ||
schema[Node.SCALAR]; | ||
schema[identity.SCALAR]; | ||
if (tag.tag !== compat.tag) { | ||
@@ -76,0 +76,0 @@ const ts = directives.tagString(tag.tag); |
import { Directives } from '../doc/directives.js'; | ||
import { Document } from '../doc/Document.js'; | ||
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js'; | ||
import { ParsedNode, Range } from '../nodes/Node.js'; | ||
import type { ParsedNode, Range } from '../nodes/Node.js'; | ||
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js'; | ||
@@ -6,0 +6,0 @@ import type { Token } from '../parse/cst.js'; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var errors = require('../errors.js'); | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var composeDoc = require('./compose-doc.js'); | ||
@@ -87,5 +87,5 @@ var resolveEnd = require('./resolve-end.js'); | ||
} | ||
else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) { | ||
else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) { | ||
let it = dc.items[0]; | ||
if (Node.isPair(it)) | ||
if (identity.isPair(it)) | ||
it = it.key; | ||
@@ -92,0 +92,0 @@ const cb = it.commentBefore; |
@@ -6,2 +6,2 @@ import { YAMLMap } from '../nodes/YAMLMap.js'; | ||
import type { ComposeErrorHandler } from './composer.js'; | ||
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>; | ||
export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null> | YAMLSeq.Parsed<import("../index.js").ParsedNode>; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Pair = require('../nodes/Pair.js'); | ||
@@ -78,3 +78,3 @@ var YAMLMap = require('../nodes/YAMLMap.js'); | ||
let prev = coll.items[coll.items.length - 1]; | ||
if (Node.isPair(prev)) | ||
if (identity.isPair(prev)) | ||
prev = prev.value ?? prev.key; | ||
@@ -81,0 +81,0 @@ if (prev.comment) |
@@ -1,4 +0,4 @@ | ||
import { ParsedNode } from '../nodes/Node'; | ||
import { Pair } from '../nodes/Pair'; | ||
import { ComposeContext } from './compose-node'; | ||
import type { ParsedNode } from '../nodes/Node.js'; | ||
import type { Pair } from '../nodes/Pair.js'; | ||
import type { ComposeContext } from './compose-node.js'; | ||
export declare function mapIncludes(ctx: ComposeContext, items: Pair<ParsedNode>[], search: ParsedNode): boolean; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
@@ -12,4 +12,4 @@ function mapIncludes(ctx, items, search) { | ||
: (a, b) => a === b || | ||
(Node.isScalar(a) && | ||
Node.isScalar(b) && | ||
(identity.isScalar(a) && | ||
identity.isScalar(b) && | ||
a.value === b.value && | ||
@@ -16,0 +16,0 @@ !(a.value === '<<' && ctx.schema.merge)); |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../nodes/Node.js'; | ||
import type { Node } from '../nodes/Node.js'; | ||
import type { Document } from './Document.js'; | ||
@@ -22,4 +22,4 @@ /** | ||
anchor: string | null; | ||
node: Node<unknown> | null; | ||
node: Node | null; | ||
}>; | ||
}; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var visit = require('../visit.js'); | ||
@@ -60,3 +60,3 @@ | ||
ref.anchor && | ||
(Node.isScalar(ref.node) || Node.isCollection(ref.node))) { | ||
(identity.isScalar(ref.node) || identity.isCollection(ref.node))) { | ||
ref.node.anchor = ref.anchor; | ||
@@ -63,0 +63,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Node } from '../nodes/Node.js'; | ||
import type { Node } from '../nodes/Node.js'; | ||
import type { Schema } from '../schema/Schema.js'; | ||
@@ -3,0 +3,0 @@ import type { CollectionTag, ScalarTag } from '../schema/types.js'; |
'use strict'; | ||
var Alias = require('../nodes/Alias.js'); | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Scalar = require('../nodes/Scalar.js'); | ||
@@ -19,8 +19,8 @@ | ||
function createNode(value, tagName, ctx) { | ||
if (Node.isDocument(value)) | ||
if (identity.isDocument(value)) | ||
value = value.contents; | ||
if (Node.isNode(value)) | ||
if (identity.isNode(value)) | ||
return value; | ||
if (Node.isPair(value)) { | ||
const map = ctx.schema[Node.MAP].createNode?.(ctx.schema, null, ctx); | ||
if (identity.isPair(value)) { | ||
const map = ctx.schema[identity.MAP].createNode?.(ctx.schema, null, ctx); | ||
map.items.push(value); | ||
@@ -69,6 +69,6 @@ return map; | ||
value instanceof Map | ||
? schema[Node.MAP] | ||
? schema[identity.MAP] | ||
: Symbol.iterator in Object(value) | ||
? schema[Node.SEQ] | ||
: schema[Node.MAP]; | ||
? schema[identity.SEQ] | ||
: schema[identity.MAP]; | ||
} | ||
@@ -75,0 +75,0 @@ if (onTagObj) { |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var visit = require('../visit.js'); | ||
@@ -149,6 +149,6 @@ | ||
let tagNames; | ||
if (doc && tagEntries.length > 0 && Node.isNode(doc.contents)) { | ||
if (doc && tagEntries.length > 0 && identity.isNode(doc.contents)) { | ||
const tags = {}; | ||
visit.visit(doc.contents, (_key, node) => { | ||
if (Node.isNode(node) && node.tag) | ||
if (identity.isNode(node) && node.tag) | ||
tags[node.tag] = true; | ||
@@ -155,0 +155,0 @@ }); |
import type { YAMLError, YAMLWarning } from '../errors.js'; | ||
import { Alias } from '../nodes/Alias.js'; | ||
import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js'; | ||
import { NODE_TYPE } from '../nodes/identity.js'; | ||
import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js'; | ||
import { Pair } from '../nodes/Pair.js'; | ||
@@ -5,0 +6,0 @@ import type { Scalar } from '../nodes/Scalar.js'; |
@@ -5,7 +5,6 @@ 'use strict'; | ||
var Collection = require('../nodes/Collection.js'); | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Pair = require('../nodes/Pair.js'); | ||
var toJS = require('../nodes/toJS.js'); | ||
var Schema = require('../schema/Schema.js'); | ||
var stringify = require('../stringify/stringify.js'); | ||
var stringifyDocument = require('../stringify/stringifyDocument.js'); | ||
@@ -27,3 +26,3 @@ var anchors = require('./anchors.js'); | ||
this.warnings = []; | ||
Object.defineProperty(this, Node.NODE_TYPE, { value: Node.DOC }); | ||
Object.defineProperty(this, identity.NODE_TYPE, { value: identity.DOC }); | ||
let _replacer = null; | ||
@@ -67,3 +66,3 @@ if (typeof replacer === 'function' || Array.isArray(replacer)) { | ||
const copy = Object.create(Document.prototype, { | ||
[Node.NODE_TYPE]: { value: Node.DOC } | ||
[identity.NODE_TYPE]: { value: identity.DOC } | ||
}); | ||
@@ -79,3 +78,3 @@ copy.commentBefore = this.commentBefore; | ||
// @ts-expect-error We can't really know that this matches Contents. | ||
copy.contents = Node.isNode(this.contents) | ||
copy.contents = identity.isNode(this.contents) | ||
? this.contents.clone(copy.schema) | ||
@@ -146,3 +145,3 @@ : this.contents; | ||
const node = createNode.createNode(value, tag, ctx); | ||
if (flow && Node.isCollection(node)) | ||
if (flow && identity.isCollection(node)) | ||
node.flow = true; | ||
@@ -190,3 +189,3 @@ setAnchors(); | ||
get(key, keepScalar) { | ||
return Node.isCollection(this.contents) | ||
return identity.isCollection(this.contents) | ||
? this.contents.get(key, keepScalar) | ||
@@ -202,6 +201,6 @@ : undefined; | ||
if (Collection.isEmptyPath(path)) | ||
return !keepScalar && Node.isScalar(this.contents) | ||
return !keepScalar && identity.isScalar(this.contents) | ||
? this.contents.value | ||
: this.contents; | ||
return Node.isCollection(this.contents) | ||
return identity.isCollection(this.contents) | ||
? this.contents.getIn(path, keepScalar) | ||
@@ -214,3 +213,3 @@ : undefined; | ||
has(key) { | ||
return Node.isCollection(this.contents) ? this.contents.has(key) : false; | ||
return identity.isCollection(this.contents) ? this.contents.has(key) : false; | ||
} | ||
@@ -223,3 +222,3 @@ /** | ||
return this.contents !== undefined; | ||
return Node.isCollection(this.contents) ? this.contents.hasIn(path) : false; | ||
return identity.isCollection(this.contents) ? this.contents.hasIn(path) : false; | ||
} | ||
@@ -309,4 +308,3 @@ /** | ||
mapKeyWarned: false, | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100, | ||
stringify: stringify.stringify | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 | ||
}; | ||
@@ -343,3 +341,3 @@ const res = toJS.toJS(this.contents, jsonArg ?? '', ctx); | ||
function assertCollection(contents) { | ||
if (Node.isCollection(contents)) | ||
if (identity.isCollection(contents)) | ||
return true; | ||
@@ -346,0 +344,0 @@ throw new Error('Expected a YAML collection as document contents'); |
@@ -6,3 +6,4 @@ export { Composer } from './compose/composer.js'; | ||
export { Alias } from './nodes/Alias.js'; | ||
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.js'; | ||
export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js'; | ||
export { Node, ParsedNode, Range } from './nodes/Node.js'; | ||
export { Pair } from './nodes/Pair.js'; | ||
@@ -9,0 +10,0 @@ export { Scalar } from './nodes/Scalar.js'; |
@@ -8,3 +8,3 @@ 'use strict'; | ||
var Alias = require('./nodes/Alias.js'); | ||
var Node = require('./nodes/Node.js'); | ||
var identity = require('./nodes/identity.js'); | ||
var Pair = require('./nodes/Pair.js'); | ||
@@ -30,10 +30,10 @@ var Scalar = require('./nodes/Scalar.js'); | ||
exports.Alias = Alias.Alias; | ||
exports.isAlias = Node.isAlias; | ||
exports.isCollection = Node.isCollection; | ||
exports.isDocument = Node.isDocument; | ||
exports.isMap = Node.isMap; | ||
exports.isNode = Node.isNode; | ||
exports.isPair = Node.isPair; | ||
exports.isScalar = Node.isScalar; | ||
exports.isSeq = Node.isSeq; | ||
exports.isAlias = identity.isAlias; | ||
exports.isCollection = identity.isCollection; | ||
exports.isDocument = identity.isDocument; | ||
exports.isMap = identity.isMap; | ||
exports.isNode = identity.isNode; | ||
exports.isPair = identity.isPair; | ||
exports.isScalar = identity.isScalar; | ||
exports.isSeq = identity.isSeq; | ||
exports.Pair = Pair.Pair; | ||
@@ -40,0 +40,0 @@ exports.Scalar = Scalar.Scalar; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var stringify = require('../stringify/stringify.js'); | ||
var Node = require('./Node.js'); | ||
var identity = require('./identity.js'); | ||
var Scalar = require('./Scalar.js'); | ||
@@ -13,4 +13,4 @@ var toJS = require('./toJS.js'); | ||
if (ctx?.doc.schema.merge && isMergeKey(key)) { | ||
value = Node.isAlias(value) ? value.resolve(ctx.doc) : value; | ||
if (Node.isSeq(value)) | ||
value = identity.isAlias(value) ? value.resolve(ctx.doc) : value; | ||
if (identity.isSeq(value)) | ||
for (const it of value.items) | ||
@@ -49,3 +49,3 @@ mergeToJSMap(ctx, map, it); | ||
const isMergeKey = (key) => key === MERGE_KEY || | ||
(Node.isScalar(key) && | ||
(identity.isScalar(key) && | ||
key.value === MERGE_KEY && | ||
@@ -61,4 +61,4 @@ (!key.type || key.type === Scalar.Scalar.PLAIN)); | ||
function mergeToJSMap(ctx, map, value) { | ||
const source = ctx && Node.isAlias(value) ? value.resolve(ctx.doc) : value; | ||
if (!Node.isMap(source)) | ||
const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value; | ||
if (!identity.isMap(source)) | ||
throw new Error('Merge sources must be maps or map aliases'); | ||
@@ -90,3 +90,3 @@ const srcMap = source.toJSON(null, ctx, Map); | ||
return String(jsKey); | ||
if (Node.isNode(key) && ctx && ctx.doc) { | ||
if (identity.isNode(key) && ctx && ctx.doc) { | ||
const strCtx = stringify.createStringifyContext(ctx.doc, {}); | ||
@@ -93,0 +93,0 @@ strCtx.anchors = new Set(); |
@@ -6,3 +6,3 @@ import type { Document } from '../doc/Document.js'; | ||
import type { Scalar } from './Scalar'; | ||
import type { ToJSContext } from './toJS.js'; | ||
import { ToJSContext } from './toJS.js'; | ||
import type { YAMLMap } from './YAMLMap.js'; | ||
@@ -9,0 +9,0 @@ import type { YAMLSeq } from './YAMLSeq.js'; |
@@ -5,7 +5,9 @@ 'use strict'; | ||
var visit = require('../visit.js'); | ||
var identity = require('./identity.js'); | ||
var Node = require('./Node.js'); | ||
var toJS = require('./toJS.js'); | ||
class Alias extends Node.NodeBase { | ||
constructor(source) { | ||
super(Node.ALIAS); | ||
super(identity.ALIAS); | ||
this.source = source; | ||
@@ -43,3 +45,8 @@ Object.defineProperty(this, 'tag', { | ||
} | ||
const data = anchors.get(source); | ||
let data = anchors.get(source); | ||
if (!data) { | ||
// Resolve anchors for Node.prototype.toJS() | ||
toJS.toJS(source, null, ctx); | ||
data = anchors.get(source); | ||
} | ||
/* istanbul ignore if */ | ||
@@ -76,3 +83,3 @@ if (!data || data.res === undefined) { | ||
function getAliasCount(doc, node, anchors) { | ||
if (Node.isAlias(node)) { | ||
if (identity.isAlias(node)) { | ||
const source = node.resolve(doc); | ||
@@ -82,3 +89,3 @@ const anchor = anchors && source && anchors.get(source); | ||
} | ||
else if (Node.isCollection(node)) { | ||
else if (identity.isCollection(node)) { | ||
let count = 0; | ||
@@ -92,3 +99,3 @@ for (const item of node.items) { | ||
} | ||
else if (Node.isPair(node)) { | ||
else if (identity.isPair(node)) { | ||
const kc = getAliasCount(doc, node.key, anchors); | ||
@@ -95,0 +102,0 @@ const vc = getAliasCount(doc, node.value, anchors); |
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<unknown>; | ||
import { NODE_TYPE } from './identity.js'; | ||
import { NodeBase } 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) => path is null | undefined; | ||
@@ -5,0 +6,0 @@ export declare abstract class Collection extends NodeBase { |
'use strict'; | ||
var createNode = require('../doc/createNode.js'); | ||
var identity = require('./identity.js'); | ||
var Node = require('./Node.js'); | ||
@@ -52,3 +53,3 @@ | ||
copy.schema = schema; | ||
copy.items = copy.items.map(it => Node.isNode(it) || Node.isPair(it) ? it.clone(schema) : it); | ||
copy.items = copy.items.map(it => identity.isNode(it) || identity.isPair(it) ? it.clone(schema) : it); | ||
if (this.range) | ||
@@ -69,3 +70,3 @@ copy.range = this.range.slice(); | ||
const node = this.get(key, true); | ||
if (Node.isCollection(node)) | ||
if (identity.isCollection(node)) | ||
node.addIn(rest, value); | ||
@@ -87,3 +88,3 @@ else if (node === undefined && this.schema) | ||
const node = this.get(key, true); | ||
if (Node.isCollection(node)) | ||
if (identity.isCollection(node)) | ||
return node.deleteIn(rest); | ||
@@ -102,9 +103,9 @@ else | ||
if (rest.length === 0) | ||
return !keepScalar && Node.isScalar(node) ? node.value : node; | ||
return !keepScalar && identity.isScalar(node) ? node.value : node; | ||
else | ||
return Node.isCollection(node) ? node.getIn(rest, keepScalar) : undefined; | ||
return identity.isCollection(node) ? node.getIn(rest, keepScalar) : undefined; | ||
} | ||
hasAllNullValues(allowScalar) { | ||
return this.items.every(node => { | ||
if (!Node.isPair(node)) | ||
if (!identity.isPair(node)) | ||
return false; | ||
@@ -114,3 +115,3 @@ const n = node.value; | ||
(allowScalar && | ||
Node.isScalar(n) && | ||
identity.isScalar(n) && | ||
n.value == null && | ||
@@ -130,3 +131,3 @@ !n.commentBefore && | ||
const node = this.get(key, true); | ||
return Node.isCollection(node) ? node.hasIn(rest) : false; | ||
return identity.isCollection(node) ? node.hasIn(rest) : false; | ||
} | ||
@@ -144,3 +145,3 @@ /** | ||
const node = this.get(key, true); | ||
if (Node.isCollection(node)) | ||
if (identity.isCollection(node)) | ||
node.setIn(rest, value); | ||
@@ -147,0 +148,0 @@ else if (node === undefined && this.schema) |
import type { Document } from '../doc/Document.js'; | ||
import type { ToJSOptions } from '../options.js'; | ||
import { Token } from '../parse/cst.js'; | ||
import type { StringifyContext } from '../stringify/stringify.js'; | ||
import type { Alias } from './Alias.js'; | ||
import type { Pair } from './Pair.js'; | ||
import { NODE_TYPE } from './identity.js'; | ||
import type { Scalar } from './Scalar.js'; | ||
@@ -18,18 +19,2 @@ import type { YAMLMap } from './YAMLMap.js'; | ||
export type Range = [number, number, number]; | ||
export declare const ALIAS: unique symbol; | ||
export declare const DOC: unique symbol; | ||
export declare const MAP: unique symbol; | ||
export declare const PAIR: unique symbol; | ||
export declare const SCALAR: unique symbol; | ||
export declare const SEQ: unique symbol; | ||
export declare const NODE_TYPE: unique symbol; | ||
export declare const isAlias: (node: any) => node is Alias; | ||
export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T, true>; | ||
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 { | ||
@@ -60,2 +45,4 @@ readonly [NODE_TYPE]: symbol; | ||
clone(): NodeBase; | ||
/** A plain JavaScript representation of this node. */ | ||
toJS(doc: Document<Node, boolean>, { mapAsMap, maxAliasCount, onAnchor, reviver }?: ToJSOptions): any; | ||
} |
'use strict'; | ||
const ALIAS = Symbol.for('yaml.alias'); | ||
const DOC = Symbol.for('yaml.document'); | ||
const MAP = Symbol.for('yaml.map'); | ||
const PAIR = Symbol.for('yaml.pair'); | ||
const SCALAR = Symbol.for('yaml.scalar'); | ||
const SEQ = Symbol.for('yaml.seq'); | ||
const NODE_TYPE = Symbol.for('yaml.node.type'); | ||
const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS; | ||
const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC; | ||
const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP; | ||
const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR; | ||
const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR; | ||
const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ; | ||
function isCollection(node) { | ||
if (node && typeof node === 'object') | ||
switch (node[NODE_TYPE]) { | ||
case MAP: | ||
case SEQ: | ||
return true; | ||
} | ||
return false; | ||
} | ||
function isNode(node) { | ||
if (node && typeof node === 'object') | ||
switch (node[NODE_TYPE]) { | ||
case ALIAS: | ||
case MAP: | ||
case SCALAR: | ||
case SEQ: | ||
return true; | ||
} | ||
return false; | ||
} | ||
const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor; | ||
var applyReviver = require('../doc/applyReviver.js'); | ||
var identity = require('./identity.js'); | ||
var toJS = require('./toJS.js'); | ||
class NodeBase { | ||
constructor(type) { | ||
Object.defineProperty(this, NODE_TYPE, { value: type }); | ||
Object.defineProperty(this, identity.NODE_TYPE, { value: type }); | ||
} | ||
@@ -48,20 +18,22 @@ /** Create a copy of this node. */ | ||
} | ||
/** A plain JavaScript representation of this node. */ | ||
toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) { | ||
const ctx = { | ||
anchors: new Map(), | ||
doc, | ||
keep: true, | ||
mapAsMap: mapAsMap === true, | ||
mapKeyWarned: false, | ||
maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100 | ||
}; | ||
const res = toJS.toJS(this, '', ctx); | ||
if (typeof onAnchor === 'function') | ||
for (const { count, res } of ctx.anchors.values()) | ||
onAnchor(res, count); | ||
return typeof reviver === 'function' | ||
? applyReviver.applyReviver(reviver, { '': res }, '', res) | ||
: res; | ||
} | ||
} | ||
exports.ALIAS = ALIAS; | ||
exports.DOC = DOC; | ||
exports.MAP = MAP; | ||
exports.NODE_TYPE = NODE_TYPE; | ||
exports.NodeBase = NodeBase; | ||
exports.PAIR = PAIR; | ||
exports.SCALAR = SCALAR; | ||
exports.SEQ = SEQ; | ||
exports.hasAnchor = hasAnchor; | ||
exports.isAlias = isAlias; | ||
exports.isCollection = isCollection; | ||
exports.isDocument = isDocument; | ||
exports.isMap = isMap; | ||
exports.isNode = isNode; | ||
exports.isPair = isPair; | ||
exports.isScalar = isScalar; | ||
exports.isSeq = isSeq; |
@@ -6,5 +6,5 @@ import { CreateNodeContext } from '../doc/createNode.js'; | ||
import { addPairToJSMap } from './addPairToJSMap.js'; | ||
import { NODE_TYPE } from './Node.js'; | ||
import { NODE_TYPE } from './identity.js'; | ||
import type { ToJSContext } from './toJS.js'; | ||
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 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 class Pair<K = unknown, V = unknown> { | ||
@@ -11,0 +11,0 @@ readonly [NODE_TYPE]: symbol; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var addPairToJSMap = require('./addPairToJSMap.js'); | ||
var Node = require('./Node.js'); | ||
var identity = require('./identity.js'); | ||
@@ -16,3 +16,3 @@ function createPair(key, value, ctx) { | ||
constructor(key, value = null) { | ||
Object.defineProperty(this, Node.NODE_TYPE, { value: Node.PAIR }); | ||
Object.defineProperty(this, identity.NODE_TYPE, { value: identity.PAIR }); | ||
this.key = key; | ||
@@ -23,5 +23,5 @@ this.value = value; | ||
let { key, value } = this; | ||
if (Node.isNode(key)) | ||
if (identity.isNode(key)) | ||
key = key.clone(schema); | ||
if (Node.isNode(value)) | ||
if (identity.isNode(value)) | ||
value = value.clone(schema); | ||
@@ -28,0 +28,0 @@ return new Pair(key, value); |
'use strict'; | ||
var identity = require('./identity.js'); | ||
var Node = require('./Node.js'); | ||
@@ -9,3 +10,3 @@ var toJS = require('./toJS.js'); | ||
constructor(value) { | ||
super(Node.SCALAR); | ||
super(identity.SCALAR); | ||
this.value = value; | ||
@@ -12,0 +13,0 @@ } |
import type { Document } from '../doc/Document.js'; | ||
import type { stringify } from '../stringify/stringify.js'; | ||
import { Node } from './Node.js'; | ||
import type { Node } from './Node.js'; | ||
export interface AnchorData { | ||
@@ -17,4 +16,2 @@ aliasCount: number; | ||
onCreate?: (res: unknown) => void; | ||
/** Requiring this directly in Pair would create circular dependencies */ | ||
stringify: typeof stringify; | ||
} | ||
@@ -21,0 +18,0 @@ /** |
'use strict'; | ||
var Node = require('./Node.js'); | ||
var identity = require('./identity.js'); | ||
@@ -21,3 +21,3 @@ /** | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call | ||
if (!ctx || !Node.hasAnchor(value)) | ||
if (!ctx || !identity.hasAnchor(value)) | ||
return value.toJSON(arg, ctx); | ||
@@ -24,0 +24,0 @@ const data = { aliasCount: 0, count: 1, res: undefined }; |
@@ -5,3 +5,3 @@ import type { BlockMap, FlowCollection } from '../parse/cst.js'; | ||
import { Collection } from './Collection.js'; | ||
import { ParsedNode, Range } from './Node.js'; | ||
import type { ParsedNode, Range } from './Node.js'; | ||
import { Pair } from './Pair.js'; | ||
@@ -8,0 +8,0 @@ import { Scalar } from './Scalar.js'; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
var Collection = require('./Collection.js'); | ||
var Node = require('./Node.js'); | ||
var identity = require('./identity.js'); | ||
var Pair = require('./Pair.js'); | ||
@@ -12,8 +12,8 @@ var Scalar = require('./Scalar.js'); | ||
function findPair(items, key) { | ||
const k = Node.isScalar(key) ? key.value : key; | ||
const k = identity.isScalar(key) ? key.value : key; | ||
for (const it of items) { | ||
if (Node.isPair(it)) { | ||
if (identity.isPair(it)) { | ||
if (it.key === key || it.key === k) | ||
return it; | ||
if (Node.isScalar(it.key) && it.key.value === k) | ||
if (identity.isScalar(it.key) && it.key.value === k) | ||
return it; | ||
@@ -29,3 +29,3 @@ } | ||
constructor(schema) { | ||
super(Node.MAP, schema); | ||
super(identity.MAP, schema); | ||
this.items = []; | ||
@@ -41,3 +41,3 @@ } | ||
let _pair; | ||
if (Node.isPair(pair)) | ||
if (identity.isPair(pair)) | ||
_pair = pair; | ||
@@ -56,3 +56,3 @@ else if (!pair || typeof pair !== 'object' || !('key' in pair)) { | ||
// For scalars, keep the old node & its comments and anchors | ||
if (Node.isScalar(prev.value) && Scalar.isScalarValue(_pair.value)) | ||
if (identity.isScalar(prev.value) && Scalar.isScalarValue(_pair.value)) | ||
prev.value.value = _pair.value; | ||
@@ -83,3 +83,3 @@ else | ||
const node = it?.value; | ||
return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined; | ||
return (!keepScalar && identity.isScalar(node) ? node.value : node) ?? undefined; | ||
} | ||
@@ -109,3 +109,3 @@ has(key) { | ||
for (const item of this.items) { | ||
if (!Node.isPair(item)) | ||
if (!identity.isPair(item)) | ||
throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`); | ||
@@ -112,0 +112,0 @@ } |
@@ -5,3 +5,3 @@ import type { BlockSequence, FlowCollection } from '../parse/cst.js'; | ||
import { Collection } from './Collection.js'; | ||
import { ParsedNode, Range } from './Node.js'; | ||
import type { ParsedNode, Range } from './Node.js'; | ||
import type { Pair } from './Pair.js'; | ||
@@ -8,0 +8,0 @@ import { Scalar } from './Scalar.js'; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
var Collection = require('./Collection.js'); | ||
var Node = require('./Node.js'); | ||
var identity = require('./identity.js'); | ||
var Scalar = require('./Scalar.js'); | ||
@@ -15,3 +15,3 @@ var toJS = require('./toJS.js'); | ||
constructor(schema) { | ||
super(Node.SEQ, schema); | ||
super(identity.SEQ, schema); | ||
this.items = []; | ||
@@ -42,3 +42,3 @@ } | ||
const it = this.items[idx]; | ||
return !keepScalar && Node.isScalar(it) ? it.value : it; | ||
return !keepScalar && identity.isScalar(it) ? it.value : it; | ||
} | ||
@@ -67,3 +67,3 @@ /** | ||
const prev = this.items[idx]; | ||
if (Node.isScalar(prev) && Scalar.isScalarValue(value)) | ||
if (identity.isScalar(prev) && Scalar.isScalarValue(value)) | ||
prev.value = value; | ||
@@ -95,3 +95,3 @@ else | ||
function asItemIndex(key) { | ||
let idx = Node.isScalar(key) ? key.value : key; | ||
let idx = identity.isScalar(key) ? key.value : key; | ||
if (idx && typeof idx === 'string') | ||
@@ -98,0 +98,0 @@ idx = Number(idx); |
'use strict'; | ||
var Node = require('../../nodes/Node.js'); | ||
var identity = require('../../nodes/identity.js'); | ||
var Pair = require('../../nodes/Pair.js'); | ||
@@ -38,3 +38,3 @@ var YAMLMap = require('../../nodes/YAMLMap.js'); | ||
resolve(map, onError) { | ||
if (!Node.isMap(map)) | ||
if (!identity.isMap(map)) | ||
onError('Expected a mapping for this tag'); | ||
@@ -41,0 +41,0 @@ return map; |
'use strict'; | ||
var createNode = require('../../doc/createNode.js'); | ||
var Node = require('../../nodes/Node.js'); | ||
var identity = require('../../nodes/identity.js'); | ||
var YAMLSeq = require('../../nodes/YAMLSeq.js'); | ||
@@ -29,3 +29,3 @@ | ||
resolve(seq, onError) { | ||
if (!Node.isSeq(seq)) | ||
if (!identity.isSeq(seq)) | ||
onError('Expected a sequence for this tag'); | ||
@@ -32,0 +32,0 @@ return seq; |
@@ -1,1 +0,1 @@ | ||
export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[]; | ||
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[]; |
import { CollectionTag, ScalarTag } from '../types.js'; | ||
export declare const schema: (ScalarTag | CollectionTag)[]; | ||
export declare const schema: (CollectionTag | ScalarTag)[]; |
@@ -1,2 +0,2 @@ | ||
import { MAP, SCALAR, SEQ } from '../nodes/Node.js'; | ||
import { MAP, SCALAR, SEQ } from '../nodes/identity.js'; | ||
import type { Pair } from '../nodes/Pair.js'; | ||
@@ -3,0 +3,0 @@ import type { SchemaOptions, ToStringOptions } from '../options.js'; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var map = require('./common/map.js'); | ||
@@ -22,5 +22,5 @@ var seq = require('./common/seq.js'); | ||
this.toStringOptions = toStringDefaults ?? null; | ||
Object.defineProperty(this, Node.MAP, { value: map.map }); | ||
Object.defineProperty(this, Node.SCALAR, { value: string.string }); | ||
Object.defineProperty(this, Node.SEQ, { value: seq.seq }); | ||
Object.defineProperty(this, identity.MAP, { value: map.map }); | ||
Object.defineProperty(this, identity.SCALAR, { value: string.string }); | ||
Object.defineProperty(this, identity.SEQ, { value: seq.seq }); | ||
// Used by createMap() | ||
@@ -27,0 +27,0 @@ this.sortMapEntries = |
@@ -39,3 +39,3 @@ import { SchemaOptions } from '../options.js'; | ||
}; | ||
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (ScalarTag | CollectionTag)[]; | ||
export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (CollectionTag | ScalarTag)[]; | ||
export {}; |
@@ -0,3 +1,3 @@ | ||
import { ToJSContext } from '../../nodes/toJS.js'; | ||
import { YAMLSeq } from '../../nodes/YAMLSeq.js'; | ||
import { ToJSContext } from '../../nodes/toJS.js'; | ||
import { CollectionTag } from '../types.js'; | ||
@@ -4,0 +4,0 @@ export declare class YAMLOMap extends YAMLSeq { |
'use strict'; | ||
var YAMLSeq = require('../../nodes/YAMLSeq.js'); | ||
var identity = require('../../nodes/identity.js'); | ||
var toJS = require('../../nodes/toJS.js'); | ||
var Node = require('../../nodes/Node.js'); | ||
var YAMLMap = require('../../nodes/YAMLMap.js'); | ||
var YAMLSeq = require('../../nodes/YAMLSeq.js'); | ||
var pairs = require('./pairs.js'); | ||
@@ -31,3 +31,3 @@ | ||
let key, value; | ||
if (Node.isPair(pair)) { | ||
if (identity.isPair(pair)) { | ||
key = toJS.toJS(pair.key, '', ctx); | ||
@@ -57,3 +57,3 @@ value = toJS.toJS(pair.value, key, ctx); | ||
for (const { key } of pairs$1.items) { | ||
if (Node.isScalar(key)) { | ||
if (identity.isScalar(key)) { | ||
if (seenKeys.includes(key.value)) { | ||
@@ -60,0 +60,0 @@ onError(`Ordered maps must not include duplicate keys: ${key.value}`); |
import type { CreateNodeContext } from '../../doc/createNode.js'; | ||
import { ParsedNode } from '../../nodes/Node.js'; | ||
import type { ParsedNode } from '../../nodes/Node.js'; | ||
import { Pair } from '../../nodes/Pair.js'; | ||
@@ -4,0 +4,0 @@ import { YAMLMap } from '../../nodes/YAMLMap.js'; |
'use strict'; | ||
var Node = require('../../nodes/Node.js'); | ||
var identity = require('../../nodes/identity.js'); | ||
var Pair = require('../../nodes/Pair.js'); | ||
@@ -9,8 +9,8 @@ var Scalar = require('../../nodes/Scalar.js'); | ||
function resolvePairs(seq, onError) { | ||
if (Node.isSeq(seq)) { | ||
if (identity.isSeq(seq)) { | ||
for (let i = 0; i < seq.items.length; ++i) { | ||
let item = seq.items[i]; | ||
if (Node.isPair(item)) | ||
if (identity.isPair(item)) | ||
continue; | ||
else if (Node.isMap(item)) { | ||
else if (identity.isMap(item)) { | ||
if (item.items.length > 1) | ||
@@ -31,3 +31,3 @@ onError('Each pair must have its own sequence indicator'); | ||
} | ||
seq.items[i] = Node.isPair(item) ? item : new Pair.Pair(item); | ||
seq.items[i] = identity.isPair(item) ? item : new Pair.Pair(item); | ||
} | ||
@@ -34,0 +34,0 @@ } |
@@ -1,1 +0,1 @@ | ||
export declare const schema: (import("../types.js").ScalarTag | import("../types.js").CollectionTag)[]; | ||
export declare const schema: (import("../types.js").CollectionTag | import("../types.js").ScalarTag)[]; |
'use strict'; | ||
var Node = require('../../nodes/Node.js'); | ||
var identity = require('../../nodes/identity.js'); | ||
var Pair = require('../../nodes/Pair.js'); | ||
@@ -14,3 +14,3 @@ var YAMLMap = require('../../nodes/YAMLMap.js'); | ||
let pair; | ||
if (Node.isPair(key)) | ||
if (identity.isPair(key)) | ||
pair = key; | ||
@@ -35,4 +35,4 @@ else if (key && | ||
const pair = YAMLMap.findPair(this.items, key); | ||
return !keepPair && Node.isPair(pair) | ||
? Node.isScalar(pair.key) | ||
return !keepPair && identity.isPair(pair) | ||
? identity.isScalar(pair.key) | ||
? pair.key.value | ||
@@ -73,3 +73,3 @@ : pair.key | ||
resolve(map, onError) { | ||
if (Node.isMap(map)) { | ||
if (identity.isMap(map)) { | ||
if (map.hasAllNullValues(true)) | ||
@@ -76,0 +76,0 @@ return Object.assign(new YAMLSet(), map); |
'use strict'; | ||
var anchors = require('../doc/anchors.js'); | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var stringifyComment = require('./stringifyComment.js'); | ||
@@ -57,3 +57,3 @@ var stringifyString = require('./stringifyString.js'); | ||
let obj; | ||
if (Node.isScalar(item)) { | ||
if (identity.isScalar(item)) { | ||
obj = item.value; | ||
@@ -79,3 +79,3 @@ const match = tags.filter(t => t.identify?.(obj)); | ||
const props = []; | ||
const anchor = (Node.isScalar(node) || Node.isCollection(node)) && node.anchor; | ||
const anchor = (identity.isScalar(node) || identity.isCollection(node)) && node.anchor; | ||
if (anchor && anchors.anchorIsValid(anchor)) { | ||
@@ -91,5 +91,5 @@ anchors$1.add(anchor); | ||
function stringify(item, ctx, onComment, onChompKeep) { | ||
if (Node.isPair(item)) | ||
if (identity.isPair(item)) | ||
return item.toString(ctx, onComment, onChompKeep); | ||
if (Node.isAlias(item)) { | ||
if (identity.isAlias(item)) { | ||
if (ctx.doc.directives) | ||
@@ -109,3 +109,3 @@ return item.toString(ctx); | ||
let tagObj = undefined; | ||
const node = Node.isNode(item) | ||
const node = identity.isNode(item) | ||
? item | ||
@@ -120,3 +120,3 @@ : ctx.doc.createNode(item, { onTagObj: o => (tagObj = o) }); | ||
? tagObj.stringify(node, ctx, onComment, onChompKeep) | ||
: Node.isScalar(node) | ||
: identity.isScalar(node) | ||
? stringifyString.stringifyString(node, ctx, onComment, onChompKeep) | ||
@@ -126,3 +126,3 @@ : node.toString(ctx, onComment, onChompKeep); | ||
return str; | ||
return Node.isScalar(node) || str[0] === '{' || str[0] === '[' | ||
return identity.isScalar(node) || str[0] === '{' || str[0] === '[' | ||
? `${props} ${str}` | ||
@@ -129,0 +129,0 @@ : `${props}\n${ctx.indent}${str}`; |
'use strict'; | ||
var Collection = require('../nodes/Collection.js'); | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var stringify = require('./stringify.js'); | ||
@@ -21,3 +21,3 @@ var stringifyComment = require('./stringifyComment.js'); | ||
let comment = null; | ||
if (Node.isNode(item)) { | ||
if (identity.isNode(item)) { | ||
if (!chompKeep && item.spaceBefore) | ||
@@ -29,4 +29,4 @@ lines.push(''); | ||
} | ||
else if (Node.isPair(item)) { | ||
const ik = Node.isNode(item.key) ? item.key : null; | ||
else if (identity.isPair(item)) { | ||
const ik = identity.isNode(item.key) ? item.key : null; | ||
if (ik) { | ||
@@ -80,3 +80,3 @@ if (!chompKeep && ik.spaceBefore) | ||
let comment = null; | ||
if (Node.isNode(item)) { | ||
if (identity.isNode(item)) { | ||
if (item.spaceBefore) | ||
@@ -88,4 +88,4 @@ lines.push(''); | ||
} | ||
else if (Node.isPair(item)) { | ||
const ik = Node.isNode(item.key) ? item.key : null; | ||
else if (identity.isPair(item)) { | ||
const ik = identity.isNode(item.key) ? item.key : null; | ||
if (ik) { | ||
@@ -98,3 +98,3 @@ if (ik.spaceBefore) | ||
} | ||
const iv = Node.isNode(item.value) ? item.value : null; | ||
const iv = identity.isNode(item.value) ? item.value : null; | ||
if (iv) { | ||
@@ -101,0 +101,0 @@ if (iv.comment) |
@@ -1,4 +0,4 @@ | ||
import { Document } from '../doc/Document.js'; | ||
import { Node } from '../nodes/Node.js'; | ||
import { ToStringOptions } from '../options.js'; | ||
import type { Document } from '../doc/Document.js'; | ||
import type { Node } from '../nodes/Node.js'; | ||
import type { ToStringOptions } from '../options.js'; | ||
export declare function stringifyDocument(doc: Readonly<Document<Node, boolean>>, options: ToStringOptions): string; |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var stringify = require('./stringify.js'); | ||
@@ -32,3 +32,3 @@ var stringifyComment = require('./stringifyComment.js'); | ||
if (doc.contents) { | ||
if (Node.isNode(doc.contents)) { | ||
if (identity.isNode(doc.contents)) { | ||
if (doc.contents.spaceBefore && hasDirectives) | ||
@@ -35,0 +35,0 @@ lines.push(''); |
'use strict'; | ||
var Node = require('../nodes/Node.js'); | ||
var identity = require('../nodes/identity.js'); | ||
var Scalar = require('../nodes/Scalar.js'); | ||
@@ -10,3 +10,3 @@ var stringify = require('./stringify.js'); | ||
const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx; | ||
let keyComment = (Node.isNode(key) && key.comment) || null; | ||
let keyComment = (identity.isNode(key) && key.comment) || null; | ||
if (simpleKeys) { | ||
@@ -16,3 +16,3 @@ if (keyComment) { | ||
} | ||
if (Node.isCollection(key)) { | ||
if (identity.isCollection(key)) { | ||
const msg = 'With simple keys, collection cannot be used as a key value'; | ||
@@ -25,4 +25,4 @@ throw new Error(msg); | ||
(keyComment && value == null && !ctx.inFlow) || | ||
Node.isCollection(key) || | ||
(Node.isScalar(key) | ||
identity.isCollection(key) || | ||
(identity.isScalar(key) | ||
? key.type === Scalar.Scalar.BLOCK_FOLDED || key.type === Scalar.Scalar.BLOCK_LITERAL | ||
@@ -72,3 +72,3 @@ : typeof key === 'object')); | ||
let vsb, vcb, valueComment; | ||
if (Node.isNode(value)) { | ||
if (identity.isNode(value)) { | ||
vsb = !!value.spaceBefore; | ||
@@ -86,3 +86,3 @@ vcb = value.commentBefore; | ||
ctx.implicitKey = false; | ||
if (!explicitKey && !keyComment && Node.isScalar(value)) | ||
if (!explicitKey && !keyComment && identity.isScalar(value)) | ||
ctx.indentAtStart = str.length + 1; | ||
@@ -94,3 +94,3 @@ chompKeep = false; | ||
!explicitKey && | ||
Node.isSeq(value) && | ||
identity.isSeq(value) && | ||
!value.flow && | ||
@@ -119,3 +119,3 @@ !value.tag && | ||
} | ||
else if (!explicitKey && Node.isCollection(value)) { | ||
else if (!explicitKey && identity.isCollection(value)) { | ||
const vs0 = valueStr[0]; | ||
@@ -122,0 +122,0 @@ const nl0 = valueStr.indexOf('\n'); |
@@ -6,4 +6,4 @@ 'use strict'; | ||
const getFoldOptions = (ctx) => ({ | ||
indentAtStart: ctx.indentAtStart, | ||
const getFoldOptions = (ctx, isBlock) => ({ | ||
indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart, | ||
lineWidth: ctx.options.lineWidth, | ||
@@ -121,3 +121,3 @@ minContentWidth: ctx.options.minContentWidth | ||
? str | ||
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx)); | ||
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx, false)); | ||
} | ||
@@ -134,3 +134,3 @@ function singleQuotedString(value, ctx) { | ||
? res | ||
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx)); | ||
: foldFlowLines.foldFlowLines(res, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false)); | ||
} | ||
@@ -242,3 +242,3 @@ function quotedString(value, ctx) { | ||
.replace(/\n+/g, `$&${indent}`); | ||
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx)); | ||
const body = foldFlowLines.foldFlowLines(`${start}${value}${end}`, indent, foldFlowLines.FOLD_BLOCK, getFoldOptions(ctx, true)); | ||
return `${header}\n${indent}${body}`; | ||
@@ -293,3 +293,3 @@ } | ||
? str | ||
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx)); | ||
: foldFlowLines.foldFlowLines(str, indent, foldFlowLines.FOLD_FLOW, getFoldOptions(ctx, false)); | ||
} | ||
@@ -296,0 +296,0 @@ function stringifyString(item, ctx, onComment, onChompKeep) { |
'use strict'; | ||
var Node = require('./nodes/Node.js'); | ||
var identity = require('./nodes/identity.js'); | ||
var publicApi = require('./public-api.js'); | ||
@@ -69,6 +69,6 @@ var visit = require('./visit.js'); | ||
} | ||
if (errPos !== -1 && Node.isNode(node) && node.range[0] >= errPos) | ||
if (errPos !== -1 && identity.isNode(node) && node.range[0] >= errPos) | ||
throw new Error(); | ||
let props = ''; | ||
let anchor = Node.isScalar(node) || Node.isCollection(node) ? node.anchor : undefined; | ||
let anchor = identity.isScalar(node) || identity.isCollection(node) ? node.anchor : undefined; | ||
if (anchor) { | ||
@@ -82,5 +82,5 @@ if (/\d$/.test(anchor)) { | ||
} | ||
if (Node.isNode(node) && node.tag) | ||
if (identity.isNode(node) && node.tag) | ||
props += ` <${node.tag}>`; | ||
if (Node.isMap(node)) { | ||
if (identity.isMap(node)) { | ||
const ev = node.flow ? '+MAP {}' : '+MAP'; | ||
@@ -94,3 +94,3 @@ events.push(`${ev}${props}`); | ||
} | ||
else if (Node.isSeq(node)) { | ||
else if (identity.isSeq(node)) { | ||
const ev = node.flow ? '+SEQ []' : '+SEQ'; | ||
@@ -103,3 +103,3 @@ events.push(`${ev}${props}`); | ||
} | ||
else if (Node.isPair(node)) { | ||
else if (identity.isPair(node)) { | ||
events.push(`+MAP${props}`); | ||
@@ -110,3 +110,3 @@ addEvents(events, doc, errPos, node.key); | ||
} | ||
else if (Node.isAlias(node)) { | ||
else if (identity.isAlias(node)) { | ||
let alias = node.source; | ||
@@ -113,0 +113,0 @@ if (alias && /\d$/.test(alias)) { |
@@ -0,2 +1,4 @@ | ||
export { createNode, CreateNodeContext } from './doc/createNode.js'; | ||
export { debug, LogLevelId, warn } from './log.js'; | ||
export { createPair } from './nodes/Pair.js'; | ||
export { findPair } from './nodes/YAMLMap.js'; | ||
@@ -3,0 +5,0 @@ export { toJS, ToJSContext } from './nodes/toJS.js'; |
'use strict'; | ||
var createNode = require('./doc/createNode.js'); | ||
var log = require('./log.js'); | ||
var Pair = require('./nodes/Pair.js'); | ||
var YAMLMap = require('./nodes/YAMLMap.js'); | ||
@@ -15,4 +17,6 @@ var toJS = require('./nodes/toJS.js'); | ||
exports.createNode = createNode.createNode; | ||
exports.debug = log.debug; | ||
exports.warn = log.warn; | ||
exports.createPair = Pair.createPair; | ||
exports.findPair = YAMLMap.findPair; | ||
@@ -19,0 +23,0 @@ exports.toJS = toJS.toJS; |
'use strict'; | ||
var Node = require('./nodes/Node.js'); | ||
var identity = require('./nodes/identity.js'); | ||
@@ -40,3 +40,3 @@ const BREAK = Symbol('break visit'); | ||
const visitor_ = initVisitor(visitor); | ||
if (Node.isDocument(node)) { | ||
if (identity.isDocument(node)) { | ||
const cd = visit_(null, node.contents, visitor_, Object.freeze([node])); | ||
@@ -60,3 +60,3 @@ if (cd === REMOVE) | ||
const ctrl = callVisitor(key, node, visitor, path); | ||
if (Node.isNode(ctrl) || Node.isPair(ctrl)) { | ||
if (identity.isNode(ctrl) || identity.isPair(ctrl)) { | ||
replaceNode(key, path, ctrl); | ||
@@ -66,3 +66,3 @@ return visit_(key, ctrl, visitor, path); | ||
if (typeof ctrl !== 'symbol') { | ||
if (Node.isCollection(node)) { | ||
if (identity.isCollection(node)) { | ||
path = Object.freeze(path.concat(node)); | ||
@@ -81,3 +81,3 @@ for (let i = 0; i < node.items.length; ++i) { | ||
} | ||
else if (Node.isPair(node)) { | ||
else if (identity.isPair(node)) { | ||
path = Object.freeze(path.concat(node)); | ||
@@ -131,3 +131,3 @@ const ck = visit_('key', node.key, visitor, path); | ||
const visitor_ = initVisitor(visitor); | ||
if (Node.isDocument(node)) { | ||
if (identity.isDocument(node)) { | ||
const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node])); | ||
@@ -151,3 +151,3 @@ if (cd === REMOVE) | ||
const ctrl = await callVisitor(key, node, visitor, path); | ||
if (Node.isNode(ctrl) || Node.isPair(ctrl)) { | ||
if (identity.isNode(ctrl) || identity.isPair(ctrl)) { | ||
replaceNode(key, path, ctrl); | ||
@@ -157,3 +157,3 @@ return visitAsync_(key, ctrl, visitor, path); | ||
if (typeof ctrl !== 'symbol') { | ||
if (Node.isCollection(node)) { | ||
if (identity.isCollection(node)) { | ||
path = Object.freeze(path.concat(node)); | ||
@@ -172,3 +172,3 @@ for (let i = 0; i < node.items.length; ++i) { | ||
} | ||
else if (Node.isPair(node)) { | ||
else if (identity.isPair(node)) { | ||
path = Object.freeze(path.concat(node)); | ||
@@ -211,11 +211,11 @@ const ck = await visitAsync_('key', node.key, visitor, path); | ||
return visitor(key, node, path); | ||
if (Node.isMap(node)) | ||
if (identity.isMap(node)) | ||
return visitor.Map?.(key, node, path); | ||
if (Node.isSeq(node)) | ||
if (identity.isSeq(node)) | ||
return visitor.Seq?.(key, node, path); | ||
if (Node.isPair(node)) | ||
if (identity.isPair(node)) | ||
return visitor.Pair?.(key, node, path); | ||
if (Node.isScalar(node)) | ||
if (identity.isScalar(node)) | ||
return visitor.Scalar?.(key, node, path); | ||
if (Node.isAlias(node)) | ||
if (identity.isAlias(node)) | ||
return visitor.Alias?.(key, node, path); | ||
@@ -226,6 +226,6 @@ return undefined; | ||
const parent = path[path.length - 1]; | ||
if (Node.isCollection(parent)) { | ||
if (identity.isCollection(parent)) { | ||
parent.items[key] = node; | ||
} | ||
else if (Node.isPair(parent)) { | ||
else if (identity.isPair(parent)) { | ||
if (key === 'key') | ||
@@ -236,7 +236,7 @@ parent.key = node; | ||
} | ||
else if (Node.isDocument(parent)) { | ||
else if (identity.isDocument(parent)) { | ||
parent.contents = node; | ||
} | ||
else { | ||
const pt = Node.isAlias(parent) ? 'alias' : 'scalar'; | ||
const pt = identity.isAlias(parent) ? 'alias' : 'scalar'; | ||
throw new Error(`Cannot replace node with ${pt} parent`); | ||
@@ -243,0 +243,0 @@ } |
{ | ||
"name": "yaml", | ||
"version": "2.3.0-0", | ||
"version": "2.3.0-1", | ||
"license": "ISC", | ||
@@ -80,3 +80,3 @@ "author": "Eemeli Aro <eemeli@gmail.com>", | ||
"@rollup/plugin-replace": "^5.0.2", | ||
"@rollup/plugin-typescript": "^10.0.1", | ||
"@rollup/plugin-typescript": "^11.0.0", | ||
"@types/jest": "^29.2.4", | ||
@@ -96,7 +96,8 @@ "@types/node": "^14.18.35", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.3.5" | ||
"typescript": "^5.0.3" | ||
}, | ||
"engines": { | ||
"node": ">= 14" | ||
"node": ">= 14", | ||
"npm": ">= 7" | ||
} | ||
} |
658130
228
17523