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

acr

v1.3.3

Published

An async, extensible, elegant validation.

Downloads

56

Readme

Acr

NPM version build status code coverage styled with prettier license

优雅、易扩展的异步验证组件。

在实现上借鉴了 joiyup 的 api 风格,重新设计底层实现,具有非常强的扩展性。

特性

  • 全异步验证
  • 高度可扩展
  • 链式操作(定义和使用)
  • 国际化
  • Typescript
  • 参数命名
  • 数据转换
  • 默认值 #2
  • 逻辑验证 #3

安装

npm

npm install acr

yarn

yarn add acr

使用

// 验证多个
const { name, age, gender } = await acr.validate({
    name: 'abel',
    age: 18,
    gender: ''
}, {
    name: acr.string().equal('abel'),
    age: acr.number().min(16).max(20),
    gender: acr.string().in(['male', 'female']).default('male')
});

console.log(name, age, gender); // abel 18 male

// 条件验证
await acr.validate({
    name: 'abel',
    age: 18,
    gender: 'male'
}, {
    // 当 name 等于 abel 时,验证 age 是否在 16-20 之间
    age: acr.when('name', 'abel', () => {
        return acr.number().min(16).max(20);
    }),
    // 当闭包返回 true 时,验证 gender 必须等于 male
    gender: acr.when(data => {
        return data['name'] === 'abel';
    }, () => {
        return acr.string().equal('male');
    })
});


// 验证失败处理
try {
    await acr.validate({
        name: 'abel',
    }, {
        name: acr.string().equal('zbel'),
    });
} catch (error) {
    console.log(error); // ValidationError
}

配置

传入配置并创建一个 acr 实例,接下来的一切都在这个实例上完成。

const Acr = require('acr');

const acr = new Acr({
    lang: 'zh-cn',
    chains: {
        string: {
            transform: String
        }
    }
});

文档

快速开始

配置说明

详细文档

相关

egg-acr:基于 acr 实现的 eggjs 版本的异步验证插件。

成员

| Name | Website | | -------- | ---------------------- | | abel | https://abel.seek.cx |

License

MIT © seekcx