How to use comment-json - 10 common examples

To help you get started, we’ve selected a few comment-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 imodeljs / imodeljs / tools / build / scripts / printconfig.js View on Github external
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on("unhandledRejection", err => {
  throw err;
});

if (argv.config === undefined) {
  console.log("Please provide a configuration file as input with the --config parameter.")
  process.exit(1);
}

var file = argv.config;
var mergedOutput = mergeJson(file);
delete mergedOutput.extends;

var mergedString = json.stringify(mergedOutput, null, 2);
if (argv.out === undefined) {
  console.log(mergedString);
}
else {
  fs.writeFileSync(argv.out, mergedString);
}

function mergeJson(jsonFilePath) {
  var jsonFile = json.parse(fs.readFileSync(jsonFilePath).toString(), null, true);

  if (jsonFile.extends !== undefined && typeof jsonFile.extends === "string") {
    var baseFileName = path.resolve(path.dirname(jsonFilePath), jsonFile.extends)

    if (!fs.existsSync(baseFileName)) {
      baseFileName = path.resolve(path.dirname(jsonFilePath), path.join("node_modules", jsonFile.extends));
    }
github girder / girder / scripts / json_config_merge.js View on Github external
return arr1;
}

var mergedConfigs = configs[0];
configs.slice(1).forEach(function (config) {
    mergedConfigs = arrayMergeRecursive(mergedConfigs, config);
});

// Save merged configs

if (verbose) {
    console.log('Output file ' + outputfile);
}

var output = json.stringify(mergedConfigs, null, 4);

output += '\n';

fs.writeFileSync(outputfile, output);
github jupyterlab / jupyterlab-data-explorer / jupyterlab / packages / coreutils / src / settingregistry.ts View on Github external
async set(plugin: string, key: string, value: JSONValue): Promise {
    // Wait for data preload before allowing normal operation.
    await this._ready;

    const plugins = this.plugins;

    if (!(plugin in plugins)) {
      return this.load(plugin).then(() => this.set(plugin, key, value));
    }

    // Parse the raw JSON string removing all comments and return an object.
    const raw = json.parse(plugins[plugin].raw, null, true);

    plugins[plugin].raw = Private.annotatedPlugin(plugins[plugin], {
      ...raw,
      [key]: value
    });

    return this._save(plugin);
  }
github streetsidesoftware / vscode-spell-checker / packages / client / src / settings / CSpellSettings.ts View on Github external
        .then(cfgJson => (json.parse(cfgJson) as CSpellSettings))
        // covert parse errors into the defaultSettings
github yuvipanda / simplest-notebook / packages / coreutils / src / settingregistry.ts View on Github external
if (!validate || !compose) {
      const errors = this._addSchema(plugin.id, plugin.schema);

      if (errors) {
        return errors;
      }

      return this.validateData(plugin);
    }

    // Parse the raw commented JSON into a user map.
    let user: JSONObject;
    try {
      const strip = true;

      user = json.parse(plugin.raw, null, strip) as JSONObject;
    } catch (error) {
      if (error instanceof SyntaxError) {
        return [
          {
            dataPath: '',
            keyword: 'syntax',
            schemaPath: '',
            message: error.message
          }
        ];
      }

      const { column, description } = error;
      const line = error.lineNumber;

      return [
github streetsidesoftware / cspell / packages / cspell-lib / src / Settings / CSpellSettingsServer.ts View on Github external
function readJsonFile(file: string): CSpellSettings {
    try {
        return json.parse(fs.readFileSync(file).toString());
    }
    catch (err) {
        console.error('Failed to read "%s": %s', file, err);
    }
    return {};
}
github solvedDev / bridge. / src / renderer / components / editor_shell / SingleFile.vue View on Github external
json_object() {
                if(typeof this.content === "string") {
                    try {        
                        return cJSON.parse(this.content, undefined, true);
                    } catch(e) {
                        if(this.content == "") return {};
                        TabSystem.setCurrentInvalid();
                        this.$store.commit("removeLoadingWindow", { id: "open-file" });
                        return "error";
                    }
                }
                return this.content;
            },
github tars / tars-cli / lib / command-actions / utils / update-project / update-plugins-config.js View on Github external
module.exports = function updatePluginsConfig(downloadedPluginsConfigString, currentPluginsConfigString, tarsConfig, currentTarsVersion) {
    let parsedPluginsConfig = {};
    const parsedDownloadedPluginsConfig = commentJson.parse(downloadedPluginsConfigString);
    const browserSyncConfig = tarsConfig.browserSyncConfig;

    if (semver.cmp(currentTarsVersion, '<', '1.8.0') && browserSyncConfig && tarsConfig.autoprefixerConfig) {
        parsedPluginsConfig = {
            browserSync: {
                server: {
                    baseDir: browserSyncConfig.baseDir
                },
                port: browserSyncConfig.port,
                open: browserSyncConfig.open,
                browser: browserSyncConfig.browser,
                startPath: browserSyncConfig.startUrl,
                notify: browserSyncConfig.useNotifyInBrowser,
                injectChanges: browserSyncConfig.injectChanges
            },
            autoprefixerConfig: tarsConfig.autoprefixerConfig,
github streetsidesoftware / vscode-spell-checker / server / src / CSpellSettingsServer.ts View on Github external
function readJsonFile(file): any {
        try {
            return json.parse(fs.readFileSync(file).toString());
        }
        catch (err) {
        }
        return defaultValues;
    }
github Bearer / bearer-js / packages / package-init / src / index.ts View on Github external
return this.withLoader('Init Typescript stuff', async () => {
      await this.runCommand('yarn tsc --init')
      const configFile = path.join(this.cwd, 'tsconfig.json')
      const src = path.join(this.cwd, 'src')
      const config = json.parse(fs.readFileSync(configFile, { encoding: 'utf8' }), undefined, true)

      set(config, 'extends', BEARER_TSCONFIG)
      fs.writeFileSync(configFile, json.stringify(config, null, 2))
      if (!fs.existsSync(src)) {
        fs.mkdirSync(src)
        fs.writeFileSync(path.join(src, 'index.ts'), '')
      }
    })
  }

comment-json

Parse and stringify JSON with comments. It will retain comments even after saved!

MIT
Latest version published 3 months ago

Package Health Score

76 / 100
Full package analysis

Popular comment-json functions