New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tailored-apps/dedition

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tailored-apps/dedition

Wrapper for AJV which can read all json files and adds them as schemas

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

DEDITION

  • This package combines ajv (https://www.npmjs.com/package/ajv) and ajv-error (https://www.npmjs.com/package/ajv-errors)
  • It also offers functionality to add validation schemas from .json files

Usage

import validator from 'dedition'

Initialize

const valid = validator({ ajvOptions = {}, logger = createDefaultLogger()} = {})
  • ajvOptions are all the options which are normally passed to ajv (https://www.npmjs.com/package/ajv#options)
  • logger can be passed optionally (i.e.: a winston instance), if not passed a default logger is created

There are two ajv-options set at any time:

  • allErrors = true
  • jsonPointers = true

These are mandatory and CANNOT be overwritten, since ajv-errors needs these two options to function

After initializing validator you have access to several functions

Functions

addSchema(schemaName: string, schemaObj: object)

Adds a given schema to the ajv instance using the passed schemaName as identifier

Returns: void

async addSchemaFromFile(filePath: string)

Adds the schema from the given filePath (must be a valid .json file) to the ajv instance.

The identifier is the fileName without the .json-extension

i.e.: Person.json -> Identifier: Person

  • filePath is the path to the .json file

Returns: void

async addSchemaFromFolder(folderPath: string)

Adds all the schemas from the given folderPath (only files inside this folder with extension .json are recognized) to the ajv instance.

The identifier is the file name without the .json-extenision

i.e.: Person.json -> Identifier: Person

  • folderPath is the path to the folder where the schema files are located

Returns: void

validate(schemaName: string, obj: object)

Validates an Object with the given schema which is identified by the schema identifier string

  • schemaName: Name of the schema
  • obj: Object to validate

Returns: true if valid, otherwise 400: BadRequestError (from package http-errors)

removeAllSchemas()

Removes all the schemas from the ajv instance

Returns: void

schemaExists(schemaName: string)

Checks wheter an schema exists or not

  • schemaName: Name of the schema

Returns: True or False wheter the schema exists or not

getSchema(schemaName: string)

Returns the schema for a given schemaName

  • schemaName: Name of the schema

Returns: Validation Schema object or 500: InternalServerError (from package http-errors)

Keywords

FAQs

Package last updated on 09 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc