How to use the comment-json.parse function in comment-json

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 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'), '')
      }
    })
  }
github teambit / bit / src / e2e-helper / e2e-bitmap-helper.ts View on Github external
read(bitMapPath: string = path.join(this.scopes.localPath, BIT_MAP), withoutComment = true) {
    const map = fs.readFileSync(bitMapPath) || {};
    return json.parse(map.toString('utf8'), null, withoutComment);
  }

comment-json

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

MIT
Latest version published 23 days ago

Package Health Score

83 / 100
Full package analysis

Popular comment-json functions