First commit
This commit is contained in:
commit
87d22a4516
235 changed files with 51802 additions and 0 deletions
152
node_modules/json5/lib/cli.js
generated
vendored
Normal file
152
node_modules/json5/lib/cli.js
generated
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const pkg = require('../package.json')
|
||||
const JSON5 = require('./')
|
||||
|
||||
const argv = parseArgs()
|
||||
|
||||
if (argv.version) {
|
||||
version()
|
||||
} else if (argv.help) {
|
||||
usage()
|
||||
} else {
|
||||
const inFilename = argv.defaults[0]
|
||||
|
||||
let readStream
|
||||
if (inFilename) {
|
||||
readStream = fs.createReadStream(inFilename)
|
||||
} else {
|
||||
readStream = process.stdin
|
||||
}
|
||||
|
||||
let json5 = ''
|
||||
readStream.on('data', data => {
|
||||
json5 += data
|
||||
})
|
||||
|
||||
readStream.on('end', () => {
|
||||
let space
|
||||
if (argv.space === 't' || argv.space === 'tab') {
|
||||
space = '\t'
|
||||
} else {
|
||||
space = Number(argv.space)
|
||||
}
|
||||
|
||||
let value
|
||||
try {
|
||||
value = JSON5.parse(json5)
|
||||
if (!argv.validate) {
|
||||
const json = JSON.stringify(value, null, space)
|
||||
|
||||
let writeStream
|
||||
|
||||
// --convert is for backward compatibility with v0.5.1. If
|
||||
// specified with <file> and not --out-file, then a file with
|
||||
// the same name but with a .json extension will be written.
|
||||
if (argv.convert && inFilename && !argv.outFile) {
|
||||
const parsedFilename = path.parse(inFilename)
|
||||
const outFilename = path.format(
|
||||
Object.assign(
|
||||
parsedFilename,
|
||||
{base: path.basename(parsedFilename.base, parsedFilename.ext) + '.json'}
|
||||
)
|
||||
)
|
||||
|
||||
writeStream = fs.createWriteStream(outFilename)
|
||||
} else if (argv.outFile) {
|
||||
writeStream = fs.createWriteStream(argv.outFile)
|
||||
} else {
|
||||
writeStream = process.stdout
|
||||
}
|
||||
|
||||
writeStream.write(json)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err.message)
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function parseArgs () {
|
||||
let convert
|
||||
let space
|
||||
let validate
|
||||
let outFile
|
||||
let version
|
||||
let help
|
||||
const defaults = []
|
||||
|
||||
const args = process.argv.slice(2)
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i]
|
||||
switch (arg) {
|
||||
case '--convert':
|
||||
case '-c':
|
||||
convert = true
|
||||
break
|
||||
|
||||
case '--space':
|
||||
case '-s':
|
||||
space = args[++i]
|
||||
break
|
||||
|
||||
case '--validate':
|
||||
case '-v':
|
||||
validate = true
|
||||
break
|
||||
|
||||
case '--out-file':
|
||||
case '-o':
|
||||
outFile = args[++i]
|
||||
break
|
||||
|
||||
case '--version':
|
||||
case '-V':
|
||||
version = true
|
||||
break
|
||||
|
||||
case '--help':
|
||||
case '-h':
|
||||
help = true
|
||||
break
|
||||
|
||||
default:
|
||||
defaults.push(arg)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
convert,
|
||||
space,
|
||||
validate,
|
||||
outFile,
|
||||
version,
|
||||
help,
|
||||
defaults,
|
||||
}
|
||||
}
|
||||
|
||||
function version () {
|
||||
console.log(pkg.version)
|
||||
}
|
||||
|
||||
function usage () {
|
||||
console.log(
|
||||
`
|
||||
Usage: json5 [options] <file>
|
||||
|
||||
If <file> is not provided, then STDIN is used.
|
||||
|
||||
Options:
|
||||
|
||||
-s, --space The number of spaces to indent or 't' for tabs
|
||||
-o, --out-file [file] Output to the specified file, otherwise STDOUT
|
||||
-v, --validate Validate JSON5 but do not output JSON
|
||||
-V, --version Output the version number
|
||||
-h, --help Output usage information`
|
||||
)
|
||||
}
|
4
node_modules/json5/lib/index.d.ts
generated
vendored
Normal file
4
node_modules/json5/lib/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
import parse = require('./parse')
|
||||
import stringify = require('./stringify')
|
||||
|
||||
export {parse, stringify}
|
9
node_modules/json5/lib/index.js
generated
vendored
Normal file
9
node_modules/json5/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
const parse = require('./parse')
|
||||
const stringify = require('./stringify')
|
||||
|
||||
const JSON5 = {
|
||||
parse,
|
||||
stringify,
|
||||
}
|
||||
|
||||
module.exports = JSON5
|
15
node_modules/json5/lib/parse.d.ts
generated
vendored
Normal file
15
node_modules/json5/lib/parse.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* Parses a JSON5 string, constructing the JavaScript value or object described
|
||||
* by the string.
|
||||
* @template T The type of the return value.
|
||||
* @param text The string to parse as JSON5.
|
||||
* @param reviver A function that prescribes how the value originally produced
|
||||
* by parsing is transformed before being returned.
|
||||
* @returns The JavaScript value converted from the JSON5 string.
|
||||
*/
|
||||
declare function parse<T = any>(
|
||||
text: string,
|
||||
reviver?: ((this: any, key: string, value: any) => any) | null,
|
||||
): T
|
||||
|
||||
export = parse
|
1114
node_modules/json5/lib/parse.js
generated
vendored
Normal file
1114
node_modules/json5/lib/parse.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
13
node_modules/json5/lib/register.js
generated
vendored
Normal file
13
node_modules/json5/lib/register.js
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
const fs = require('fs')
|
||||
const JSON5 = require('./')
|
||||
|
||||
// eslint-disable-next-line node/no-deprecated-api
|
||||
require.extensions['.json5'] = function (module, filename) {
|
||||
const content = fs.readFileSync(filename, 'utf8')
|
||||
try {
|
||||
module.exports = JSON5.parse(content)
|
||||
} catch (err) {
|
||||
err.message = filename + ': ' + err.message
|
||||
throw err
|
||||
}
|
||||
}
|
4
node_modules/json5/lib/require.js
generated
vendored
Normal file
4
node_modules/json5/lib/require.js
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
// This file is for backward compatibility with v0.5.1.
|
||||
require('./register')
|
||||
|
||||
console.warn("'json5/require' is deprecated. Please use 'json5/register' instead.")
|
89
node_modules/json5/lib/stringify.d.ts
generated
vendored
Normal file
89
node_modules/json5/lib/stringify.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
declare type StringifyOptions = {
|
||||
/**
|
||||
* A function that alters the behavior of the stringification process, or an
|
||||
* array of String and Number objects that serve as a allowlist for
|
||||
* selecting/filtering the properties of the value object to be included in
|
||||
* the JSON5 string. If this value is null or not provided, all properties
|
||||
* of the object are included in the resulting JSON5 string.
|
||||
*/
|
||||
replacer?:
|
||||
| ((this: any, key: string, value: any) => any)
|
||||
| (string | number)[]
|
||||
| null
|
||||
|
||||
/**
|
||||
* A String or Number object that's used to insert white space into the
|
||||
* output JSON5 string for readability purposes. If this is a Number, it
|
||||
* indicates the number of space characters to use as white space; this
|
||||
* number is capped at 10 (if it is greater, the value is just 10). Values
|
||||
* less than 1 indicate that no space should be used. If this is a String,
|
||||
* the string (or the first 10 characters of the string, if it's longer than
|
||||
* that) is used as white space. If this parameter is not provided (or is
|
||||
* null), no white space is used. If white space is used, trailing commas
|
||||
* will be used in objects and arrays.
|
||||
*/
|
||||
space?: string | number | null
|
||||
|
||||
/**
|
||||
* A String representing the quote character to use when serializing
|
||||
* strings.
|
||||
*/
|
||||
quote?: string | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JavaScript value to a JSON5 string.
|
||||
* @param value The value to convert to a JSON5 string.
|
||||
* @param replacer A function that alters the behavior of the stringification
|
||||
* process. If this value is null or not provided, all properties of the object
|
||||
* are included in the resulting JSON5 string.
|
||||
* @param space A String or Number object that's used to insert white space into
|
||||
* the output JSON5 string for readability purposes. If this is a Number, it
|
||||
* indicates the number of space characters to use as white space; this number
|
||||
* is capped at 10 (if it is greater, the value is just 10). Values less than 1
|
||||
* indicate that no space should be used. If this is a String, the string (or
|
||||
* the first 10 characters of the string, if it's longer than that) is used as
|
||||
* white space. If this parameter is not provided (or is null), no white space
|
||||
* is used. If white space is used, trailing commas will be used in objects and
|
||||
* arrays.
|
||||
* @returns The JSON5 string converted from the JavaScript value.
|
||||
*/
|
||||
declare function stringify(
|
||||
value: any,
|
||||
replacer?: ((this: any, key: string, value: any) => any) | null,
|
||||
space?: string | number | null,
|
||||
): string
|
||||
|
||||
/**
|
||||
* Converts a JavaScript value to a JSON5 string.
|
||||
* @param value The value to convert to a JSON5 string.
|
||||
* @param replacer An array of String and Number objects that serve as a
|
||||
* allowlist for selecting/filtering the properties of the value object to be
|
||||
* included in the JSON5 string. If this value is null or not provided, all
|
||||
* properties of the object are included in the resulting JSON5 string.
|
||||
* @param space A String or Number object that's used to insert white space into
|
||||
* the output JSON5 string for readability purposes. If this is a Number, it
|
||||
* indicates the number of space characters to use as white space; this number
|
||||
* is capped at 10 (if it is greater, the value is just 10). Values less than 1
|
||||
* indicate that no space should be used. If this is a String, the string (or
|
||||
* the first 10 characters of the string, if it's longer than that) is used as
|
||||
* white space. If this parameter is not provided (or is null), no white space
|
||||
* is used. If white space is used, trailing commas will be used in objects and
|
||||
* arrays.
|
||||
* @returns The JSON5 string converted from the JavaScript value.
|
||||
*/
|
||||
declare function stringify(
|
||||
value: any,
|
||||
replacer: (string | number)[],
|
||||
space?: string | number | null,
|
||||
): string
|
||||
|
||||
/**
|
||||
* Converts a JavaScript value to a JSON5 string.
|
||||
* @param value The value to convert to a JSON5 string.
|
||||
* @param options An object specifying options.
|
||||
* @returns The JSON5 string converted from the JavaScript value.
|
||||
*/
|
||||
declare function stringify(value: any, options: StringifyOptions): string
|
||||
|
||||
export = stringify
|
261
node_modules/json5/lib/stringify.js
generated
vendored
Normal file
261
node_modules/json5/lib/stringify.js
generated
vendored
Normal file
|
@ -0,0 +1,261 @@
|
|||
const util = require('./util')
|
||||
|
||||
module.exports = function stringify (value, replacer, space) {
|
||||
const stack = []
|
||||
let indent = ''
|
||||
let propertyList
|
||||
let replacerFunc
|
||||
let gap = ''
|
||||
let quote
|
||||
|
||||
if (
|
||||
replacer != null &&
|
||||
typeof replacer === 'object' &&
|
||||
!Array.isArray(replacer)
|
||||
) {
|
||||
space = replacer.space
|
||||
quote = replacer.quote
|
||||
replacer = replacer.replacer
|
||||
}
|
||||
|
||||
if (typeof replacer === 'function') {
|
||||
replacerFunc = replacer
|
||||
} else if (Array.isArray(replacer)) {
|
||||
propertyList = []
|
||||
for (const v of replacer) {
|
||||
let item
|
||||
|
||||
if (typeof v === 'string') {
|
||||
item = v
|
||||
} else if (
|
||||
typeof v === 'number' ||
|
||||
v instanceof String ||
|
||||
v instanceof Number
|
||||
) {
|
||||
item = String(v)
|
||||
}
|
||||
|
||||
if (item !== undefined && propertyList.indexOf(item) < 0) {
|
||||
propertyList.push(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (space instanceof Number) {
|
||||
space = Number(space)
|
||||
} else if (space instanceof String) {
|
||||
space = String(space)
|
||||
}
|
||||
|
||||
if (typeof space === 'number') {
|
||||
if (space > 0) {
|
||||
space = Math.min(10, Math.floor(space))
|
||||
gap = ' '.substr(0, space)
|
||||
}
|
||||
} else if (typeof space === 'string') {
|
||||
gap = space.substr(0, 10)
|
||||
}
|
||||
|
||||
return serializeProperty('', {'': value})
|
||||
|
||||
function serializeProperty (key, holder) {
|
||||
let value = holder[key]
|
||||
if (value != null) {
|
||||
if (typeof value.toJSON5 === 'function') {
|
||||
value = value.toJSON5(key)
|
||||
} else if (typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key)
|
||||
}
|
||||
}
|
||||
|
||||
if (replacerFunc) {
|
||||
value = replacerFunc.call(holder, key, value)
|
||||
}
|
||||
|
||||
if (value instanceof Number) {
|
||||
value = Number(value)
|
||||
} else if (value instanceof String) {
|
||||
value = String(value)
|
||||
} else if (value instanceof Boolean) {
|
||||
value = value.valueOf()
|
||||
}
|
||||
|
||||
switch (value) {
|
||||
case null: return 'null'
|
||||
case true: return 'true'
|
||||
case false: return 'false'
|
||||
}
|
||||
|
||||
if (typeof value === 'string') {
|
||||
return quoteString(value, false)
|
||||
}
|
||||
|
||||
if (typeof value === 'number') {
|
||||
return String(value)
|
||||
}
|
||||
|
||||
if (typeof value === 'object') {
|
||||
return Array.isArray(value) ? serializeArray(value) : serializeObject(value)
|
||||
}
|
||||
|
||||
return undefined
|
||||
}
|
||||
|
||||
function quoteString (value) {
|
||||
const quotes = {
|
||||
"'": 0.1,
|
||||
'"': 0.2,
|
||||
}
|
||||
|
||||
const replacements = {
|
||||
"'": "\\'",
|
||||
'"': '\\"',
|
||||
'\\': '\\\\',
|
||||
'\b': '\\b',
|
||||
'\f': '\\f',
|
||||
'\n': '\\n',
|
||||
'\r': '\\r',
|
||||
'\t': '\\t',
|
||||
'\v': '\\v',
|
||||
'\0': '\\0',
|
||||
'\u2028': '\\u2028',
|
||||
'\u2029': '\\u2029',
|
||||
}
|
||||
|
||||
let product = ''
|
||||
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const c = value[i]
|
||||
switch (c) {
|
||||
case "'":
|
||||
case '"':
|
||||
quotes[c]++
|
||||
product += c
|
||||
continue
|
||||
|
||||
case '\0':
|
||||
if (util.isDigit(value[i + 1])) {
|
||||
product += '\\x00'
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (replacements[c]) {
|
||||
product += replacements[c]
|
||||
continue
|
||||
}
|
||||
|
||||
if (c < ' ') {
|
||||
let hexString = c.charCodeAt(0).toString(16)
|
||||
product += '\\x' + ('00' + hexString).substring(hexString.length)
|
||||
continue
|
||||
}
|
||||
|
||||
product += c
|
||||
}
|
||||
|
||||
const quoteChar = quote || Object.keys(quotes).reduce((a, b) => (quotes[a] < quotes[b]) ? a : b)
|
||||
|
||||
product = product.replace(new RegExp(quoteChar, 'g'), replacements[quoteChar])
|
||||
|
||||
return quoteChar + product + quoteChar
|
||||
}
|
||||
|
||||
function serializeObject (value) {
|
||||
if (stack.indexOf(value) >= 0) {
|
||||
throw TypeError('Converting circular structure to JSON5')
|
||||
}
|
||||
|
||||
stack.push(value)
|
||||
|
||||
let stepback = indent
|
||||
indent = indent + gap
|
||||
|
||||
let keys = propertyList || Object.keys(value)
|
||||
let partial = []
|
||||
for (const key of keys) {
|
||||
const propertyString = serializeProperty(key, value)
|
||||
if (propertyString !== undefined) {
|
||||
let member = serializeKey(key) + ':'
|
||||
if (gap !== '') {
|
||||
member += ' '
|
||||
}
|
||||
member += propertyString
|
||||
partial.push(member)
|
||||
}
|
||||
}
|
||||
|
||||
let final
|
||||
if (partial.length === 0) {
|
||||
final = '{}'
|
||||
} else {
|
||||
let properties
|
||||
if (gap === '') {
|
||||
properties = partial.join(',')
|
||||
final = '{' + properties + '}'
|
||||
} else {
|
||||
let separator = ',\n' + indent
|
||||
properties = partial.join(separator)
|
||||
final = '{\n' + indent + properties + ',\n' + stepback + '}'
|
||||
}
|
||||
}
|
||||
|
||||
stack.pop()
|
||||
indent = stepback
|
||||
return final
|
||||
}
|
||||
|
||||
function serializeKey (key) {
|
||||
if (key.length === 0) {
|
||||
return quoteString(key, true)
|
||||
}
|
||||
|
||||
const firstChar = String.fromCodePoint(key.codePointAt(0))
|
||||
if (!util.isIdStartChar(firstChar)) {
|
||||
return quoteString(key, true)
|
||||
}
|
||||
|
||||
for (let i = firstChar.length; i < key.length; i++) {
|
||||
if (!util.isIdContinueChar(String.fromCodePoint(key.codePointAt(i)))) {
|
||||
return quoteString(key, true)
|
||||
}
|
||||
}
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
function serializeArray (value) {
|
||||
if (stack.indexOf(value) >= 0) {
|
||||
throw TypeError('Converting circular structure to JSON5')
|
||||
}
|
||||
|
||||
stack.push(value)
|
||||
|
||||
let stepback = indent
|
||||
indent = indent + gap
|
||||
|
||||
let partial = []
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
const propertyString = serializeProperty(String(i), value)
|
||||
partial.push((propertyString !== undefined) ? propertyString : 'null')
|
||||
}
|
||||
|
||||
let final
|
||||
if (partial.length === 0) {
|
||||
final = '[]'
|
||||
} else {
|
||||
if (gap === '') {
|
||||
let properties = partial.join(',')
|
||||
final = '[' + properties + ']'
|
||||
} else {
|
||||
let separator = ',\n' + indent
|
||||
let properties = partial.join(separator)
|
||||
final = '[\n' + indent + properties + ',\n' + stepback + ']'
|
||||
}
|
||||
}
|
||||
|
||||
stack.pop()
|
||||
indent = stepback
|
||||
return final
|
||||
}
|
||||
}
|
3
node_modules/json5/lib/unicode.d.ts
generated
vendored
Normal file
3
node_modules/json5/lib/unicode.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
export declare const Space_Separator: RegExp
|
||||
export declare const ID_Start: RegExp
|
||||
export declare const ID_Continue: RegExp
|
4
node_modules/json5/lib/unicode.js
generated
vendored
Normal file
4
node_modules/json5/lib/unicode.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
5
node_modules/json5/lib/util.d.ts
generated
vendored
Normal file
5
node_modules/json5/lib/util.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
export declare function isSpaceSeparator(c?: string): boolean
|
||||
export declare function isIdStartChar(c?: string): boolean
|
||||
export declare function isIdContinueChar(c?: string): boolean
|
||||
export declare function isDigit(c?: string): boolean
|
||||
export declare function isHexDigit(c?: string): boolean
|
35
node_modules/json5/lib/util.js
generated
vendored
Normal file
35
node_modules/json5/lib/util.js
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
const unicode = require('../lib/unicode')
|
||||
|
||||
module.exports = {
|
||||
isSpaceSeparator (c) {
|
||||
return typeof c === 'string' && unicode.Space_Separator.test(c)
|
||||
},
|
||||
|
||||
isIdStartChar (c) {
|
||||
return typeof c === 'string' && (
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c === '$') || (c === '_') ||
|
||||
unicode.ID_Start.test(c)
|
||||
)
|
||||
},
|
||||
|
||||
isIdContinueChar (c) {
|
||||
return typeof c === 'string' && (
|
||||
(c >= 'a' && c <= 'z') ||
|
||||
(c >= 'A' && c <= 'Z') ||
|
||||
(c >= '0' && c <= '9') ||
|
||||
(c === '$') || (c === '_') ||
|
||||
(c === '\u200C') || (c === '\u200D') ||
|
||||
unicode.ID_Continue.test(c)
|
||||
)
|
||||
},
|
||||
|
||||
isDigit (c) {
|
||||
return typeof c === 'string' && /[0-9]/.test(c)
|
||||
},
|
||||
|
||||
isHexDigit (c) {
|
||||
return typeof c === 'string' && /[0-9A-Fa-f]/.test(c)
|
||||
},
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue