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

  • 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
  • //...
    const conf = require('../conf');
    
    const ajv = new Ajv({
        schemaId: 'auto',
        allErrors: true,
        verbose: true,
    });
    
    ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
    ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));
    
    function URIfromId(id) {
        return url.parse(id).path;
    }
    
    
    
    //...
    
    /openintegrationhub/openintegrationhub apache-2.0
  • import {_, KeywordCxt} from Ajv
    
    ajv.addKeyword({
      keyword: "even",
      type: "number",
      schemaType: "boolean",
      // $data: true // to support [$data reference](./guide/combining-schemas.md#data-reference), ...
      code(cxt: KeywordCxt) {
        const {data, schema} = cxt
        const op = schema ? _`!==` : _`===`
        cxt.fail(_`${data} %2 ${op} 0`) // ... the only code change needed is to use `cxt.fail$data` here
      },
    })
    
    const schema = {even: true}
    const validate = ajv.compile(schema)
    console.log(validate(2)) // true
    console.log(validate(3)) // false
    
    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
  • const validate = new Ajv().addSchema(schema).addFormat(name, regex).getSchema(uri)
    
    Docs
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples