How to use strip-json-comments - 9 common examples

To help you get started, we’ve selected a few strip-json-comments 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 rpl / flow-coverage-report / src / lib / cli / config.js View on Github external
...normalizedConfig(pkg['flow-coverage-report']),
        ...args
      };
    }
  } catch (err) {
    if (process.env.VERBOSE) {
      console.error('Unable to load config from project package.json', packageJSONPath, err);
    }
  }

  let projectConfigPath;

  try {
    projectConfigPath = path.resolve(path.join(getProjectDir(args), '.flow-coverage-report.json'));
    const projectConfigRaw = fs.readFileSync(projectConfigPath);
    const projectConfigData = parseJSON(stripJSONComments(String(projectConfigRaw)));

    if (process.env.VERBOSE) {
      console.log('Loaded config from project dir', projectConfigPath, projectConfigData);
    }

    return {
      ...defaultConfig,
      ...normalizedConfig(projectConfigData),
      ...args
    };
  } catch (err) {
    if (process.env.VERBOSE) {
      console.error('Unable to load config from file', projectConfigPath, err);
    }
  }
github shakacode / bootstrap-loader / src / utils / parseConfig.js View on Github external
export default function(configPath) {
  const configContent = stripComments(fs.readFileSync(configPath, 'utf8'));
  return yaml.safeLoad(configContent);
}
github makeflow / remote-workspace / src / node-shared / config.ts View on Github external
private load(): void {
    let jsonc = FS.readFileSync(this.path, 'utf8');
    let json = stripJSONComments(jsonc);

    this.raw = JSON.parse(json);
  }
}
github Tencent / feflow / packages / feflow-cli / src / core / devkit / config.ts View on Github external
loadJSONConfigFile(filePath: string) {
    this.ctx.logger.debug(`Loading JSON config file: ${filePath}`);

    try {
      return JSON.parse(stripComments(this.readFile(filePath)));
    } catch (e) {
      this.ctx.logger.debug(`Error reading JSON file: ${filePath}`);
      e.message = `Cannot read config file: ${filePath}\nError: ${e.message}`;
      e.messageTemplate = "failed-to-read-json";
      e.messageData = {
        path: filePath,
        message: e.message
      };
      throw e;
    }
  }
github umijs / umi / packages / af-webpack / src / readRc.js View on Github external
export default function(path) {
  const content = stripJsonComments(readFileSync(path, 'utf-8'));
  return JSON.parse(content);
}
github shakacode / bootstrap-loader / src / bootstrap.config.js View on Github external
function parseConfigFile(configFilePath) {
  const configContent = stripComments(fs.readFileSync(configFilePath, 'utf8'));
  try {
    return jsYaml.safeLoad(configContent);
  } catch (YAMLException) {
    throw new Error(`Config file cannot be parsed: ${configFilePath}'`);
  }
}
github mozilla / web-ext / src / cmd / build.js View on Github external
let messageData: LocalizedMessageData;
  let messageContents: string | Buffer;
  let extensionName: string = manifestData.name;

  try {
    messageContents = await fs.readFile(messageFile, {encoding: 'utf-8'});
  } catch (error) {
    throw new UsageError(
      `Error reading messages.json file at ${messageFile}: ${error}`);
  }

  messageContents = stripBom(messageContents);

  try {
    messageData = parseJSON(stripJsonComments(messageContents));
  } catch (error) {
    throw new UsageError(
      `Error parsing messages.json file at ${messageFile}: ${error}`);
  }

  extensionName = manifestData.name.replace(
    /__MSG_([A-Za-z0-9@_]+?)__/g,
    (match, messageName) => {
      if (!(messageData[messageName]
            && messageData[messageName].message)) {
        const error = new UsageError(
          `The locale file ${messageFile} ` +
            `is missing key: ${messageName}`);
        throw error;
      } else {
        return messageData[messageName].message;
github typhonjs-node-tjsdoc / tjsdoc / src / TJSDocCLI.js View on Github external
_createConfigFromFile(configPath)
   {
      configPath = path.resolve(configPath);

      const ext = path.extname(configPath);

      if (ext === '.js')
      {
         return require(configPath);
      }
      else
      {
         const configJSON = fs.readFileSync(configPath, { encode: 'utf8' }).toString();

         return JSON.parse(stripJsonComments(configJSON));
      }
   }
github forcedotcom / lightning-inspector / src / aura / viewer / __mocks__ / BrowserApi.js View on Github external
static async eval(command, callback) {
        if (typeof callback === 'function') {
            callback(command);
        }
    }

    static getLabel(key) {
        if (!labels.hasOwnProperty(key)) {
            return `[${key}]`;
        }

        return labels[key].message;
    }
}

const json = stripJsonComments(fs.readFileSync('_locales/en/messages.json', 'utf8'));
const labels = JSON.parse(json);

strip-json-comments

Strip comments from JSON. Lets you use comments in your JSON files!

MIT
Latest version published 10 months ago

Package Health Score

77 / 100
Full package analysis

Popular strip-json-comments functions