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

@jsonql/validator-core

v0.12.2

Published

@jsonql/validator-core provide all core functions for @jsonql/validator and config-validator

Downloads

3

Readme

@jsonql/validator-core

This library provide all the core validation functions for couple other libraries. Also it has a plugin system, and some commonly use plugins to help with the validation.

ValidatorPlugins

As of version 0.8.0, we move all the plugins related methods into this module. And this will be able to share between many different @jsonql/validator instance to use, instead of every time we init a ValidatorFactory and have to load all the plugins again.

More to come

About the plugin system

The core library provide function to validate against primitive types and their value. When we need to test the value in a more specific way, we can use the plugin system. Also this plugin system allow developer to create their own plugin to suit their specific need.

A plugin file looks like this:

// test for integer
const name = "int"

function main(value: number): boolean {
  return Number.isInteger(value)
}

export default {
  name,
  main,
}

If you require additional parameter:

// example from our built-in plugin between

// between
import moreThan from './more-than'
import lessThan from './less-than'

const name = 'between'

function main(
  max: number,
  min: number,
  value: number | string
): boolean {

  return lessThan.main(max, value) && moreThan.main(min, value)
}

// Then when we register it, we know what `params` we should expect
export default {
  main,
  name,
  params: ['max', 'min']
}

The value that will get validate MUST be the last argument. Because we will curry the main method before insert into our validation queue system.

Built-in plugins

Here is list of available built-in plugins:

between

{ plugin: 'between', max: 100, min: 1}

Check a number or string (length) is < max and > min

email

{ plugin: 'email'}

Check if the input is email address

float

{ plugin: 'float' }

Check if the value is a float number

int

{ plugin: 'int' }

Check if the value is an signed integer

lessThanEqual

{ plugin: 'lessThanEqual', num: 100}

Check if a number or string (length) is =< num

lessThan

{ plugin: 'lessThan', num: 100}

Check if a number or string (length) is < num

moreThanEqual

{ plugin: 'moreThanEqual', num: 100}

Check if a number or string (length) is >= num

moreThan

{ plugin: 'moreThan', num: 100}

Check if a number of string (length) is > num

uint

{ plugin: 'uint' }

Check if a number is a unsigned integer (>=0)

within

{ plugin: 'within', max: 100, min: 1}

Check if a number or string (length) is <= max and >= min


JSONQL