How to use the json5.parse function in json5

To help you get started, we’ve selected a few json5 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 Hotell / typescript-lib-starter / scripts / migrate / migrate-3-4.js View on Github external
*/

  const starterConfigPath = resolve(ROOT, 'tslint.json')
  const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tslint.json')

  /**
   * @type {TsLintConfig}
   */
  const starterConfig = JSON5.parse(
    readFileSync(starterConfigPath, { encoding: 'utf-8' })
  )

  /**
   * @type {TsLintConfig}
   */
  const libConfig = JSON5.parse(
    readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
  )

  // @TODO find out how to properly merge objects with comments as tslint.json supports comments
  // 👉 https://github.com/Hotell/typescript-lib-starter/issues/133

  // log('starter:', starterConfig)
  // log('library:', libConfig)

  log('==TS-Lint:nothing updated ☕️ ==\n')
}
github Hotell / typescript-lib-starter / scripts / migrate / migrate-3-4.js View on Github external
function updateTsLintConfig() {
  /**
   * @typedef {typeof import('../../tslint.json')} TsLintConfig
   */

  const starterConfigPath = resolve(ROOT, 'tslint.json')
  const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tslint.json')

  /**
   * @type {TsLintConfig}
   */
  const starterConfig = JSON5.parse(
    readFileSync(starterConfigPath, { encoding: 'utf-8' })
  )

  /**
   * @type {TsLintConfig}
   */
  const libConfig = JSON5.parse(
    readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
  )

  // @TODO find out how to properly merge objects with comments as tslint.json supports comments
  // 👉 https://github.com/Hotell/typescript-lib-starter/issues/133

  // log('starter:', starterConfig)
  // log('library:', libConfig)
github scripted-editor / scripted / server / utils / parse-json-file.js View on Github external
var d = getContents(handle).then(function (contents) {
				var data = null;
				if (!ALL_WHITE_SPACE.test(contents)) {
					try {
						data = JSON5.parse(contents);
					} catch (e) {
						data = {
							error: "Couldn't parse (JSON5) '"+handle+"'\nERROR: " + e
						};
					}
				}
				data = data || {};
				return data;
			}).otherwise(function (err) {
				debug_log(err);
github milesj / boost / packages / core / src / ConfigLoader.ts View on Github external
parseFile(basePath: PortablePath, args: any[] = [], options: ParseOptions = {}): T {
    const filePath = Path.create(basePath);
    const name = filePath.name();
    const ext = filePath.ext();
    let value: any = null;

    this.debug('Parsing file %s', color.filePath(filePath));

    if (!filePath.isAbsolute()) {
      throw new Error(this.tool.msg('errors:absolutePathRequired'));
    }

    if (ext === '.json' || ext === '.json5') {
      value = JSON5.parse(fs.readFileSync(filePath.path(), 'utf8'));
    } else if (ext === '.js') {
      value = requireModule(filePath);

      if (typeof value === 'function') {
        if (options.errorOnFunction) {
          throw new Error(this.tool.msg('errors:configNoFunction', { name }));
        } else {
          value = value(...args);
        }
      }
    } else {
      throw new Error(this.tool.msg('errors:configUnsupportedExt', { ext }));
    }

    if (!isObject(value)) {
      throw new Error(this.tool.msg('errors:configInvalidNamed', { name }));
github fimbullinter / wotan / packages / wotan / src / services / default / configuration-provider.ts View on Github external
public read(filename: string): RawConfiguration {
        switch (path.extname(filename)) {
            case '.json':
            case '.json5':
                return json5.parse(this.fs.readFile(filename));
            case '.yaml':
            case '.yml':
                return yaml.safeLoad(this.fs.readFile(filename))!;
            default:
                return this.resolver.require(filename, {cache: false});
        }
    }
github decentralized-identity / element / packages / element-core / scripts / migrate / migrate-4-5.js View on Github external
function updateTsConfig() {
  /**
   * @typedef {typeof import('../tsconfig.json')} TsConfig
   */

  const starterConfigPath = resolve(ROOT, 'tsconfig.json')
  const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tsconfig.json')

  /**
   * @type {TsConfig}
   */
  const starterConfig = JSON5.parse(
    readFileSync(starterConfigPath, { encoding: 'utf-8' })
  )

  /**
   * @type {TsConfig}
   */
  const libConfig = JSON5.parse(
    readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
  )

  const newConfig = {
    ...libConfig,
    compilerOptions: {
      ...libConfig.compilerOptions,
      ...starterConfig.compilerOptions,
    },
github fand / veda / src / config.ts View on Github external
private parseComment(filepath: string, comment: string): IRcFragment {
        let rc: IRcFragment = {};
        try {
            rc = JSON5.parse(comment);
        } catch (e) {}

        rc = fixPath(path.dirname(filepath), rc);

        return rc;
    }
github Hotell / typescript-lib-starter / scripts / migrate / migrate-4-5.js View on Github external
*/

  const starterConfigPath = resolve(ROOT, 'tsconfig.json')
  const libPackageConfigPath = resolve(PACKAGE_ROOT, 'tsconfig.json')

  /**
   * @type {TsConfig}
   */
  const starterConfig = JSON5.parse(
    readFileSync(starterConfigPath, { encoding: 'utf-8' })
  )

  /**
   * @type {TsConfig}
   */
  const libConfig = JSON5.parse(
    readFileSync(libPackageConfigPath, { encoding: 'utf-8' })
  )

  const newConfig = {
    ...libConfig,
    compilerOptions: {
      ...libConfig.compilerOptions,
      ...starterConfig.compilerOptions,
    },
    include: [...new Set([...libConfig.include, ...starterConfig.include])],
  }

  const updatedLibTsConfigToWrite = JSON.stringify(newConfig, null, 2)
  writeFileSync(libPackageConfigPath, updatedLibTsConfigToWrite)

  log(kleur.green('==TS-Config:updated ☕️ ✅ ==\n'))
github makajs / maka / packages / example / maka-app-store / apps / base / component / json-viewer / src / index.js View on Github external
import pkgJson from '../package.json'
import { actionMixin, registerAction, registerComponent } from 'maka'
import JSON5 from 'json5'
import beautify from 'js-beautify/js/lib/beautifier.min'
import JsonViewer from 'react-json-view'
import './style.less'

const name = pkgJson.name

registerAction('beautify', beautify, true)
registerAction('json5', JSON5, true)
registerComponent('JsonViewer', JsonViewer)


const strJson = beautify.js(JSON.stringify(JSON5.parse(`
{
    aa:1,
    bb:2
}`)))


const state = {
    data: {
        json: strJson
    }
}

@actionMixin('base')
class action {
    constructor(option) {
        Object.assign(this, option.mixins)

json5

JSON for Humans

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis