How to use lossless-json - 7 common examples

To help you get started, we’ve selected a few lossless-json examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github antonmedv / fx / index.js View on Github external
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)
}
github taskrabbit / elasticsearch-dump / lib / jsonparser.js View on Github external
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
  }
}
github taskrabbit / elasticsearch-dump / lib / jsonparser.js View on Github external
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
  }
}
github nkjm / line-pay / module / line-pay.js View on Github external
}).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));
            }
        })
    }
github taskrabbit / elasticsearch-dump / lib / jsonparser.js View on Github external
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
}
github antonmedv / fx / stream.js View on Github external
function apply(cb, input) {
  let json
  try {
    json = JSON.parse(input)
  } catch (e) {
    process.stderr.write(e.toString() + '\n')
    return
  }
  cb(json)
}
github taskrabbit / elasticsearch-dump / lib / jsonparser.js View on Github external
const stringify = (json, configs) => _.get(configs, 'options.support-big-int')
  ? LosslessJSON.stringify(json, _replacer)
  : JSON.stringify(json)

lossless-json

Parse JSON without risk of losing numeric information

MIT
Latest version published 3 months ago

Package Health Score

67 / 100
Full package analysis