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 🙏

© 2026 – Pkg Stats / Ryan Hefner

jvalidation

v0.1.4

Published

a simple validation util

Readme

jValidation

a simple util for better validation code semantization.

Notification: this validation is meant to focus on simple type data validation, if you want to do some Array or Object or Function type validation, you may do it before you generate a validation via this util.

API

Very Quick Start

  1. run npm install --save-dev jvalidation or yarn add --save-dev jvalidation

  2. import to your code

import Validation from 'jvalidation'
    // init validation
    let name = 'John'
    let _validation = new Validation(name)
    
    // run validator
    _validation.isChName('请输入纯中文汉字', 'name')

    // get result
    console.log(_validation.result, _validation.info, _validation.invalid)
    // false, '请输入纯中文汉字', [{tag: 'name', info: '请输入纯中文汉字'}]

MultiRules for Same Target

  • supported chainig invocation
import Validation from 'jvalidation'

    let name = 'John'
    let _validation = new Validation(name, {assertion: false})

    _validation.isRequired().isChName().isLengthBetween(3,6,'长度不对')

    console.log(_validation.result, _validation.info, _validation.invalid)
    // false, '长度不对', [[ { tag: 'name', info: '请输入中文字符' }, { tag: 'length', info: '长度不对'}] }]

Group Validation for Different Targets

import { GroupValidation } from 'jvalidation'
    const sample = {
        userName: '我只是个测试的a',
        mobile: '136616666166',
        idCardNo: '310109198701235364X'
    }

you can use this pattern

    let _validation = new GroupValidation(
        [sample.userName, {assertion: false},
        ['isChName', '请输入纯中文', 'name'],
        ['isLengthBetween', 3, 6, '请输入3-6长的字符', 'length']],
        [sample.mobile, null, 'isMobileNo'],
        [sample.idCardNo, null, ['isIdNo', '请输入合法身份证', 'idcard']]
    )
    _validation.validate(false)

or this pattern

    let _validation = new GroupValidation(
        [sample.userName, {assertion: false},
        ['isChName', '请输入纯中文', 'name'],
        ['isLengthBetween', 3, 6, '请输入3-6长的字符', 'length']]
    )
    .compose([sample.mobile, null, 'isMobileNo'])
    .compose([sample.idCardNo, null, ['isIdNo', '请输入合法身份证', 'idcard']])
    _validation.validate(false)

or this pattern

    let _validation = new GroupValidation(
        [sample.userName, {assertion: false},
        ['isChName', '请输入纯中文', 'name'],
        ['isLengthBetween', 3, 6, '请输入3-6长的字符', 'length']],
    ).compose(
        [sample.mobile, null, 'isMobileNo'],
        [sample.idCardNo, null, ['isIdNo', '请输入合法身份证', 'idcard']]
    )
    _validation.validate(false)

to get result you may use .getInvalidInfo()

    _validation.getInvalidInfo()
    // this will return all the invalid items with tags in Object

you may also use .getInvalidTags() to get all the invalid tags you input in an Array

    _validation.getInvalidTags()

Assertion

  • if you want to implement assertion in a single item, just set {assertion: false} as the second prop.
  • if you want to implement assertion assertion mode in group validation, just use .validate() instead of .validate(false) when the group rule of validation is invoked.

for more detail api just check the source code cause this is really really easy to understand...

pleas feel free to rewrite or contribute.