Socket
Socket
Sign inDemoInstall

yaml

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yaml - npm Package Compare versions

Comparing version 2.2.1 to 2.3.0-0

1

browser/dist/compose/compose-doc.js

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

}
// @ts-expect-error If Contents is set, let's trust the user
doc.contents = value

@@ -31,0 +32,0 @@ ? composeNode(ctx, value, props, onError)

16

browser/dist/doc/Document.js

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

this.setSchema(version, options);
if (value === undefined)
this.contents = null;
else {
this.contents = this.createNode(value, _replacer, options);
}
// @ts-expect-error We can't really know that this matches Contents.
this.contents =
value === undefined ? null : this.createNode(value, _replacer, options);
}

@@ -76,2 +74,3 @@ /**

copy.schema = this.schema.clone();
// @ts-expect-error We can't really know that this matches Contents.
copy.contents = isNode(this.contents)

@@ -172,2 +171,3 @@ ? this.contents.clone(copy.schema)

return false;
// @ts-expect-error Presumed impossible if Strict extends false
this.contents = null;

@@ -224,2 +224,3 @@ return true;

if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = collectionFromPath(this.schema, [key], value);

@@ -236,5 +237,8 @@ }

setIn(path, value) {
if (isEmptyPath(path))
if (isEmptyPath(path)) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = value;
}
else if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = collectionFromPath(this.schema, Array.from(path), value);

@@ -241,0 +245,0 @@ }

@@ -15,3 +15,3 @@ import { map } from './common/map.js';

import { set } from './yaml-1.1/set.js';
import { floatTime, intTime, timestamp } from './yaml-1.1/timestamp.js';
import { timestamp, floatTime, intTime } from './yaml-1.1/timestamp.js';

@@ -18,0 +18,0 @@ const schemas = new Map([

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

if (comment) {
str += lineComment(str, commentString(comment), indent);
str += lineComment(str, indent, commentString(comment));
if (onComment)

@@ -139,0 +139,0 @@ onComment();

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

}
// The negative lookbehind avoids a polynomial search,
// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind
let blockEndNewlines;
try {
blockEndNewlines = new RegExp('(^|(?<!\n))\n+(?!\n|$)', 'g');
}
catch {
blockEndNewlines = /\n+(?!\n|$)/g;
}
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {

@@ -193,3 +202,3 @@ const { blockQuote, commentString, lineWidth } = ctx.options;

end = end.slice(0, -1);
end = end.replace(/\n+(?!\n|$)/g, `$&${indent}`);
end = end.replace(blockEndNewlines, `$&${indent}`);
}

@@ -196,0 +205,0 @@ // determine indent indicator from whitespace at value start

import type { Directives } from '../doc/directives.js';
import { Document } from '../doc/Document.js';
import type { ParsedNode } from '../nodes/Node.js';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
import type * as CST from '../parse/cst.js';
import type { ComposeErrorHandler } from './composer.js';
export declare function composeDoc(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<import("../index.js").ParsedNode>;
export declare function composeDoc<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true>(options: ParseOptions & DocumentOptions & SchemaOptions, directives: Directives, { offset, start, value, end }: CST.Document, onError: ComposeErrorHandler): Document.Parsed<Contents, Strict>;

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

}
// @ts-expect-error If Contents is set, let's trust the user
doc.contents = value

@@ -33,0 +34,0 @@ ? composeNode.composeNode(ctx, value, props, onError)

import { Directives } from '../doc/directives.js';
import { Document } from '../doc/Document.js';
import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
import { Range } from '../nodes/Node.js';
import { ParsedNode, Range } from '../nodes/Node.js';
import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';

@@ -23,3 +23,3 @@ import type { Token } from '../parse/cst.js';

*/
export declare class Composer {
export declare class Composer<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> {
private directives;

@@ -52,5 +52,5 @@ private doc;

*/
compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
compose(tokens: Iterable<Token>, forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
/** Advance the composer by one CST token. */
next(token: Token): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
next(token: Token): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
/**

@@ -62,4 +62,4 @@ * Call at end of input to yield any remaining document.

*/
end(forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<import("../nodes/Node.js").ParsedNode>, void, unknown>;
end(forceDoc?: boolean, endOffset?: number): Generator<Document.Parsed<Contents, Strict>, void, unknown>;
}
export {};

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

export declare function anchorIsValid(anchor: string): true;
export declare function anchorNames(root: Document | Node): Set<string>;
export declare function anchorNames(root: Document<Node, boolean> | Node): Set<string>;
/** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
export declare function findNewAnchor(prefix: string, exclude: Set<string>): string;
export declare function createNodeAnchors(doc: Document, prefix: string): {
export declare function createNodeAnchors(doc: Document<Node, boolean>, prefix: string): {
onAnchor: (source: unknown) => string;

@@ -15,0 +15,0 @@ /**

@@ -13,3 +13,4 @@ import type { YAMLError, YAMLWarning } from '../errors.js';

export declare namespace Document {
interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
/** @ts-ignore The typing of directives fails in TS <= 4.2 */
interface Parsed<Contents extends ParsedNode = ParsedNode, Strict extends boolean = true> extends Document<Contents, Strict> {
directives: Directives;

@@ -19,3 +20,3 @@ range: Range;

}
export declare class Document<T extends Node = Node> {
export declare class Document<Contents extends Node = Node, Strict extends boolean = true> {
readonly [NODE_TYPE]: symbol;

@@ -27,4 +28,4 @@ /** A comment before this Document */

/** The document contents. */
contents: T | null;
directives?: Directives;
contents: Strict extends true ? Contents | null : Contents;
directives: Strict extends true ? Directives | undefined : Directives;
/** Errors encountered during parsing. */

@@ -55,3 +56,3 @@ errors: YAMLError[];

*/
clone(): Document<T>;
clone(): Document<Contents, Strict>;
/** Adds a value to the document. */

@@ -70,3 +71,3 @@ add(value: any): void;

*/
createAlias(node: Scalar | YAMLMap | YAMLSeq, name?: string): Alias;
createAlias(node: Strict extends true ? Scalar | YAMLMap | YAMLSeq : Node, name?: string): Alias;
/**

@@ -98,3 +99,3 @@ * Convert any value into a `Node` using the current schema, recursively

*/
get(key: unknown, keepScalar?: boolean): unknown;
get(key: unknown, keepScalar?: boolean): Strict extends true ? unknown : any;
/**

@@ -105,3 +106,3 @@ * Returns item at `path`, or `undefined` if not found. By default unwraps

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

@@ -108,0 +109,0 @@ * Checks if the document includes a value with the key `key`.

@@ -54,7 +54,5 @@ 'use strict';

this.setSchema(version, options);
if (value === undefined)
this.contents = null;
else {
this.contents = this.createNode(value, _replacer, options);
}
// @ts-expect-error We can't really know that this matches Contents.
this.contents =
value === undefined ? null : this.createNode(value, _replacer, options);
}

@@ -78,2 +76,3 @@ /**

copy.schema = this.schema.clone();
// @ts-expect-error We can't really know that this matches Contents.
copy.contents = Node.isNode(this.contents)

@@ -174,2 +173,3 @@ ? this.contents.clone(copy.schema)

return false;
// @ts-expect-error Presumed impossible if Strict extends false
this.contents = null;

@@ -226,2 +226,3 @@ return true;

if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = Collection.collectionFromPath(this.schema, [key], value);

@@ -238,5 +239,8 @@ }

setIn(path, value) {
if (Collection.isEmptyPath(path))
if (Collection.isEmptyPath(path)) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = value;
}
else if (this.contents == null) {
// @ts-expect-error We can't really know that this matches Contents.
this.contents = Collection.collectionFromPath(this.schema, Array.from(path), value);

@@ -243,0 +247,0 @@ }

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

/** Utility type mapper */
export type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
export type NodeType<T> = T extends string | number | bigint | boolean | null | undefined ? Scalar<T> : T extends Date ? Scalar<string | Date> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
[key: string]: any;

@@ -27,3 +27,3 @@ } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : T extends {

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>;
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>;

@@ -30,0 +30,0 @@ export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;

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

anchors: Map<Node, AnchorData>;
doc: Document;
doc: Document<Node, boolean>;
keep: boolean;

@@ -14,0 +14,0 @@ mapAsMap: boolean;

import { Composer } from './compose/composer.js';
import type { Reviver } from './doc/applyReviver.js';
import { Document, Replacer } from './doc/Document.js';
import type { ParsedNode } from './nodes/Node.js';
import type { Node, ParsedNode } from './nodes/Node.js';
import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';

@@ -18,5 +18,5 @@ export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {

*/
export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
export declare function parseAllDocuments<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Array<Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>> | EmptyStream;
/** Parse an input string into a single YAML.Document */
export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
export declare function parseDocument<Contents extends Node = ParsedNode, Strict extends boolean = true>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Contents extends ParsedNode ? Document.Parsed<Contents, Strict> : Document<Contents, Strict>;
/**

@@ -23,0 +23,0 @@ * Parse an input string into JavaScript.

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

if (comment) {
str += stringifyComment.lineComment(str, commentString(comment), indent);
str += stringifyComment.lineComment(str, indent, commentString(comment));
if (onComment)

@@ -141,0 +141,0 @@ onComment();

import { Document } from '../doc/Document.js';
import { Node } from '../nodes/Node.js';
import { ToStringOptions } from '../options.js';
export declare function stringifyDocument(doc: Readonly<Document>, options: ToStringOptions): string;
export declare function stringifyDocument(doc: Readonly<Document<Node, boolean>>, options: ToStringOptions): string;

@@ -151,2 +151,11 @@ 'use strict';

}
// The negative lookbehind avoids a polynomial search,
// but isn't supported yet on Safari: https://caniuse.com/js-regexp-lookbehind
let blockEndNewlines;
try {
blockEndNewlines = new RegExp('(^|(?<!\n))\n+(?!\n|$)', 'g');
}
catch {
blockEndNewlines = /\n+(?!\n|$)/g;
}
function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {

@@ -195,3 +204,3 @@ const { blockQuote, commentString, lineWidth } = ctx.options;

end = end.slice(0, -1);
end = end.replace(/\n+(?!\n|$)/g, `$&${indent}`);
end = end.replace(blockEndNewlines, `$&${indent}`);
}

@@ -198,0 +207,0 @@ // determine indent indicator from whitespace at value start

@@ -7,4 +7,4 @@ export { debug, LogLevelId, warn } from './log.js';

export { string as stringTag } from './schema/common/string.js';
export { foldFlowLines } from './stringify/foldFlowLines';
export { foldFlowLines, FoldOptions } from './stringify/foldFlowLines';
export { stringifyNumber } from './stringify/stringifyNumber.js';
export { stringifyString } from './stringify/stringifyString.js';
{
"name": "yaml",
"version": "2.2.1",
"version": "2.3.0-0",
"license": "ISC",

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

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

@@ -39,2 +38,9 @@ ],

},
"typesVersions": {
"*": {
"*": [
"dist/*"
]
}
},
"scripts": {

@@ -54,3 +60,3 @@ "build": "npm run build:node && npm run build:browser",

"test:dist:types": "tsc --allowJs --moduleResolution node --noEmit --target es5 dist/index.js",
"test:types": "tsc --noEmit",
"test:types": "tsc --noEmit && tsc --noEmit -p tests/tsconfig.json",
"docs:install": "cd docs-slate && bundle install",

@@ -57,0 +63,0 @@ "docs:deploy": "cd docs-slate && ./deploy.sh",

@@ -17,2 +17,6 @@ # YAML <a href="https://www.npmjs.com/package/yaml"><img align="right" src="https://badge.fury.io/js/yaml.svg" title="npm package" /></a>

The minimum supported TypeScript version of the included typings is 3.9;
for use in earlier versions you may need to set `skipLibCheck: true` in your config.
This requirement may be updated between minor versions of the library.
For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)

@@ -19,0 +23,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc