How to use the js-yaml.FAILSAFE_SCHEMA function in js-yaml

To help you get started, we’ve selected a few js-yaml 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 greenkeeperio / greenkeeper / jobs / create-initial-branch.js View on Github external
async function travisTransform (config, travisyml) {
  try {
    var travis = yaml.safeLoad(travisyml, {
      schema: yaml.FAILSAFE_SCHEMA
    })
  } catch (e) {
    // ignore .travis.yml if it can not be parsed
    return
  }
  const onlyBranches = _.get(travis, 'branches.only')
  if (!onlyBranches || !Array.isArray(onlyBranches)) return

  const greenkeeperRule = onlyBranches.some(function (branch) {
    if (_.first(branch) !== '/' || _.last(branch) !== '/') return false
    try {
      const regex = new RegExp(branch.slice(1, -1))
      return regex.test(config.branchPrefix)
    } catch (e) {
      return false
    }
github greenkeeperio / greenkeeper / jobs / deprecate-nodejs-version.js View on Github external
function travisTransform (travisYML) {
    try {
      var travisJSON = yaml.safeLoad(travisYML, {
        schema: yaml.FAILSAFE_SCHEMA
      })
    } catch (e) {
      // ignore .travis.yml if it can not be parsed
      return
    }
    // No versions specified in travis YML
    if (!_.get(travisJSON, 'node_js')) return

    const nodeVersionFromYaml = getNodeVersionsFromTravisYML(travisYML)
    const hasNodeVersion = getNodeVersionIndex(nodeVersionFromYaml.versions, nodeVersion, codeName, true) !== -1
    if (!hasNodeVersion) return
    const updatedTravisYaml = addNewLowestAndDeprecate({
      travisYML,
      nodeVersion,
      codeName,
      newLowestVersion,
github greenkeeperio / greenkeeper / jobs / update-nodejs-version.js View on Github external
function travisTransform (travisYML) {
    try {
      var travisJSON = yaml.safeLoad(travisYML, {
        schema: yaml.FAILSAFE_SCHEMA
      })
    } catch (e) {
      // ignore .travis.yml if it can not be parsed
      return
    }
    // No node versions specified in root level of travis YML
    // There may be node versions defined in the matrix or jobs keys, but those can become
    // far too complex for us to handle, so we don’t
    if (!_.get(travisJSON, 'node_js')) return

    const nodeVersionFromYaml = getNodeVersionsFromTravisYML(travisYML)
    const hasNodeVersion = getNodeVersionIndex(nodeVersionFromYaml.versions, nodeVersion, codeName) !== -1
    if (hasNodeVersion) return

    const updatedTravisYaml = addNodeVersionToTravisYML(travisYML, nodeVersion, codeName, nodeVersionFromYaml)
    return updatedTravisYaml
github vazco / meteor-universe-i18n / builder.js View on Github external
const type = path[path.length - 1].toLowerCase();
        const packageName = file.getPackageName();
        let translations;
        if (type === 'json') {
            try {
                translations = JSON.parse(stripJsonComments(source));
            } catch (e) {
                file.error({
                    message: `Parsing Error: ${e.message}\n`
                });
                return;
            }
        } else {
            try {
                translations = YAML.load(source, {
                    schema: YAML.FAILSAFE_SCHEMA,
                    onWarning: console.warn.bind(console)
                });
            } catch (e) {
                file.error({
                    message:  `Parsing Error: ${e.message}\n`
                });
                return;
            }
        }

        let locale = translations._locale || getLocaleFromPath(filePath);
        if (!locale) {
            file.error({
                message: `Cannot find localization for file: ${file} ${(
                    packageName ? 'in package: ' + packageName : ''
                )}. Please change file name or set _locale key in file`
github sider / TyScan / src / config / loader.ts View on Github external
export function load(path: string, tsconfigPath: string) {
  let txt;
  try {
    txt = fs.readFileSync(path).toString();
  } catch {
    throw new Error(`${path} not found`);
  }

  let obj;
  try {
    obj = yaml.safeLoad(txt, { schema: yaml.FAILSAFE_SCHEMA });
  } catch {
    throw new Error('Invalid YAML');
  }

  return loadConfig(obj, tsconfigPath);
}
github sider / TyScan / src / loader.ts View on Github external
export function load(path: string) {
  let txt;
  try {
    txt = fs.readFileSync(path).toString();
  } catch {
    throw new Error(`${path} not found`);
  }

  let obj;
  try {
    obj = yaml.safeLoad(txt, { schema: yaml.FAILSAFE_SCHEMA });
  } catch {
    throw new Error('Invalid YAML');
  }

  return loadConfig(obj);
}
github envkey / envkey-app / envkey-react / src / lib / parse / index.js View on Github external
  toYaml = obj => yaml.safeDump(JSON.parse(JSON.stringify(obj)), {schema: yaml.FAILSAFE_SCHEMA}),
github etienne-martin / device-detector-js / src / utils / yaml-loader.ts View on Github external
const loadYaml = (slug: string): any => {
  return YAML.load(fs.readFileSync(slug, "utf8"), {
    schema: YAML.FAILSAFE_SCHEMA
  });
};
github facebookincubator / marketing-data-file-uploader / src / mdfu / ConfigsReader.js View on Github external
export const readConfigsFromFile = (
  configFilePath: string
): UserSuppliedConfigs => {
  try {
    return filterOptions(yaml.safeLoad(
      fs.readFileSync(configFilePath, 'utf8'),
      {schema: yaml.FAILSAFE_SCHEMA},
    ));
  } catch (err) {
    throw new Error(`${ERROR_CANNOT_PARSE_CONFIG_FILE.description}: ${err.message}`);
  }
};
github etienne-martin / device-detector-js / dist / utils / yaml-loader.js View on Github external
const loadYaml = (slug) => {
    return YAML.load(fs.readFileSync(slug, "utf8"), {
        schema: YAML.FAILSAFE_SCHEMA
    });
};
exports.loadRegexes = (slug) => {