npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@tailored-apps/dedition

v1.0.0

Published

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

Downloads

22

Readme

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

  • schemaName Identifier for the schema
  • schemaObj is a ajv validation schema (https://www.npmjs.com/package/ajv#validation-keywords)

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)