fast-json-stringify
Advanced tools
Comparing version 5.0.1 to 5.0.2
@@ -5,4 +5,3 @@ 'use strict' | ||
const chalk = require('chalk') | ||
const inquirer = require('inquirer') | ||
const cliSelect = require('cli-select') | ||
const simpleGit = require('simple-git') | ||
@@ -15,20 +14,23 @@ | ||
const PERCENT_THRESHOLD = 5 | ||
const greyColor = '\x1b[30m' | ||
const redColor = '\x1b[31m' | ||
const greenColor = '\x1b[32m' | ||
const resetColor = '\x1b[0m' | ||
async function selectBranchName (message, branches) { | ||
const result = await inquirer.prompt([{ | ||
console.log(message) | ||
const result = await cliSelect({ | ||
type: 'list', | ||
name: 'branch', | ||
choices: branches, | ||
loop: false, | ||
pageSize: 20, | ||
message | ||
}]) | ||
return result.branch | ||
values: branches | ||
}) | ||
console.log(result.value) | ||
return result.value | ||
} | ||
async function executeCommandOnBranch (command, branch) { | ||
console.log(chalk.grey(`Checking out "${branch}"`)) | ||
console.log(`${greyColor}Checking out "${branch}"${resetColor}`) | ||
await git.checkout(branch) | ||
console.log(chalk.grey(`Execute "${command}"`)) | ||
console.log(`${greyColor}Execute "${command}"${resetColor}`) | ||
const childProcess = spawn(command, { stdio: 'pipe', shell: true }) | ||
@@ -79,5 +81,5 @@ | ||
if (roundedPercent > PERCENT_THRESHOLD) { | ||
console.log(chalk.green(message)) | ||
console.log(`${greenColor}${message}${resetColor}`) | ||
} else if (roundedPercent < -PERCENT_THRESHOLD) { | ||
console.log(chalk.red(message)) | ||
console.log(`${redColor}${message}${resetColor}`) | ||
} else { | ||
@@ -116,3 +118,3 @@ console.log(message) | ||
console.log(chalk.gray(`Back to ${currentBranch.name} ${currentBranch.commit}`)) | ||
console.log(`${greyColor}Back to ${currentBranch.name} ${currentBranch.commit}${resetColor}`) | ||
})() |
22
index.js
@@ -300,3 +300,3 @@ 'use strict' | ||
function additionalProperty (location) { | ||
let ap = location.schema.additionalProperties | ||
const ap = location.schema.additionalProperties | ||
let code = '' | ||
@@ -313,6 +313,6 @@ if (ap === true) { | ||
} | ||
let apLocation = mergeLocation(location, 'additionalProperties') | ||
if (ap.$ref) { | ||
apLocation = resolveRef(location, ap.$ref) | ||
ap = apLocation.schema | ||
if (apLocation.schema.$ref) { | ||
apLocation = resolveRef(apLocation, apLocation.schema.$ref) | ||
} | ||
@@ -528,4 +528,5 @@ | ||
code += addIfThenElse(thenLocation) | ||
} else { | ||
code += buildInnerObject(thenLocation) | ||
} | ||
code += buildInnerObject(thenLocation) | ||
code += ` | ||
@@ -544,4 +545,5 @@ } | ||
code += addIfThenElse(elseLocation) | ||
} else { | ||
code += buildInnerObject(elseLocation) | ||
} | ||
code += buildInnerObject(elseLocation) | ||
code += ` | ||
@@ -589,11 +591,9 @@ } | ||
let rCode | ||
if (schema.if && schema.then) { | ||
rCode = addIfThenElse(location) | ||
functionCode += addIfThenElse(location) | ||
} else { | ||
rCode = buildInnerObject(location) | ||
functionCode += buildInnerObject(location) | ||
} | ||
// Removes the comma if is the last element of the string (in case there are not properties) | ||
functionCode += `${rCode} | ||
functionCode += ` | ||
json += '}' | ||
@@ -600,0 +600,0 @@ return json |
{ | ||
"name": "fast-json-stringify", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Stringify your JSON at max speed", | ||
@@ -38,5 +38,4 @@ "main": "index.js", | ||
"benchmark": "^2.1.4", | ||
"chalk": "^4.1.2", | ||
"cli-select": "^1.1.2", | ||
"compile-json-stringify": "^0.1.2", | ||
"inquirer": "^9.0.0", | ||
"is-my-json-valid": "^2.20.0", | ||
@@ -43,0 +42,0 @@ "luxon": "^2.4.0", |
@@ -51,3 +51,3 @@ 'use strict' | ||
const num = Number(i) | ||
if (Number.isNaN(num)) { | ||
if (Number.isNaN(num) || !Number.isFinite(num)) { | ||
throw new Error(`The value "${i}" cannot be converted to a number.`) | ||
@@ -54,0 +54,0 @@ } else { |
@@ -336,1 +336,36 @@ 'use strict' | ||
}) | ||
t.test('nested if/then', t => { | ||
t.plan(2) | ||
const schema = { | ||
type: 'object', | ||
properties: { a: { type: 'string' } }, | ||
if: { | ||
type: 'object', | ||
properties: { foo: { type: 'string' } } | ||
}, | ||
then: { | ||
properties: { bar: { type: 'string' } }, | ||
if: { | ||
type: 'object', | ||
properties: { foo1: { type: 'string' } } | ||
}, | ||
then: { | ||
properties: { bar1: { type: 'string' } } | ||
} | ||
} | ||
} | ||
const stringify = build(schema) | ||
t.equal( | ||
stringify({ a: 'A', foo: 'foo', bar: 'bar' }), | ||
JSON.stringify({ a: 'A', bar: 'bar' }) | ||
) | ||
t.equal( | ||
stringify({ a: 'A', foo: 'foo', bar: 'bar', foo1: 'foo1', bar1: 'bar1' }), | ||
JSON.stringify({ a: 'A', bar: 'bar', bar1: 'bar1' }) | ||
) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
311706
14
75
11582