How to use better-ajv-errors - 1 common examples

To help you get started, we’ve selected a few better-ajv-errors 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 GDJiaMi / jm-cli / src / options.ts View on Github external
export default function getOptions(pkg: { [key: string]: any }): JMOptions {
  if (options) {
    return options
  }

  const schemaPath = path.join(__dirname, '../lib/option.schema.json')
  const schema = fs.readJsonSync(schemaPath)
  if (key in pkg) {
    const ajv = new Ajv({ jsonPointers: true })
    const validate = ajv.compile(schema)
    if (validate(pkg[key])) {
      return (options = { ...defaultOptions, ...pkg[key] })
    }
    const errors = prepareErrors(validate.errors)
    const output = betterAjvErrors(schema, pkg[key], errors, { indent: 2 })
    console.log(
      chalk.red(`❌  Configuration error. Check property ${chalk.cyan(key)} of the ${chalk.cyan('package.json')}`),
    )
    console.log(output)
    process.exit(1)
  }

  return (options = defaultOptions)
}

better-ajv-errors

JSON Schema validation for Human

Apache-2.0
Latest version published 3 years ago

Package Health Score

62 / 100
Full package analysis

Popular better-ajv-errors functions