update
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
# JSON5 – JSON for Humans
|
||||
|
||||
[][Build Status]
|
||||
[][Build Status]
|
||||
[][Coverage
|
||||
Status]
|
||||
@@ -12,7 +12,7 @@ some productions from [ECMAScript 5.1].
|
||||
This JavaScript library is the official reference implementation for JSON5
|
||||
parsing and serialization libraries.
|
||||
|
||||
[Build Status]: https://travis-ci.org/json5/json5
|
||||
[Build Status]: https://travis-ci.com/json5/json5
|
||||
|
||||
[Coverage Status]: https://coveralls.io/github/json5/json5
|
||||
|
||||
|
||||
+65
-25
@@ -2,37 +2,17 @@
|
||||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const minimist = require('minimist')
|
||||
const pkg = require('../package.json')
|
||||
const JSON5 = require('./')
|
||||
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
alias: {
|
||||
'convert': 'c',
|
||||
'space': 's',
|
||||
'validate': 'v',
|
||||
'out-file': 'o',
|
||||
'version': 'V',
|
||||
'help': 'h',
|
||||
},
|
||||
boolean: [
|
||||
'convert',
|
||||
'validate',
|
||||
'version',
|
||||
'help',
|
||||
],
|
||||
string: [
|
||||
'space',
|
||||
'out-file',
|
||||
],
|
||||
})
|
||||
const argv = parseArgs()
|
||||
|
||||
if (argv.version) {
|
||||
version()
|
||||
} else if (argv.help) {
|
||||
usage()
|
||||
} else {
|
||||
const inFilename = argv._[0]
|
||||
const inFilename = argv.defaults[0]
|
||||
|
||||
let readStream
|
||||
if (inFilename) {
|
||||
@@ -65,7 +45,7 @@ if (argv.version) {
|
||||
// --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.o) {
|
||||
if (argv.convert && inFilename && !argv.outFile) {
|
||||
const parsedFilename = path.parse(inFilename)
|
||||
const outFilename = path.format(
|
||||
Object.assign(
|
||||
@@ -75,8 +55,8 @@ if (argv.version) {
|
||||
)
|
||||
|
||||
writeStream = fs.createWriteStream(outFilename)
|
||||
} else if (argv.o) {
|
||||
writeStream = fs.createWriteStream(argv.o)
|
||||
} else if (argv.outFile) {
|
||||
writeStream = fs.createWriteStream(argv.outFile)
|
||||
} else {
|
||||
writeStream = process.stdout
|
||||
}
|
||||
@@ -90,6 +70,66 @@ if (argv.version) {
|
||||
})
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import parse = require('./parse')
|
||||
import stringify = require('./stringify')
|
||||
|
||||
export {parse, stringify}
|
||||
+15
@@ -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
|
||||
+89
@@ -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
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export declare const Space_Separator: RegExp
|
||||
export declare const ID_Start: RegExp
|
||||
export declare const ID_Continue: RegExp
|
||||
+5
@@ -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
|
||||
+20
-16
@@ -1,34 +1,40 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"json5@2.1.3",
|
||||
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
|
||||
"json5@2.2.1",
|
||||
"/home/node/nuxt"
|
||||
]
|
||||
],
|
||||
"_from": "json5@2.1.3",
|
||||
"_id": "json5@2.1.3",
|
||||
"_from": "json5@2.2.1",
|
||||
"_id": "json5@2.2.1",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-KXPvOm8K9IJKFM0bmdn8QXh7udDh1g/giieX0NLCaMnb4hEiVFqnop2ImTXCc5e0/oHz3LTqmHGtExn5hfMkOA==",
|
||||
"_integrity": "sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA==",
|
||||
"_location": "/json5",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "json5@2.1.3",
|
||||
"raw": "json5@2.2.1",
|
||||
"name": "json5",
|
||||
"escapedName": "json5",
|
||||
"rawSpec": "2.1.3",
|
||||
"rawSpec": "2.2.1",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "2.1.3"
|
||||
"fetchSpec": "2.2.1"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/@babel/core",
|
||||
"/@nuxt/webpack/loader-utils",
|
||||
"/babel-loader/loader-utils",
|
||||
"/css-loader/loader-utils",
|
||||
"/eslint-loader/loader-utils",
|
||||
"/extract-css-chunks-webpack-plugin/loader-utils"
|
||||
"/extract-css-chunks-webpack-plugin/loader-utils",
|
||||
"/style-resources-loader/loader-utils",
|
||||
"/thread-loader/loader-utils",
|
||||
"/url-loader/loader-utils"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/json5/-/json5-2.1.3.tgz",
|
||||
"_spec": "2.1.3",
|
||||
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
|
||||
"_resolved": "https://registry.npmjs.org/json5/-/json5-2.2.1.tgz",
|
||||
"_spec": "2.2.1",
|
||||
"_where": "/home/node/nuxt",
|
||||
"author": {
|
||||
"name": "Aseem Kishore",
|
||||
"email": "aseem.kishore@gmail.com"
|
||||
@@ -54,9 +60,6 @@
|
||||
"email": "jordanbtucker@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"minimist": "^1.2.5"
|
||||
},
|
||||
"description": "JSON for humans.",
|
||||
"devDependencies": {
|
||||
"core-js": "^2.6.5",
|
||||
@@ -111,5 +114,6 @@
|
||||
"test": "tap -Rspec --100 test",
|
||||
"version": "npm run build-package && git add package.json5"
|
||||
},
|
||||
"version": "2.1.3"
|
||||
"types": "lib/index.d.ts",
|
||||
"version": "2.2.1"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user