How to use where clause in Knex
Create refunds with Stripe
Load HTML with Cheerio
How to send POST request with Axios
Find intersection of array in Lodash
Powered by Official white Bloop logo with a period

Terms / Privacy / Search / Support

  • const ajv = new Ajv({processCode: transpileFunc})
    const validate = ajv.compile(schema) // transpiled es7 async function
    validate(data).then(successFunc).catch(errorFunc)
    
    Docs
  • const ajv = new Ajv({loadSchema: loadSchema})
    
    ajv.compileAsync(schema).then(function (validate) {
      const valid = validate(data)
      // ...
    })
    
    async function loadSchema(uri) {
      const res = await request.json(uri)
      if (res.statusCode >= 400) throw new Error("Loading error: " + res.statusCode)
      return res.body
    }
    
    Docs
  • const fs = require("fs")
    const path = require("path")
    const Ajv = require("ajv")
    const standaloneCode = require("ajv/dist/standalone").default
    
    const schema = {
      $id: "https://example.com/bar.json",
      $schema: "http://json-schema.org/draft-07/schema#",
      type: "object",
      properties: {
        bar: {type: "string"},
      },
      "required": ["bar"]
    }
    
    // The generated code will have a default export:
    // `module.exports = <validateFunctionCode>;module.exports.default = <validateFunctionCode>;`
    const ajv = new Ajv({code: {source: true}})
    const validate = ajv.compile(schema)
    let moduleCode = standaloneCode(ajv, validate)
    
    // Now you can write the module code to file
    fs.writeFileSync(path.join(__dirname, "../consume/validate-cjs.js"), moduleCode)
    
    Docs
  • const ajv = new Ajv({ allErrors: true })
    const validate = ajv.compile(schema.valueOf())
    let user = {}
    let valid = validate(user)
    console.log({ valid }) //=> {valid: false}
    console.log(validate.errors) //=> {valid: false}
    Docs
  • ajv.addKeyword({
      keyword: "constant",
      validate: (schema, data) =>
        typeof schema == "object" && schema !== null ? deepEqual(schema, data) : schema === data,
      errors: false,
    })
    
    const schema = {
      constant: 2,
    }
    const validate = ajv.compile(schema)
    console.log(validate(2)) // true
    console.log(validate(3)) // false
    
    const schema = {
      constant: {foo: "bar"},
    }
    const validate = ajv.compile(schema)
    console.log(validate({foo: "bar"})) // true
    console.log(validate({foo: "baz"})) // false
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples