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

jvd.js

v1.2.2

Published

js validator

Downloads

18

Readme

jvd.js

js validator, an awesome validator for js

just do it

npm i --save jvd.js
var JVD = require('jvd.js')

// test 
JVD().isString().gt(23).lt(13).test(null)
// test 81 > 10  and 81 < 80
JVD().isNumber().gt(10).lt(80).test(81)
// test 110 >=10  and 110 <= 100
JVD().isNumber().not().lt(10).not().gt(100).test(110)
// test 9 < 10 or 9 > 100
JVD().isNumber().lt(10).or().gt(100).test(9)


// test not empty
JVD().anything().test(null)
// test required
JVD().required().test('')
// test 25 between 24 and 27
JVD().between(24,27).test(25)
//test 25 between 24 and 23
JVD().between(24,23).test(25)
//test json equils
JVD().equils({name : 'LiSA'},(n1,n2)=>{return n1.name == n2.name}).test({'name':'LiSA'})
//test array contains 
JVD().in([1,3,5,7]).test(5)
//test 'hello' equils 'hi'
JVD().is('hello').test('hi')
//test is Array
JVD().isArray().test([])
//test is AsyncFunction
JVD().isAsyncFunction().test(()=>{})
// test is int
JVD().isInteger().test(1.1)
// test is JSON
JVD().isJSON().test({})
// test is regexp
JVD().isRegExp().test(/ab/g)
// test matches
JVD().match(/abc/g).test('helloabcaa')

采用表达式

表达式更简单易写

 //JVD().isString().gt(23).lt(13).run(null)
JVD("?''&&>23&&<13").run(null)
//JVD().isNumber().gt(10).lt(80).run(81)
JVD("?d&>10&<80").run(81)
//JVD().isNumber().not().lt(10).not().gt(100).run(110)
JVD("?d&!<10&!>100").run(110)
//JVD().isNumber().lt(10).or().gt(100).test(9)
JVD("?d&<10|?>100").test(9)

// JVD().anything().test(null)
JVD('!!').test(null)
JVD("!!").test(9)
// JVD().required().test('')
JVD("!!").test('')
// JVD().between(24,27).test(25)
JVD("?(24,27)").test(25)
// JVD().between(24,23).test(25)
JVD("?(24,23)").test(25)
// JVD().equils({name : 'LiSA'},(n1,n2)=>{return n1.name == n2.name}).test({'name':'LiSA'})
// JVD().in([1,3,5,7]).test(5)
JVD("?[1,3,5,7]").test(5)
// JVD().is('hello').test('hi')
JVD("='hello'").test('hello')
// JVD().isArray().test([])
JVD("?[]").test([1,2])
// JVD().isAsyncFunction().test(()=>{})
JVD("?async").test(()=>{})
// JVD().isInteger().test(1.1)
JVD("?int").test(1.1)
// JVD().isJSON().test({})
JVD("?j").test({})
// JVD().isRegExp().test(/ab/g)
JVD("?//").test(/ab/g)
// JVD().match(/abc/g).test('helloabcaa')
JVD("?/abc/").test('helloabcaa')

说明

| expression | jvd方法名称 | not | remark | | ----------------------------------------- | ------------------------ | ----------------------------------------- | ------------------------------------------------------------ | | & && | . | | 内置操作符, and | | ||| | or | | 内置操作符 | | ! | not | | 内置操作符 | | ?''?string | isString | !'' !string | | | ?d?number | isNumber | !d !number | | | ?int | isInteger | !int | | | ?function?fn?fun?method | isFunction | !function!fn!fun!method | | | ?sync | isSyncFunction | !sync | | | ?async | isAsyncFunction | !async | | | ?json or ?j or ?{} or ?object | isJSON | !json or !j or !{} or !object | | | ?[] or ?array | isArray | ![] or !array | | | ?// or ?regexp | isRegExp | !// or !regexp | | | !! | requiredanything | | | | ?/ab/ | patternmatch | !/ab/ | | | ?>12>12 | gtgreaterThan | !>12<=12 | 当待验证数据是字符串时,比较字符串长度当验证数据为数组时,比较数组长度 | | ?<12<12 | ltlitterThan | !<12>=12 | 同上 | | ?(1,200.2) | betweenrange | !(1,200.2) | | | ?[1,'a','ccc'] | oneOfin | ![1,'a','ccc'] | | | ?=1?='b'='dd' | equilstoBeis | !=2 | | | | transInfo(属性) | | 字符串表达式转换结果,用于判断字符串是否可以转换为jvd | | | regadd | | 用于扩展jvd的方法,可用于覆盖现有实现 | | | testrungo | | 执行jvd验证,核心方法 | | | isJVD | | 用于判断是否为JVD,永久返回true | | | $ | | 空实现,根据传值判断是否返回true,不传值返回true |

如何扩展

var JVD = require('jvd.js')

var jvd = JVD()
//这里注意 参数data和options是必须的 
jvd.reg('hello', (data,options,yourParam) => {
    console.log(options.hi)
    console.log(yourParam)
    if (data && data =='hello')
        return true
    return false
})

var options = { hi : 'good days'}
jvd.hello('here is your param').test('hello',options)