update electron to v43

This commit is contained in:
olcxja 2026-07-09 22:38:33 +02:00
commit fb6c8b6ee9
5385 changed files with 513060 additions and 123058 deletions

View file

@ -1,7 +1,7 @@
JS-YAML - YAML 1.2 parser / writer for JavaScript
=================================================
[![CI](https://github.com/nodeca/js-yaml/workflows/CI/badge.svg?branch=master)](https://github.com/nodeca/js-yaml/actions)
[![CI](https://github.com/nodeca/js-yaml/actions/workflows/ci.yml/badge.svg)](https://github.com/nodeca/js-yaml/actions/workflows/ci.yml)
[![NPM version](https://img.shields.io/npm/v/js-yaml.svg)](https://www.npmjs.org/package/js-yaml)
__[Online Demo](https://nodeca.github.io/js-yaml/)__
@ -88,6 +88,11 @@ options:
https://www.yaml.org/spec/1.2/spec.html#id2804923
- `DEFAULT_SCHEMA` - all supported YAML types.
- `json` _(default: false)_ - compatibility with JSON.parse behaviour. If true, then duplicate keys in a mapping will override values rather than throwing an error.
- `maxDepth` _(default: 100)_ - limits nesting depth for collections (does not
take aliasees into account).
- `maxTotalMergeKeys` _(default: 10000)_ - limits the total number of keys
processed by merge (`<<`) across one `load()` / `loadAll()` call. Set to `-1`
to disable.
NOTE: This function **does not** understand multi-document sources, it throws
exception on those.
@ -226,22 +231,3 @@ moment of adding them.
``` javascript
{ "foo,bar": ["baz"], "[object Object]": ["baz", "baz"] }
```
Also, reading of properties on implicit block mapping keys is not supported yet.
So, the following YAML document cannot be loaded.
``` yaml
&anchor foo:
foo: bar
*anchor: duplicate key
baz: bat
*anchor: duplicate key
```
js-yaml for enterprise
----------------------
Available as part of the Tidelift Subscription
The maintainers of js-yaml and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-js-yaml?utm_source=npm-js-yaml&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

View file

@ -1,126 +1,117 @@
#!/usr/bin/env node
'use strict'
'use strict';
const fs = require('fs')
const argparse = require('argparse')
const yaml = require('..')
/*eslint-disable no-console*/
/// /////////////////////////////////////////////////////////////////////////////
var fs = require('fs');
var argparse = require('argparse');
var yaml = require('..');
////////////////////////////////////////////////////////////////////////////////
var cli = new argparse.ArgumentParser({
prog: 'js-yaml',
add_help: true
});
const cli = new argparse.ArgumentParser({
prog: 'js-yaml',
add_help: true
})
cli.add_argument('-v', '--version', {
action: 'version',
version: require('../package.json').version
});
})
cli.add_argument('-c', '--compact', {
help: 'Display errors in compact mode',
help: 'Display errors in compact mode',
action: 'store_true'
});
})
// deprecated (not needed after we removed output colors)
// option suppressed, but not completely removed for compatibility
cli.add_argument('-j', '--to-json', {
help: argparse.SUPPRESS,
dest: 'json',
help: argparse.SUPPRESS,
dest: 'json',
action: 'store_true'
});
})
cli.add_argument('-t', '--trace', {
help: 'Show stack trace on error',
help: 'Show stack trace on error',
action: 'store_true'
});
})
cli.add_argument('file', {
help: 'File to read, utf-8 encoded without BOM',
nargs: '?',
help: 'File to read, utf-8 encoded without BOM',
nargs: '?',
default: '-'
});
})
/// /////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
const options = cli.parse_args()
/// /////////////////////////////////////////////////////////////////////////////
var options = cli.parse_args();
////////////////////////////////////////////////////////////////////////////////
function readFile(filename, encoding, callback) {
function readFile (filename, encoding, callback) {
if (options.file === '-') {
// read from stdin
var chunks = [];
const chunks = []
process.stdin.on('data', function (chunk) {
chunks.push(chunk);
});
chunks.push(chunk)
})
process.stdin.on('end', function () {
return callback(null, Buffer.concat(chunks).toString(encoding));
});
return callback(null, Buffer.concat(chunks).toString(encoding))
})
} else {
fs.readFile(filename, encoding, callback);
fs.readFile(filename, encoding, callback)
}
}
readFile(options.file, 'utf8', function (error, input) {
var output, isYaml;
let output
let isYaml
if (error) {
if (error.code === 'ENOENT') {
console.error('File not found: ' + options.file);
process.exit(2);
console.error('File not found: ' + options.file)
process.exit(2)
}
console.error(
options.trace && error.stack ||
(options.trace && error.stack) ||
error.message ||
String(error));
String(error))
process.exit(1);
process.exit(1)
}
try {
output = JSON.parse(input);
isYaml = false;
output = JSON.parse(input)
isYaml = false
} catch (err) {
if (err instanceof SyntaxError) {
try {
output = [];
yaml.loadAll(input, function (doc) { output.push(doc); }, {});
isYaml = true;
if (output.length === 0) output = null;
else if (output.length === 1) output = output[0];
output = []
yaml.loadAll(input, function (doc) { output.push(doc) }, {})
isYaml = true
if (output.length === 0) output = null
else if (output.length === 1) output = output[0]
} catch (e) {
if (options.trace && err.stack) console.error(e.stack);
else console.error(e.toString(options.compact));
if (options.trace && err.stack) console.error(e.stack)
else console.error(e.toString(options.compact))
process.exit(1);
process.exit(1)
}
} else {
console.error(
options.trace && err.stack ||
(options.trace && err.stack) ||
err.message ||
String(err));
String(err))
process.exit(1);
process.exit(1)
}
}
if (isYaml) console.log(JSON.stringify(output, null, ' '));
else console.log(yaml.dump(output));
});
if (isYaml) console.log(JSON.stringify(output, null, ' '))
else console.log(yaml.dump(output))
})

File diff suppressed because it is too large Load diff

1
electron/node_modules/js-yaml/dist/js-yaml.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

