Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (args.length === 1 && (args[0] === '-v' || args[0] === '--version')) {
stderr.write(require('./package.json').version + '\n')
process.exit(2)
}
if (args.length === 1 && args[0] === '--life') {
require('./bang')
return
}
input = fs.readFileSync(args[0]).toString('utf8')
filename = path.basename(args[0])
global.FX_FILENAME = filename
args.shift()
}
const json = JSON.parse(input)
if (args.length === 0 && stdout.isTTY) {
require('./fx')(filename, json)
return
}
apply(json)
}
const _replacer = (key, value) => {
if (_.isString(value) && DECIMAL_REGEX.test(value) &&
!isNaN(value) && parseFloat(value) > Number.MAX_SAFE_INTEGER) {
return new LosslessJSON.LosslessNumber(value.replace(/^\+/, ''))
} else if (value instanceof Decimal) {
return new LosslessJSON.LosslessNumber(value.toString())
} else {
return value
}
}
const _replacer = (key, value) => {
if (_.isString(value) && DECIMAL_REGEX.test(value) &&
!isNaN(value) && parseFloat(value) > Number.MAX_SAFE_INTEGER) {
return new LosslessJSON.LosslessNumber(value.replace(/^\+/, ''))
} else if (value instanceof Decimal) {
return new LosslessJSON.LosslessNumber(value.toString())
} else {
return value
}
}
}).then((response) => {
let body = lossless_json.parse(response.body, this._lossless_converter);
if (body.returnCode && body.returnCode == "0000"){
debug(`Completed confirming payment.`);
debug(body);
return body;
} else {
debug(`Failed to confirm payment.`);
debug(body);
return Promise.reject(new Error(body));
}
})
}
const parse = (str, configs) => {
let result
try {
result = _.get(configs, 'options.support-big-int')
? LosslessJSON.parse(str, _reviver)
: JSON.parse(str)
} catch (e) {
throw new Error(`failed to parse json (message: "${e.message}") - source: ${JSON.stringify(str)}`)
}
return result
}
function apply(cb, input) {
let json
try {
json = JSON.parse(input)
} catch (e) {
process.stderr.write(e.toString() + '\n')
return
}
cb(json)
}
const stringify = (json, configs) => _.get(configs, 'options.support-big-int')
? LosslessJSON.stringify(json, _replacer)
: JSON.stringify(json)