node_modules: upgrade

This commit is contained in:
Dawid Dziurla
2024-01-17 10:08:10 +01:00
parent 9ff0bc8d99
commit 00765f79cf
320 changed files with 31840 additions and 1039 deletions

View File

@@ -1,4 +1,4 @@
import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
import { map } from './common/map.js';
import { seq } from './common/seq.js';
import { string } from './common/string.js';

View File

@@ -1,34 +1,8 @@
import { isMap } from '../../nodes/Node.js';
import { createPair } from '../../nodes/Pair.js';
import { isMap } from '../../nodes/identity.js';
import { YAMLMap } from '../../nodes/YAMLMap.js';
function createMap(schema, obj, ctx) {
const { keepUndefined, replacer } = ctx;
const map = new YAMLMap(schema);
const add = (key, value) => {
if (typeof replacer === 'function')
value = replacer.call(obj, key, value);
else if (Array.isArray(replacer) && !replacer.includes(key))
return;
if (value !== undefined || keepUndefined)
map.items.push(createPair(key, value, ctx));
};
if (obj instanceof Map) {
for (const [key, value] of obj)
add(key, value);
}
else if (obj && typeof obj === 'object') {
for (const key of Object.keys(obj))
add(key, obj[key]);
}
if (typeof schema.sortMapEntries === 'function') {
map.items.sort(schema.sortMapEntries);
}
return map;
}
const map = {
collection: 'map',
createNode: createMap,
default: true,
nodeClass: YAMLMap,
tag: 'tag:yaml.org,2002:map',
@@ -36,7 +10,8 @@ const map = {
if (!isMap(map))
onError('Expected a mapping for this tag');
return map;
}
},
createNode: (schema, obj, ctx) => YAMLMap.from(schema, obj, ctx)
};
export { map };

View File

@@ -1,25 +1,8 @@
import { createNode } from '../../doc/createNode.js';
import { isSeq } from '../../nodes/Node.js';
import { isSeq } from '../../nodes/identity.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
function createSeq(schema, obj, ctx) {
const { replacer } = ctx;
const seq = new YAMLSeq(schema);
if (obj && Symbol.iterator in Object(obj)) {
let i = 0;
for (let it of obj) {
if (typeof replacer === 'function') {
const key = obj instanceof Set ? it : String(i++);
it = replacer.call(obj, key, it);
}
seq.items.push(createNode(it, undefined, ctx));
}
}
return seq;
}
const seq = {
collection: 'seq',
createNode: createSeq,
default: true,
nodeClass: YAMLSeq,
tag: 'tag:yaml.org,2002:seq',
@@ -27,7 +10,8 @@ const seq = {
if (!isSeq(seq))
onError('Expected a sequence for this tag');
return seq;
}
},
createNode: (schema, obj, ctx) => YAMLSeq.from(schema, obj, ctx)
};
export { seq };

View File

@@ -12,7 +12,7 @@ import { omap } from './yaml-1.1/omap.js';
import { pairs } from './yaml-1.1/pairs.js';
import { schema as schema$2 } from './yaml-1.1/schema.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';
const schemas = new Map([
['core', schema],

View File

@@ -1,7 +1,7 @@
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';
class YAMLOMap extends YAMLSeq {
@@ -39,6 +39,12 @@ class YAMLOMap extends YAMLSeq {
}
return map;
}
static from(schema, iterable, ctx) {
const pairs = createPairs(schema, iterable, ctx);
const omap = new this();
omap.items = pairs.items;
return omap;
}
}
YAMLOMap.tag = 'tag:yaml.org,2002:omap';
const omap = {
@@ -62,12 +68,7 @@ const omap = {
}
return Object.assign(new YAMLOMap(), pairs);
},
createNode(schema, iterable, ctx) {
const pairs = createPairs(schema, iterable, ctx);
const omap = new YAMLOMap();
omap.items = pairs.items;
return omap;
}
createNode: (schema, iterable, ctx) => YAMLOMap.from(schema, iterable, ctx)
};
export { YAMLOMap, omap };

View File

@@ -1,4 +1,4 @@
import { isSeq, isPair, isMap } from '../../nodes/Node.js';
import { isSeq, isPair, isMap } from '../../nodes/identity.js';
import { Pair, createPair } from '../../nodes/Pair.js';
import { Scalar } from '../../nodes/Scalar.js';
import { YAMLSeq } from '../../nodes/YAMLSeq.js';
@@ -56,8 +56,9 @@ function createPairs(schema, iterable, ctx) {
key = keys[0];
value = it[key];
}
else
throw new TypeError(`Expected { key: value } tuple: ${it}`);
else {
throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
}
}
else {
key = it;

View File

@@ -1,5 +1,5 @@
import { isMap, isPair, isScalar } from '../../nodes/Node.js';
import { createPair, Pair } from '../../nodes/Pair.js';
import { isMap, isPair, isScalar } from '../../nodes/identity.js';
import { Pair, createPair } from '../../nodes/Pair.js';
import { YAMLMap, findPair } from '../../nodes/YAMLMap.js';
class YAMLSet extends YAMLMap {
@@ -57,6 +57,17 @@ class YAMLSet extends YAMLMap {
else
throw new Error('Set items must all have null values');
}
static from(schema, iterable, ctx) {
const { replacer } = ctx;
const set = new this(schema);
if (iterable && Symbol.iterator in Object(iterable))
for (let value of iterable) {
if (typeof replacer === 'function')
value = replacer.call(iterable, value, value);
set.items.push(createPair(value, null, ctx));
}
return set;
}
}
YAMLSet.tag = 'tag:yaml.org,2002:set';
const set = {
@@ -65,6 +76,7 @@ const set = {
nodeClass: YAMLSet,
default: false,
tag: 'tag:yaml.org,2002:set',
createNode: (schema, iterable, ctx) => YAMLSet.from(schema, iterable, ctx),
resolve(map, onError) {
if (isMap(map)) {
if (map.hasAllNullValues(true))
@@ -75,17 +87,6 @@ const set = {
else
onError('Expected a mapping for this tag');
return map;
},
createNode(schema, iterable, ctx) {
const { replacer } = ctx;
const set = new YAMLSet(schema);
if (iterable && Symbol.iterator in Object(iterable))
for (let value of iterable) {
if (typeof replacer === 'function')
value = replacer.call(iterable, value, value);
set.items.push(createPair(value, null, ctx));
}
return set;
}
};

View File

@@ -43,7 +43,7 @@ function stringifySexagesimal(node) {
}
return (sign +
parts
.map(n => (n < 10 ? '0' + String(n) : String(n)))
.map(n => String(n).padStart(2, '0'))
.join(':')
.replace(/000000\d*$/, '') // % 60 may introduce error
);