1
electron/node_modules/js-yaml/dist/js-yaml.mjs.map generated vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,47 +1,44 @@
'use strict';
'use strict'
const loader = require('./lib/loader')
const dumper = require('./lib/dumper')
var loader = require('./lib/loader');
var dumper = require('./lib/dumper');
function renamed(from, to) {
function renamed (from, to) {
return function () {
throw new Error('Function yaml.' + from + ' is removed in js-yaml 4. ' +
'Use yaml.' + to + ' instead, which is now safe by default.');
};
'Use yaml.' + to + ' instead, which is now safe by default.')
}
}
module.exports.Type = require('./lib/type');
module.exports.Schema = require('./lib/schema');
module.exports.FAILSAFE_SCHEMA = require('./lib/schema/failsafe');
module.exports.JSON_SCHEMA = require('./lib/schema/json');
module.exports.CORE_SCHEMA = require('./lib/schema/core');
module.exports.DEFAULT_SCHEMA = require('./lib/schema/default');
module.exports.load = loader.load;
module.exports.loadAll = loader.loadAll;
module.exports.dump = dumper.dump;
module.exports.YAMLException = require('./lib/exception');
module.exports.Type = require('./lib/type')
module.exports.Schema = require('./lib/schema')
module.exports.FAILSAFE_SCHEMA = require('./lib/schema/failsafe')
module.exports.JSON_SCHEMA = require('./lib/schema/json')
module.exports.CORE_SCHEMA = require('./lib/schema/core')
module.exports.DEFAULT_SCHEMA = require('./lib/schema/default')
module.exports.load = loader.load
module.exports.loadAll = loader.loadAll
module.exports.dump = dumper.dump
module.exports.YAMLException = require('./lib/exception')
// Re-export all types in case user wants to create custom schema
module.exports.types = {
binary: require('./lib/type/binary'),
float: require('./lib/type/float'),
map: require('./lib/type/map'),
null: require('./lib/type/null'),
pairs: require('./lib/type/pairs'),
set: require('./lib/type/set'),
binary: require('./lib/type/binary'),
float: require('./lib/type/float'),
map: require('./lib/type/map'),
null: require('./lib/type/null'),
pairs: require('./lib/type/pairs'),
set: require('./lib/type/set'),
timestamp: require('./lib/type/timestamp'),
bool: require('./lib/type/bool'),
int: require('./lib/type/int'),
merge: require('./lib/type/merge'),
omap: require('./lib/type/omap'),
seq: require('./lib/type/seq'),
str: require('./lib/type/str')
};
bool: require('./lib/type/bool'),
int: require('./lib/type/int'),
merge: require('./lib/type/merge'),
omap: require('./lib/type/omap'),
seq: require('./lib/type/seq'),
str: require('./lib/type/str')
}
// Removed functions from JS-YAML 3.0.x
module.exports.safeLoad = renamed('safeLoad', 'load');
module.exports.safeLoadAll = renamed('safeLoadAll', 'loadAll');
module.exports.safeDump = renamed('safeDump', 'dump');
module.exports.safeLoad = renamed('safeLoad', 'load')
module.exports.safeLoadAll = renamed('safeLoadAll', 'loadAll')
module.exports.safeDump = renamed('safeDump', 'dump')

View file

