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

check-types-v2

v2.2.2

Published

New version of check types library

Downloads

3

Readme

check-types-v2

npm version GitHub license Maintenance

New version of check types library. Check on npm and github.

🎉 Version 2.2.x is live 🎉

Check out for changes in the CHANGELOG:

Changelog

Supporting the project

Maintaining a project takes time. To help allocate time, you can Buy Me a Coffee 😉

Install

npm install check-types-v2 --save
yarn add check-types-v2

Example

Following a generic example, full documentation is under construction.

const { Types, CheckTypes, Schema } = require('check-types-v2');
// Get data types helpers
const { String, Array, Number, Boolean, Float } = new Types();
// Call a new instance of CheckTypes only once.
const CheckType = new CheckTypes();

// Set a custom schema to validate data
const customSchema = new Schema({
  firstname: {
    type: String,
    required: true,
    default: null,
    match: /[A-z]/ig
  },
  roles: {
    type: Array,
    of: [String],
    required: true,
    enum: ['GUEST', 'USER', 'ADMIN'],
    default: ['ADMIN']
  },
  role: {
    type: String,
    required: true,
    enum: ['GUEST', 'USER', 'ADMIN'],
    default: 'ADMIN'
  },
  emails: {
    type: Array,
    of: String,
    required: true,
    default: [],
    match: /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ig
  },
  floatNumber: {
    type: Float,
    required: true,
    default: 1.5
  }
});

// Some custom features example
const value1 = CheckType.setValue().Any().Required().Default('test').Enum(['test']).check({ extended: true });
// Array and nested array example
const value2 = CheckType.setValue([1, 'test', true]).String().Array({ of: [String, Number, Boolean] }).check({ extended: true });

// Fake request body
const obj = {
  firstname: "[email protected]",
  username: 'test1',
  emails: ["[email protected]"],
  roles: ['ADMIN'],
  role: 'USER',
  floatNumber: 5.3
};
// Use schema to validate
const value3 = CheckType.setValue(obj).setSchema(customSchema).check({ strict: false, extended: true });

// Outputs
console.log(value1); // Will output: test
console.log(value2); // Will output: [ 1, 'test', true ]

console.log(value3);
/**
 * Will output:
 * {
 *   firstname: '[email protected]',
 *   username: 'test1',
 *   emails: [ '[email protected]' ],
 *   roles: [ 'ADMIN' ],
 *   role: 'USER',
 *   floatNumber: 5.3
 * }
 */

Examples

Check the examples directory. New examples will added soon.

To do

This project is under active maintenance. New features soon.

To fix

  • [X] Fix errors handler, it takes the same error multiple times
  • [X] Fix setValue, it may cause issue on schema processing

Improved

  • [X] Integrate <Float> and <Int> validation type

Coming Soon Features

  • [ ] Integrate <Class> validation type
  • [ ] Integrate <Array>: { of: <Schema> } validation type
  • [X] Integrate separate class for better error handling
  • [X] Create middleware helpers compatible with express.js framework

Generic Task

  • [ ] Write complete documentation
  • [ ] Write examples for each function