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({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 ajv = new Ajv({processCode: transpileFunc})
    const validate = ajv.compile(schema) // transpiled es7 async function
    validate(data).then(successFunc).catch(errorFunc)
    
    Docs
  • async function test() {
      
      //...
    const schema = JSON.parse(await fs.readFile("./schema/buttplug-schema.json", "utf-8"));
      const validator = new ajv();
      validator.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"));
      const jsonValidator = validator.compile(schema);
      
      //...
    }
    
    
    /buttplugio/buttplug bsd-3-clause
  • module.exports = async function (options) {
    	
    	//...
    return Promise.all([getSchema(options), getContent]).then(
    		([schema, json]) => {
    			const ajv = new Ajv({ extendRefs: true });
    			const valid = ajv.validate(schema, json);
    			if (valid) return json;
    			ajv.errors.forEach((error) =>
    				logger.error(error.message, error.dataPath)
    			);
    
    			throw new Error("Invalid dependencies");
    		}
    	);
    }
    /microsoft/powerbi-visuals-webpack-plugin mit
  • 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
  • Powered by Official black Bloop logo with a period
    download the IDE extension

    View other examples