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({ 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: "range",
      type: "number",
      compile([min, max], parentSchema) {
        return parentSchema.exclusiveRange === true
          ? (data) => data > min && data < max
          : (data) => data >= min && data <= max
      },
      errors: false,
      metaSchema: {
        // schema to validate keyword value
        type: "array",
        items: [{type: "number"}, {type: "number"}],
        minItems: 2,
        additionalItems: false,
      },
    })
    
    const schema = {
      range: [2, 4],
      exclusiveRange: true,
    }
    const validate = ajv.compile(schema)
    console.log(validate(2.01)) // true
    console.log(validate(3.99)) // true
    console.log(validate(2)) // false
    console.log(validate(4)) // false
    
    Docs
  • const userValidator = compile( userSchema );
    userValidator( data );
    // { ok: true } or
    // { ok: false, errors: [Ajv errors...], explanation: string }
    Docs
  • ajv.addKeyword({
      keyword: "range",
      type: "number",
      schemaType: "array",
      implements: "exclusiveRange",
      compile: ([min, max], parentSchema) =>
        parentSchema.exclusiveRange === true
          ? (data) => data > min && data < max
          : (data) => data >= min && data <= max,
    })
    
    const schema = {range: [2, 4], exclusiveRange: true}
    const validate = ajv.compile(schema)
    console.log(validate(2.01)) // true
    console.log(validate(3.99)) // true
    console.log(validate(2)) // false
    console.log(validate(4)) // false
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples