How to use json5 - 10 common examples

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 vorpaljs / bash-parser / test / _utils.js View on Github external
exports.logDiff = function logDiff(expected, actual) {
	console.log(json.stringify(diff(actual, expected), null, 4));
};
github pattern-lab / patternlab-node / core / lib / pattern_assembler.js View on Github external
function parseDataLinksHelper(patternlab, obj, key) {
    var linkRE, dataObjAsString, linkMatches, expandedLink;

    linkRE = /link\.[A-z0-9-_]+/g;
    dataObjAsString = JSON5.stringify(obj);
    linkMatches = dataObjAsString.match(linkRE);

    if (linkMatches) {
      for (var i = 0; i < linkMatches.length; i++) {
        expandedLink = patternlab.data.link[linkMatches[i].split('.')[1]];
        if (expandedLink) {
          if (patternlab.config.debug) {
            console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + key);
          }
          dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
        }
      }
    }

    var dataObj;
    try {
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 blackmiaool / rn-less / src / index.js View on Github external
traverseProperty(input, function ({ value, property, selector }) {
        if (property === 'transform') {
            const arr = [];
            const match = value.replace(/(\w+)\s*\(([^)]+)\)\s*/g, (nothing, name, value) => {
                if (value.match(/^[\d\.]+$/)) {
                    value = value * 1;
                }
                arr.push({ [name]: value });
            });
            return JSON5.stringify(arr);
        }
    });
    const regexpArr = args.split(',').map(arg => arg.trim()).map(name => new RegExp(`(^|['"])` + name + "([\\[\\.\"? *\/+-]|$)"));
github kulshekhar / ts-jest / src / config / config-set.spec.ts View on Github external
it('should resolve node paths', () => {
    const cs = createConfigSet({ jestConfig: { rootDir: '/root', cwd: '/cwd' } as any, resolve: null })
    const doResolve = (path: string) => cs.resolvePath(path, { throwIfMissing: false, nodeResolve: true })
    expect(doResolve('json5')).toBe(resolve(__dirname, '../../node_modules/json5', require('json5/package.json').main))
    expect(doResolve('./bar.js')).toBe(resolve('/cwd/bar.js'))
    expect(doResolve('bar.js')).toBe(resolve('/root/bar.js'))
    expect(doResolve('/bar.js')).toBe(resolve('/root//bar.js'))
  })
  it('should throw for invalid paths', () => {
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,
    },

json5

JSON for Humans

MIT
Latest version published 1 year ago

Package Health Score

79 / 100
Full package analysis