@ -1,59 +1,50 @@
'use strict';
'use strict'
function isNothing(subject) {
return (typeof subject === 'undefined') || (subject === null);
function isNothing (subject) {
return (typeof subject === 'undefined') || (subject === null)
}
function isObject(subject) {
return (typeof subject === 'object') && (subject !== null);
function isObject (subject) {
return (typeof subject === 'object') && (subject !== null)
}
function toArray (sequence) {
if (Array.isArray(sequence)) return sequence
else if (isNothing(sequence)) return []
function toArray(sequence) {
if (Array.isArray(sequence)) return sequence;
else if (isNothing(sequence)) return [];
return [ sequence ];
return [sequence]
}
function extend(target, source) {
var index, length, key, sourceKeys;
function extend (target, source) {
if (source) {
sourceKeys = Object.keys(source);
const sourceKeys = Object.keys(source)
for (index = 0, length = sourceKeys.length; index < length; index += 1) {
key = sourceKeys[index];
target[key] = source[key];
for (let index = 0, length = sourceKeys.length; index < length; index += 1) {
const key = sourceKeys[index]
target[key] = source[key]
}
}
return target;
return target
}
function repeat (string, count) {
let result = ''
function repeat(string, count) {
var result = '', cycle;
for (cycle = 0; cycle < count; cycle += 1) {
result += string;
for (let cycle = 0; cycle < count; cycle += 1) {
result += string
}
return result;
return result
}
function isNegativeZero(number) {
return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
function isNegativeZero (number) {
return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number)
}
module.exports.isNothing = isNothing;
module.exports.isObject = isObject;
module.exports.toArray = toArray;
module.exports.repeat = repeat;
module.exports.isNegativeZero = isNegativeZero;
module.exports.extend = extend;
module.exports.isNothing = isNothing
module.exports.isObject = isObject
module.exports.toArray = toArray
module.exports.repeat = repeat
module.exports.isNegativeZero = isNegativeZero
module.exports.extend = extend

File diff suppressed because it is too large Load diff

View file

@ -1,55 +1,51 @@
// YAML error class. http://stackoverflow.com/questions/8458984
//
'use strict';
'use strict'
function formatError (exception, compact) {
let where = ''
const message = exception.reason || '(unknown reason)'
function formatError(exception, compact) {
var where = '', message = exception.reason || '(unknown reason)';
if (!exception.mark) return message;
if (!exception.mark) return message
if (exception.mark.name) {
where += 'in "' + exception.mark.name + '" ';
where += 'in "' + exception.mark.name + '" '
}
where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')';
where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')'
if (!compact && exception.mark.snippet) {
where += '\n\n' + exception.mark.snippet;
where += '\n\n' + exception.mark.snippet
}
return message + ' ' + where;
return message + ' ' + where
}
function YAMLException(reason, mark) {
function YAMLException (reason, mark) {
// Super constructor
Error.call(this);
Error.call(this)
this.name = 'YAMLException';
this.reason = reason;
this.mark = mark;
this.message = formatError(this, false);
this.name = 'YAMLException'
this.reason = reason
this.mark = mark
this.message = formatError(this, false)
// Include stack trace in error object
if (Error.captureStackTrace) {
// Chrome and NodeJS
Error.captureStackTrace(this, this.constructor);
Error.captureStackTrace(this, this.constructor)
} else {
// FF, IE 10+ and Safari 6+. Fallback for others
this.stack = (new Error()).stack || '';
this.stack = (new Error()).stack || ''
}
}
// Inherit from Error
YAMLException.prototype = Object.create(Error.prototype);
YAMLException.prototype.constructor = YAMLException;
YAMLException.prototype = Object.create(Error.prototype)
YAMLException.prototype.constructor = YAMLException
YAMLException.prototype.toString = function toString (compact) {
return this.name + ': ' + formatError(this, compact)
}
YAMLException.prototype.toString = function toString(compact) {
return this.name + ': ' + formatError(this, compact);
};
module.exports = YAMLException;
module.exports = YAMLException

View file

@ -0,0 +1,37 @@
import yaml from '../index.js'
const {
Type,
Schema,
FAILSAFE_SCHEMA,
JSON_SCHEMA,
CORE_SCHEMA,
DEFAULT_SCHEMA,
load,
loadAll,
dump,
YAMLException,
types,
safeLoad,
safeLoadAll,
safeDump
} = yaml
export {
Type,
Schema,
FAILSAFE_SCHEMA,
JSON_SCHEMA,
CORE_SCHEMA,
DEFAULT_SCHEMA,
load,
loadAll,
dump,
YAMLException,
types,
safeLoad,
safeLoadAll,
safeDump
}
export default yaml

File diff suppressed because it is too large Load diff

View file

@ -1,121 +1,109 @@
'use strict';
'use strict'
/*eslint-disable max-len*/
const YAMLException = require('./exception')
const Type = require('./type')
var YAMLException = require('./exception');
var Type = require('./type');
function compileList(schema, name) {
var result = [];
function compileList (schema, name) {
const result = []
schema[name].forEach(function (currentType) {
var newIndex = result.length;
let newIndex = result.length
result.forEach(function (previousType, previousIndex) {
if (previousType.tag === currentType.tag &&
previousType.kind === currentType.kind &&
previousType.multi === currentType.multi) {
newIndex = previousIndex;
newIndex = previousIndex
}
});
})
result[newIndex] = currentType;
});
result[newIndex] = currentType
})
return result;
return result
}
function compileMap(/* lists... */) {
var result = {
scalar: {},
sequence: {},
mapping: {},
fallback: {},
multi: {
scalar: [],
sequence: [],
mapping: [],
fallback: []
}
}, index, length;
function collectType(type) {
function compileMap (/* lists... */) {
const result = {
scalar: {},
sequence: {},
mapping: {},
fallback: {},
multi: {
scalar: [],
sequence: [],
mapping: [],
fallback: []
}
}
function collectType (type) {
if (type.multi) {
result.multi[type.kind].push(type);
result.multi['fallback'].push(type);
result.multi[type.kind].push(type)
result.multi['fallback'].push(type)
} else {
result[type.kind][type.tag] = result['fallback'][type.tag] = type;
result[type.kind][type.tag] = result['fallback'][type.tag] = type
}
}
for (index = 0, length = arguments.length; index < length; index += 1) {
arguments[index].forEach(collectType);
for (let index = 0, length = arguments.length; index < length; index += 1) {
arguments[index].forEach(collectType)
}
return result;
return result
}
function Schema(definition) {
return this.extend(definition);
function Schema (definition) {
return this.extend(definition)
}
Schema.prototype.extend = function extend(definition) {
var implicit = [];
var explicit = [];
Schema.prototype.extend = function extend (definition) {
let implicit = []
let explicit = []
if (definition instanceof Type) {
// Schema.extend(type)
explicit.push(definition);
explicit.push(definition)
} else if (Array.isArray(definition)) {
// Schema.extend([ type1, type2, ... ])
explicit = explicit.concat(definition);
explicit = explicit.concat(definition)
} else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
// Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] })
if (definition.implicit) implicit = implicit.concat(definition.implicit);
if (definition.explicit) explicit = explicit.concat(definition.explicit);
if (definition.implicit) implicit = implicit.concat(definition.implicit)
if (definition.explicit) explicit = explicit.concat(definition.explicit)
} else {
throw new YAMLException('Schema.extend argument should be a Type, [ Type ], ' +
'or a schema definition ({ implicit: [...], explicit: [...] })');
'or a schema definition ({ implicit: [...], explicit: [...] })')
}
implicit.forEach(function (type) {
if (!(type instanceof Type)) {
throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.');
throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.')
}
if (type.loadKind && type.loadKind !== 'scalar') {
throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.')
}
if (type.multi) {
throw new YAMLException('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.');
throw new YAMLException('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.')
}
});
})
explicit.forEach(function (type) {
if (!(type instanceof Type)) {
throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.');
throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.')
}
});
})
var result = Object.create(Schema.prototype);
const result = Object.create(Schema.prototype)
result.implicit = (this.implicit || []).concat(implicit);
result.explicit = (this.explicit || []).concat(explicit);
result.implicit = (this.implicit || []).concat(implicit)
result.explicit = (this.explicit || []).concat(explicit)
result.compiledImplicit = compileList(result, 'implicit');
result.compiledExplicit = compileList(result, 'explicit');
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
result.compiledImplicit = compileList(result, 'implicit')
result.compiledExplicit = compileList(result, 'explicit')
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit)
return result;
};
return result
}
module.exports = Schema;
module.exports = Schema

View file

@ -4,8 +4,6 @@
// NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
// So, Core schema has no distinctions from JSON schema is JS-YAML.
'use strict'
'use strict';
module.exports = require('./json');
module.exports = require('./json')

View file

@ -4,9 +4,7 @@
// This schema is based on standard YAML's Core schema and includes most of
// extra types described at YAML tag repository. (http://yaml.org/type/)
'use strict';
'use strict'
module.exports = require('./core').extend({
implicit: [
@ -19,4 +17,4 @@ module.exports = require('./core').extend({
require('../type/pairs'),
require('../type/set')
]
});
})

View file

@ -1,12 +1,9 @@
// Standard YAML's Failsafe schema.
// http://www.yaml.org/spec/1.2/spec.html#id2802346
'use strict'
'use strict';
var Schema = require('../schema');
const Schema = require('../schema')
module.exports = new Schema({
explicit: [
@ -14,4 +11,4 @@ module.exports = new Schema({
require('../type/seq'),
require('../type/map')
]
});
})

View file

@ -5,9 +5,7 @@
// So, this schema is not such strict as defined in the YAML specification.
// It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
'use strict';
'use strict'
module.exports = require('./failsafe').extend({
implicit: [
@ -16,4 +14,4 @@ module.exports = require('./failsafe').extend({
require('../type/int'),
require('../type/float')
]
});
})

View file

@ -1,101 +1,96 @@
'use strict';
var common = require('./common');
'use strict'
const common = require('./common')
// get snippet for a single line, respecting maxLength
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
var head = '';
var tail = '';
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
function getLine (buffer, lineStart, lineEnd, position, maxLineLength) {
let head = ''
let tail = ''
const maxHalfLength = Math.floor(maxLineLength / 2) - 1
if (position - lineStart > maxHalfLength) {
head = ' ... ';
lineStart = position - maxHalfLength + head.length;
head = ' ... '
lineStart = position - maxHalfLength + head.length
}
if (lineEnd - position > maxHalfLength) {
tail = ' ...';
lineEnd = position + maxHalfLength - tail.length;
tail = ' ...'
lineEnd = position + maxHalfLength - tail.length
}
return {
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
pos: position - lineStart + head.length // relative position
};
}
}
function padStart(string, max) {
return common.repeat(' ', max - string.length) + string;
function padStart (string, max) {
return common.repeat(' ', max - string.length) + string
}
function makeSnippet (mark, options) {
options = Object.create(options || null)
function makeSnippet(mark, options) {
options = Object.create(options || null);
if (!mark.buffer) return null
if (!mark.buffer) return null;
if (!options.maxLength) options.maxLength = 79
if (typeof options.indent !== 'number') options.indent = 1
if (typeof options.linesBefore !== 'number') options.linesBefore = 3
if (typeof options.linesAfter !== 'number') options.linesAfter = 2
if (!options.maxLength) options.maxLength = 79;
if (typeof options.indent !== 'number') options.indent = 1;
if (typeof options.linesBefore !== 'number') options.linesBefore = 3;
if (typeof options.linesAfter !== 'number') options.linesAfter = 2;
var re = /\r?\n|\r|\0/g;
var lineStarts = [ 0 ];
var lineEnds = [];
var match;
var foundLineNo = -1;
const re = /\r?\n|\r|\0/g
const lineStarts = [0]
const lineEnds = []
let match
let foundLineNo = -1
while ((match = re.exec(mark.buffer))) {
lineEnds.push(match.index);
lineStarts.push(match.index + match[0].length);
lineEnds.push(match.index)
lineStarts.push(match.index + match[0].length)
if (mark.position <= match.index && foundLineNo < 0) {
foundLineNo = lineStarts.length - 2;
foundLineNo = lineStarts.length - 2
}
}
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1
var result = '', i, line;
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
let result = ''
const lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length
const maxLineLength = options.maxLength - (options.indent + lineNoLength + 3)
for (i = 1; i <= options.linesBefore; i++) {
if (foundLineNo - i < 0) break;
line = getLine(
for (let i = 1; i <= options.linesBefore; i++) {
if (foundLineNo - i < 0) break
const line = getLine(
mark.buffer,
lineStarts[foundLineNo - i],
lineEnds[foundLineNo - i],
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
maxLineLength
);
)
result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) +
' | ' + line.str + '\n' + result;
' | ' + line.str + '\n' + result
}
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
const line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength)
result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) +
' | ' + line.str + '\n';
result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n';
' | ' + line.str + '\n'
result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n'
for (i = 1; i <= options.linesAfter; i++) {
if (foundLineNo + i >= lineEnds.length) break;
line = getLine(
for (let i = 1; i <= options.linesAfter; i++) {
if (foundLineNo + i >= lineEnds.length) break
const line = getLine(
mark.buffer,
lineStarts[foundLineNo + i],
lineEnds[foundLineNo + i],
mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
maxLineLength
);
)
result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) +
' | ' + line.str + '\n';
' | ' + line.str + '\n'
}
return result.replace(/\n$/, '');
return result.replace(/\n$/, '')
}
module.exports = makeSnippet;
module.exports = makeSnippet

View file

@ -1,8 +1,8 @@
'use strict';
'use strict'
var YAMLException = require('./exception');
const YAMLException = require('./exception')
var TYPE_CONSTRUCTOR_OPTIONS = [
const TYPE_CONSTRUCTOR_OPTIONS = [
'kind',
'multi',
'resolve',
@ -13,54 +13,54 @@ var TYPE_CONSTRUCTOR_OPTIONS = [
'representName',
'defaultStyle',
'styleAliases'
];
]
var YAML_NODE_KINDS = [
const YAML_NODE_KINDS = [
'scalar',
'sequence',
'mapping'
];
]
function compileStyleAliases(map) {
var result = {};
function compileStyleAliases (map) {
const result = {}
if (map !== null) {
Object.keys(map).forEach(function (style) {
map[style].forEach(function (alias) {
result[String(alias)] = style;
});
});
result[String(alias)] = style
})
})
}
return result;
return result
}
function Type(tag, options) {
options = options || {};
function Type (tag, options) {
options = options || {}
Object.keys(options).forEach(function (name) {
if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.')
}
});
})
// TODO: Add tag format check.
this.options = options; // keep original options in case user wants to extend this type later
this.tag = tag;
this.kind = options['kind'] || null;
this.resolve = options['resolve'] || function () { return true; };
this.construct = options['construct'] || function (data) { return data; };
this.instanceOf = options['instanceOf'] || null;
this.predicate = options['predicate'] || null;
this.represent = options['represent'] || null;
this.representName = options['representName'] || null;
this.defaultStyle = options['defaultStyle'] || null;
this.multi = options['multi'] || false;
this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
this.options = options // keep original options in case user wants to extend this type later
this.tag = tag
this.kind = options['kind'] || null
this.resolve = options['resolve'] || function () { return true }
this.construct = options['construct'] || function (data) { return data }
this.instanceOf = options['instanceOf'] || null
this.predicate = options['predicate'] || null
this.represent = options['represent'] || null
this.representName = options['representName'] || null
this.defaultStyle = options['defaultStyle'] || null
this.multi = options['multi'] || false
this.styleAliases = compileStyleAliases(options['styleAliases'] || null)
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.')
}
}
module.exports = Type;
module.exports = Type

View file

@ -1,119 +1,116 @@
'use strict';
/*eslint-disable no-bitwise*/
var Type = require('../type');
'use strict'
const Type = require('../type')
// [ 64, 65, 66 ] -> [ padding, CR, LF ]
var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
const BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r'
function resolveYamlBinary (data) {
if (data === null) return false
function resolveYamlBinary(data) {
if (data === null) return false;
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
let bitlen = 0
const max = data.length
const map = BASE64_MAP
// Convert one by one.
for (idx = 0; idx < max; idx++) {
code = map.indexOf(data.charAt(idx));
for (let idx = 0; idx < max; idx++) {
const code = map.indexOf(data.charAt(idx))
// Skip CR/LF
if (code > 64) continue;
if (code > 64) continue
// Fail on illegal characters
if (code < 0) return false;
if (code < 0) return false
bitlen += 6;
bitlen += 6
}
// If there are any bits left, source was corrupted
return (bitlen % 8) === 0;
return (bitlen % 8) === 0
}
function constructYamlBinary(data) {
var idx, tailbits,
input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
max = input.length,
map = BASE64_MAP,
bits = 0,
result = [];
function constructYamlBinary (data) {
const input = data.replace(/[\r\n=]/g, '') // remove CR/LF & padding to simplify scan
const max = input.length
const map = BASE64_MAP
let bits = 0
const result = []
// Collect by 6*4 bits (3 bytes)
for (idx = 0; idx < max; idx++) {
for (let idx = 0; idx < max; idx++) {
if ((idx % 4 === 0) && idx) {
result.push((bits >> 16) & 0xFF);
result.push((bits >> 8) & 0xFF);
result.push(bits & 0xFF);
result.push((bits >> 16) & 0xFF)
result.push((bits >> 8) & 0xFF)
result.push(bits & 0xFF)
}
bits = (bits << 6) | map.indexOf(input.charAt(idx));
bits = (bits << 6) | map.indexOf(input.charAt(idx))
}
// Dump tail
tailbits = (max % 4) * 6;
const tailbits = (max % 4) * 6
if (tailbits === 0) {
result.push((bits >> 16) & 0xFF);
result.push((bits >> 8) & 0xFF);
result.push(bits & 0xFF);
result.push((bits >> 16) & 0xFF)
result.push((bits >> 8) & 0xFF)
result.push(bits & 0xFF)
} else if (tailbits === 18) {
result.push((bits >> 10) & 0xFF);
result.push((bits >> 2) & 0xFF);
result.push((bits >> 10) & 0xFF)
result.push((bits >> 2) & 0xFF)
} else if (tailbits === 12) {
result.push((bits >> 4) & 0xFF);
result.push((bits >> 4) & 0xFF)
}
return new Uint8Array(result);
return new Uint8Array(result)
}
function representYamlBinary(object /*, style*/) {
var result = '', bits = 0, idx, tail,
max = object.length,
map = BASE64_MAP;
function representYamlBinary (object /*, style */) {
let result = ''
let bits = 0
const max = object.length
const map = BASE64_MAP
// Convert every three bytes to 4 ASCII characters.
for (idx = 0; idx < max; idx++) {
for (let idx = 0; idx < max; idx++) {
if ((idx % 3 === 0) && idx) {
result += map[(bits >> 18) & 0x3F];
result += map[(bits >> 12) & 0x3F];
result += map[(bits >> 6) & 0x3F];
result += map[bits & 0x3F];
result += map[(bits >> 18) & 0x3F]
result += map[(bits >> 12) & 0x3F]
result += map[(bits >> 6) & 0x3F]
result += map[bits & 0x3F]
}
bits = (bits << 8) + object[idx];
bits = (bits << 8) + object[idx]
}
// Dump tail
tail = max % 3;
const tail = max % 3
if (tail === 0) {
result += map[(bits >> 18) & 0x3F];
result += map[(bits >> 12) & 0x3F];
result += map[(bits >> 6) & 0x3F];
result += map[bits & 0x3F];
result += map[(bits >> 18) & 0x3F]
result += map[(bits >> 12) & 0x3F]
result += map[(bits >> 6) & 0x3F]
result += map[bits & 0x3F]
} else if (tail === 2) {
result += map[(bits >> 10) & 0x3F];
result += map[(bits >> 4) & 0x3F];
result += map[(bits << 2) & 0x3F];
result += map[64];
result += map[(bits >> 10) & 0x3F]
result += map[(bits >> 4) & 0x3F]
result += map[(bits << 2) & 0x3F]
result += map[64]
} else if (tail === 1) {
result += map[(bits >> 2) & 0x3F];
result += map[(bits << 4) & 0x3F];
result += map[64];
result += map[64];
result += map[(bits >> 2) & 0x3F]
result += map[(bits << 4) & 0x3F]
result += map[64]
result += map[64]
}
return result;
return result
}
function isBinary(obj) {
return Object.prototype.toString.call(obj) === '[object Uint8Array]';
function isBinary (obj) {
return Object.prototype.toString.call(obj) === '[object Uint8Array]'
}
module.exports = new Type('tag:yaml.org,2002:binary', {
@ -122,4 +119,4 @@ module.exports = new Type('tag:yaml.org,2002:binary', {
construct: constructYamlBinary,
predicate: isBinary,
represent: representYamlBinary
});
})

View file

@ -1,24 +1,24 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
function resolveYamlBoolean(data) {
if (data === null) return false;
function resolveYamlBoolean (data) {
if (data === null) return false
var max = data.length;
const max = data.length
return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
(max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'))
}
function constructYamlBoolean(data) {
function constructYamlBoolean (data) {
return data === 'true' ||
data === 'True' ||
data === 'TRUE';
data === 'TRUE'
}
function isBoolean(object) {
return Object.prototype.toString.call(object) === '[object Boolean]';
function isBoolean (object) {
return Object.prototype.toString.call(object) === '[object Boolean]'
}
module.exports = new Type('tag:yaml.org,2002:bool', {
@ -27,9 +27,9 @@ module.exports = new Type('tag:yaml.org,2002:bool', {
construct: constructYamlBoolean,
predicate: isBoolean,
represent: {
lowercase: function (object) { return object ? 'true' : 'false'; },
uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
camelcase: function (object) { return object ? 'True' : 'False'; }
lowercase: function (object) { return object ? 'true' : 'false' },
uppercase: function (object) { return object ? 'TRUE' : 'FALSE' },
camelcase: function (object) { return object ? 'True' : 'False' }
},
defaultStyle: 'lowercase'
});
})

View file

@ -1,90 +1,92 @@
'use strict';
'use strict'
var common = require('../common');
var Type = require('../type');
const common = require('../common')
const Type = require('../type')
var YAML_FLOAT_PATTERN = new RegExp(
const YAML_FLOAT_PATTERN = new RegExp(
// 2.5e4, 2.5 and integers
'^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
'^(?:[-+]?(?:[0-9]+)(?:\\.[0-9]*)?(?:[eE][-+]?[0-9]+)?' +
// .2e4, .2
// special case, seems not from spec
'|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
'|\\.[0-9]+(?:[eE][-+]?[0-9]+)?' +
// .inf
'|[-+]?\\.(?:inf|Inf|INF)' +
// .nan
'|\\.(?:nan|NaN|NAN))$');
'|\\.(?:nan|NaN|NAN))$')
function resolveYamlFloat(data) {
if (data === null) return false;
const YAML_FLOAT_SPECIAL_PATTERN = new RegExp(
'^(?:' +
// .inf
'[-+]?\\.(?:inf|Inf|INF)' +
// .nan
'|\\.(?:nan|NaN|NAN))$')
if (!YAML_FLOAT_PATTERN.test(data) ||
// Quick hack to not allow integers end with `_`
// Probably should update regexp & check speed
data[data.length - 1] === '_') {
return false;
function resolveYamlFloat (data) {
if (data === null) return false
if (!YAML_FLOAT_PATTERN.test(data)) {
return false
}
return true;
if (isFinite(parseFloat(data, 10))) {
return true
}
return YAML_FLOAT_SPECIAL_PATTERN.test(data)
}
function constructYamlFloat(data) {
var value, sign;
value = data.replace(/_/g, '').toLowerCase();
sign = value[0] === '-' ? -1 : 1;
function constructYamlFloat (data) {
let value = data.toLowerCase()
const sign = value[0] === '-' ? -1 : 1
if ('+-'.indexOf(value[0]) >= 0) {
value = value.slice(1);
value = value.slice(1)
}
if (value === '.inf') {
return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY
} else if (value === '.nan') {
return NaN;
return NaN
}
return sign * parseFloat(value, 10);
return sign * parseFloat(value, 10)
}
const SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/
var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
function representYamlFloat(object, style) {
var res;
function representYamlFloat (object, style) {
if (isNaN(object)) {
switch (style) {
case 'lowercase': return '.nan';
case 'uppercase': return '.NAN';
case 'camelcase': return '.NaN';
case 'lowercase': return '.nan'
case 'uppercase': return '.NAN'
case 'camelcase': return '.NaN'
}
} else if (Number.POSITIVE_INFINITY === object) {
switch (style) {
case 'lowercase': return '.inf';
case 'uppercase': return '.INF';
case 'camelcase': return '.Inf';
case 'lowercase': return '.inf'
case 'uppercase': return '.INF'
case 'camelcase': return '.Inf'
}
} else if (Number.NEGATIVE_INFINITY === object) {
switch (style) {
case 'lowercase': return '-.inf';
case 'uppercase': return '-.INF';
case 'camelcase': return '-.Inf';
case 'lowercase': return '-.inf'
case 'uppercase': return '-.INF'
case 'camelcase': return '-.Inf'
}
} else if (common.isNegativeZero(object)) {
return '-0.0';
return '-0.0'
}
res = object.toString(10);
const res = object.toString(10)
// JS stringifier can build scientific format without dots: 5e-100,
// while YAML requres dot: 5.e-100. Fix it with simple hack
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res
}
function isFloat(object) {
function isFloat (object) {
return (Object.prototype.toString.call(object) === '[object Number]') &&
(object % 1 !== 0 || common.isNegativeZero(object));
(object % 1 !== 0 || common.isNegativeZero(object))
}
module.exports = new Type('tag:yaml.org,2002:float', {
@ -94,4 +96,4 @@ module.exports = new Type('tag:yaml.org,2002:float', {
predicate: isFloat,
represent: representYamlFloat,
defaultStyle: 'lowercase'
});
})

View file

@ -1,137 +1,124 @@
'use strict';
'use strict'
var common = require('../common');
var Type = require('../type');
const common = require('../common')
const Type = require('../type')
function isHexCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
((0x61/* a */ <= c) && (c <= 0x66/* f */));
function isHexCode (c) {
return ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */)) ||
((c >= 0x41/* A */) && (c <= 0x46/* F */)) ||
((c >= 0x61/* a */) && (c <= 0x66/* f */))
}
function isOctCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
function isOctCode (c) {
return ((c >= 0x30/* 0 */) && (c <= 0x37/* 7 */))
}
function isDecCode(c) {
return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
function isDecCode (c) {
return ((c >= 0x30/* 0 */) && (c <= 0x39/* 9 */))
}
function resolveYamlInteger(data) {
if (data === null) return false;
function resolveYamlInteger (data) {
if (data === null) return false
var max = data.length,
index = 0,
hasDigits = false,
ch;
const max = data.length
let index = 0
let hasDigits = false
if (!max) return false;
if (!max) return false
ch = data[index];
let ch = data[index]
// sign
if (ch === '-' || ch === '+') {
ch = data[++index];
ch = data[++index]
}
if (ch === '0') {
// 0
if (index + 1 === max) return true;
ch = data[++index];
if (index + 1 === max) return true
ch = data[++index]
// base 2, base 8, base 16
if (ch === 'b') {
// base 2
index++;
index++
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (ch !== '0' && ch !== '1') return false;
hasDigits = true;
ch = data[index]
if (ch !== '0' && ch !== '1') return false
hasDigits = true
}
return hasDigits && ch !== '_';
return hasDigits && isFinite(parseYamlInteger(data))
}
if (ch === 'x') {
// base 16
index++;
index++
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (!isHexCode(data.charCodeAt(index))) return false;
hasDigits = true;
if (!isHexCode(data.charCodeAt(index))) return false
hasDigits = true
}
return hasDigits && ch !== '_';
return hasDigits && isFinite(parseYamlInteger(data))
}
if (ch === 'o') {
// base 8
index++;
index++
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (!isOctCode(data.charCodeAt(index))) return false;
hasDigits = true;
if (!isOctCode(data.charCodeAt(index))) return false
hasDigits = true
}
return hasDigits && ch !== '_';
return hasDigits && isFinite(parseYamlInteger(data))
}
}
// base 10 (except 0)
// value should not start with `_`;
if (ch === '_') return false;
for (; index < max; index++) {
ch = data[index];
if (ch === '_') continue;
if (!isDecCode(data.charCodeAt(index))) {
return false;
return false
}
hasDigits = true;
hasDigits = true
}
// Should have digits and should not end with `_`
if (!hasDigits || ch === '_') return false;
if (!hasDigits) return false
return true;
return isFinite(parseYamlInteger(data))
}
function constructYamlInteger(data) {
var value = data, sign = 1, ch;
function parseYamlInteger (data) {
let value = data
let sign = 1
if (value.indexOf('_') !== -1) {
value = value.replace(/_/g, '');
}
ch = value[0];
let ch = value[0]
if (ch === '-' || ch === '+') {
if (ch === '-') sign = -1;
value = value.slice(1);
ch = value[0];
if (ch === '-') sign = -1
value = value.slice(1)
ch = value[0]
}
if (value === '0') return 0;
if (value === '0') return 0
if (ch === '0') {
if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
if (value[1] === 'x') return sign * parseInt(value.slice(2), 16);
if (value[1] === 'o') return sign * parseInt(value.slice(2), 8);
if (value[1] === 'b') return sign * parseInt(value.slice(2), 2)
if (value[1] === 'x') return sign * parseInt(value.slice(2), 16)
if (value[1] === 'o') return sign * parseInt(value.slice(2), 8)
}
return sign * parseInt(value, 10);
return sign * parseInt(value, 10)
}
function isInteger(object) {
function constructYamlInteger (data) {
return parseYamlInteger(data)
}
function isInteger (object) {
return (Object.prototype.toString.call(object)) === '[object Number]' &&
(object % 1 === 0 && !common.isNegativeZero(object));
(object % 1 === 0 && !common.isNegativeZero(object))
}
module.exports = new Type('tag:yaml.org,2002:int', {
@ -140,17 +127,16 @@ module.exports = new Type('tag:yaml.org,2002:int', {
construct: constructYamlInteger,
predicate: isInteger,
represent: {
binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); },
decimal: function (obj) { return obj.toString(10); },
/* eslint-disable max-len */
hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1) },
octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1) },
decimal: function (obj) { return obj.toString(10) },
hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1) }
},
defaultStyle: 'decimal',
styleAliases: {
binary: [ 2, 'bin' ],
octal: [ 8, 'oct' ],
decimal: [ 10, 'dec' ],
hexadecimal: [ 16, 'hex' ]
binary: [2, 'bin'],
octal: [8, 'oct'],
decimal: [10, 'dec'],
hexadecimal: [16, 'hex']
}
});
})

View file

@ -1,8 +1,8 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
module.exports = new Type('tag:yaml.org,2002:map', {
kind: 'mapping',
construct: function (data) { return data !== null ? data : {}; }
});
construct: function (data) { return data !== null ? data : {} }
})

View file

@ -1,12 +1,12 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
function resolveYamlMerge(data) {
return data === '<<' || data === null;
function resolveYamlMerge (data) {
return data === '<<' || data === null
}
module.exports = new Type('tag:yaml.org,2002:merge', {
kind: 'scalar',
resolve: resolveYamlMerge
});
})

View file

@ -1,22 +1,22 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
function resolveYamlNull(data) {
if (data === null) return true;
function resolveYamlNull (data) {
if (data === null) return true
var max = data.length;
const max = data.length
return (max === 1 && data === '~') ||
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
(max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'))
}
function constructYamlNull() {
return null;
function constructYamlNull () {
return null
}
function isNull(object) {
return object === null;
function isNull (object) {
return object === null
}
module.exports = new Type('tag:yaml.org,2002:null', {
@ -25,11 +25,11 @@ module.exports = new Type('tag:yaml.org,2002:null', {
construct: constructYamlNull,
predicate: isNull,
represent: {
canonical: function () { return '~'; },
lowercase: function () { return 'null'; },
uppercase: function () { return 'NULL'; },
camelcase: function () { return 'Null'; },
empty: function () { return ''; }
canonical: function () { return '~' },
lowercase: function () { return 'null' },
uppercase: function () { return 'NULL' },
camelcase: function () { return 'Null' },
empty: function () { return '' }
},
defaultStyle: 'lowercase'
});
})

View file

@ -1,44 +1,45 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
var _hasOwnProperty = Object.prototype.hasOwnProperty;
var _toString = Object.prototype.toString;
const _hasOwnProperty = Object.prototype.hasOwnProperty
const _toString = Object.prototype.toString
function resolveYamlOmap(data) {
if (data === null) return true;
function resolveYamlOmap (data) {
if (data === null) return true
var objectKeys = [], index, length, pair, pairKey, pairHasKey,
object = data;
const objectKeys = []
const object = data
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
pairHasKey = false;
for (let index = 0, length = object.length; index < length; index += 1) {
const pair = object[index]
let pairHasKey = false
if (_toString.call(pair) !== '[object Object]') return false;
if (_toString.call(pair) !== '[object Object]') return false
let pairKey
for (pairKey in pair) {
if (_hasOwnProperty.call(pair, pairKey)) {
if (!pairHasKey) pairHasKey = true;
else return false;
if (!pairHasKey) pairHasKey = true
else return false
}
}
if (!pairHasKey) return false;
if (!pairHasKey) return false
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
else return false;
if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey)
else return false
}
return true;
return true
}
function constructYamlOmap(data) {
return data !== null ? data : [];
function constructYamlOmap (data) {
return data !== null ? data : []
}
module.exports = new Type('tag:yaml.org,2002:omap', {
kind: 'sequence',
resolve: resolveYamlOmap,
construct: constructYamlOmap
});
})

View file

@ -1,53 +1,50 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
var _toString = Object.prototype.toString;
const _toString = Object.prototype.toString
function resolveYamlPairs(data) {
if (data === null) return true;
function resolveYamlPairs (data) {
if (data === null) return true
var index, length, pair, keys, result,
object = data;
const object = data
result = new Array(object.length);
const result = new Array(object.length)
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
for (let index = 0, length = object.length; index < length; index += 1) {
const pair = object[index]
if (_toString.call(pair) !== '[object Object]') return false;
if (_toString.call(pair) !== '[object Object]') return false
keys = Object.keys(pair);
const keys = Object.keys(pair)
if (keys.length !== 1) return false;
if (keys.length !== 1) return false
result[index] = [ keys[0], pair[keys[0]] ];
result[index] = [keys[0], pair[keys[0]]]
}
return true;
return true
}
function constructYamlPairs(data) {
if (data === null) return [];
function constructYamlPairs (data) {
if (data === null) return []
var index, length, pair, keys, result,
object = data;
const object = data
const result = new Array(object.length)
result = new Array(object.length);
for (let index = 0, length = object.length; index < length; index += 1) {
const pair = object[index]
for (index = 0, length = object.length; index < length; index += 1) {
pair = object[index];
const keys = Object.keys(pair)
keys = Object.keys(pair);
result[index] = [ keys[0], pair[keys[0]] ];
result[index] = [keys[0], pair[keys[0]]]
}
return result;
return result
}
module.exports = new Type('tag:yaml.org,2002:pairs', {
kind: 'sequence',
resolve: resolveYamlPairs,
construct: constructYamlPairs
});
})

View file

@ -1,8 +1,8 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
module.exports = new Type('tag:yaml.org,2002:seq', {
kind: 'sequence',
construct: function (data) { return data !== null ? data : []; }
});
construct: function (data) { return data !== null ? data : [] }
})

View file

@ -1,29 +1,29 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
var _hasOwnProperty = Object.prototype.hasOwnProperty;
const _hasOwnProperty = Object.prototype.hasOwnProperty
function resolveYamlSet(data) {
if (data === null) return true;
function resolveYamlSet (data) {
if (data === null) return true
var key, object = data;
const object = data
for (key in object) {
for (const key in object) {
if (_hasOwnProperty.call(object, key)) {
if (object[key] !== null) return false;
if (object[key] !== null) return false
}
}
return true;
return true
}
function constructYamlSet(data) {
return data !== null ? data : {};
function constructYamlSet (data) {
return data !== null ? data : {}
}
module.exports = new Type('tag:yaml.org,2002:set', {
kind: 'mapping',
resolve: resolveYamlSet,
construct: constructYamlSet
});
})

View file

@ -1,8 +1,8 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
module.exports = new Type('tag:yaml.org,2002:str', {
kind: 'scalar',
construct: function (data) { return data !== null ? data : ''; }
});
construct: function (data) { return data !== null ? data : '' }
})

View file

@ -1,82 +1,82 @@
'use strict';
'use strict'
var Type = require('../type');
const Type = require('../type')
var YAML_DATE_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9])' + // [2] month
'-([0-9][0-9])$'); // [3] day
const YAML_DATE_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9])' + // [2] month
'-([0-9][0-9])$') // [3] day
var YAML_TIMESTAMP_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9]?)' + // [2] month
'-([0-9][0-9]?)' + // [3] day
'(?:[Tt]|[ \\t]+)' + // ...
'([0-9][0-9]?)' + // [4] hour
':([0-9][0-9])' + // [5] minute
':([0-9][0-9])' + // [6] second
'(?:\\.([0-9]*))?' + // [7] fraction
'(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
'(?::([0-9][0-9]))?))?$'); // [11] tz_minute
const YAML_TIMESTAMP_REGEXP = new RegExp(
'^([0-9][0-9][0-9][0-9])' + // [1] year
'-([0-9][0-9]?)' + // [2] month
'-([0-9][0-9]?)' + // [3] day
'(?:[Tt]|[ \\t]+)' + // ...
'([0-9][0-9]?)' + // [4] hour
':([0-9][0-9])' + // [5] minute
':([0-9][0-9])' + // [6] second
'(?:\\.([0-9]*))?' + // [7] fraction
'(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tzHour
'(?::([0-9][0-9]))?))?$') // [11] tzMinute
function resolveYamlTimestamp(data) {
if (data === null) return false;
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
return false;
function resolveYamlTimestamp (data) {
if (data === null) return false
if (YAML_DATE_REGEXP.exec(data) !== null) return true
if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true
return false
}
function constructYamlTimestamp(data) {
var match, year, month, day, hour, minute, second, fraction = 0,
delta = null, tz_hour, tz_minute, date;
function constructYamlTimestamp (data) {
let fraction = 0
let delta = null
match = YAML_DATE_REGEXP.exec(data);
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
let match = YAML_DATE_REGEXP.exec(data)
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data)
if (match === null) throw new Error('Date resolve error');
if (match === null) throw new Error('Date resolve error')
// match: [1] year [2] month [3] day
year = +(match[1]);
month = +(match[2]) - 1; // JS month starts with 0
day = +(match[3]);
const year = +(match[1])
const month = +(match[2]) - 1 // JS month starts with 0
const day = +(match[3])
if (!match[4]) { // no hour
return new Date(Date.UTC(year, month, day));
return new Date(Date.UTC(year, month, day))
}
// match: [4] hour [5] minute [6] second [7] fraction
hour = +(match[4]);
minute = +(match[5]);
second = +(match[6]);
const hour = +(match[4])
const minute = +(match[5])
const second = +(match[6])
if (match[7]) {
fraction = match[7].slice(0, 3);
fraction = match[7].slice(0, 3)
while (fraction.length < 3) { // milli-seconds
fraction += '0';
fraction += '0'
}
fraction = +fraction;
fraction = +fraction
}
// match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
// match: [8] tz [9] tz_sign [10] tzHour [11] tzMinute
if (match[9]) {
tz_hour = +(match[10]);
tz_minute = +(match[11] || 0);
delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
if (match[9] === '-') delta = -delta;
const tzHour = +(match[10])
const tzMinute = +(match[11] || 0)
delta = (tzHour * 60 + tzMinute) * 60000 // delta in mili-seconds
if (match[9] === '-') delta = -delta
}
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
const date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction))
if (delta) date.setTime(date.getTime() - delta);
if (delta) date.setTime(date.getTime() - delta)
return date;
return date
}
function representYamlTimestamp(object /*, style*/) {
return object.toISOString();
function representYamlTimestamp (object /*, style */) {
return object.toISOString()
}
module.exports = new Type('tag:yaml.org,2002:timestamp', {
@ -85,4 +85,4 @@ module.exports = new Type('tag:yaml.org,2002:timestamp', {
construct: constructYamlTimestamp,
instanceOf: Date,
represent: representYamlTimestamp
});
})

View file

@ -1,6 +1,6 @@
{
"name": "js-yaml",
"version": "4.1.1",
"version": "4.3.0",
"description": "YAML 1.2 parser and serializer",
"keywords": [
"yaml",
@ -16,12 +16,25 @@
],
"license": "MIT",
"repository": "nodeca/js-yaml",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/puzrin"
},
{
"type": "github",
"url": "https://github.com/sponsors/nodeca"
}
],
"files": [
"index.js",
"lib/",
"bin/",
"dist/"
],
"publishConfig": {
"tag": "v4-legacy"
},
"bin": {
"js-yaml": "bin/js-yaml.js"
},
@ -35,12 +48,15 @@
},
"scripts": {
"lint": "eslint .",
"test": "npm run lint && mocha",
"coverage": "npm run lint && nyc mocha && nyc report --reporter html",
"demo": "npm run lint && node support/build_demo.js",
"gh-demo": "npm run demo && gh-pages -d demo -f",
"browserify": "rollup -c support/rollup.config.js",
"prepublishOnly": "npm run gh-demo"
"lint-fix": "eslint . --fix",
"test": "npm run lint && npm run test:core && npm run test:build",
"test:core": "node --test test/core/*.test.*",
"test:build": "npm run build && node --test test/build/*.test.*",
"coverage": "npm run build && c8 --include 'lib/**' -r text -r html -r lcov node --test test/core/*.test.*",
"build": "node support/build-dist.mjs",
"build:demo": "npm run lint && node support/build_demo.mjs",
"gh-demo": "npm run build:demo && gh-pages -d demo -f",
"prepack": "npm test && npm run build"
},
"unpkg": "dist/js-yaml.min.js",
"jsdelivr": "dist/js-yaml.min.js",
@ -48,19 +64,20 @@
"argparse": "^2.0.1"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"ansi": "^0.3.1",
"benchmark": "^2.1.4",
"codemirror": "^5.13.4",
"eslint": "^7.0.0",
"fast-check": "^2.8.0",
"gh-pages": "^3.1.0",
"mocha": "^8.2.1",
"nyc": "^15.1.0",
"rollup": "^2.34.1",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-terser": "^7.0.2",
"shelljs": "^0.8.4"
"@babel/core": "8.0.1",
"@babel/preset-env": "8.0.1",
"@rollup/plugin-commonjs": "29.0.3",
"@rollup/plugin-terser": "0.4.4",
"c8": "^11.0.0",
"codemirror": "^5.65.21",
"eslint": "^9.39.4",
"fast-check": "^4.8.0",
"gh-pages": "^6.3.0",
"neostandard": "^0.13.0",
"tinybench": "^6.0.2",
"vite": "7.3.6",
"vite-plugin-node-polyfills": "^0.28.0",
"vite-plugin-singlefile": "^2.3.3",
"workerpool": "^10.0.2"
}
}