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

sterilizer

v0.1.1

Published

Simple javascript sterilizer & validator

Downloads

109

Readme

Testing

Introduction

  • Sterilizer
    Remove specified symbols
    移除指定符号字符
  • Validator
    Validate input value with sequelize similar interface
    简单的中文前端校验器,使用和 Sequelize 基本相同的接口名称,方便前后端代码保持一致

Usage

Install

npm install sterilizer

Import

ES6

import { sterilizer, validator } from "sterilizer/index.js";

Node.js

const { sterilizer, validator } = require("sterilizer");

Sterilizer

interface

sterilizer(str:string,chain:boolean).<method>(symbols:string)+.toString()?

example

sterilizer("abc~!@###-$").kill().toString(); //移除所有符号字符
// => abc
sterilizer("abc~!@###-$").kill("-#").toString(); //移除指定符号
// => abc~!@$
sterilizer("abc~!@###-$").live("@").toString(); //移除除指定符号外的所有符号字符
// => abc@
sterilizer("abc~!@###-$", true).kill("-#").remove("a").toString(); //链式调用
// => bc~!@$

method

chain

  • kill(symbols) remove the specified symbols
  • live(symbols) remove all the symbols exclude args
  • safe() remove htmlspecialchars + urlspecialchars
  • removeHSC() remove htmlspecialchars
  • removeURL() remove urlspecialchars
  • removeSpace() remove all the space
  • remove(words[,replacement]) remove specified words or replace it by replacement
  • removeHTMLtag() remove all the HTML tags

output

  • toString() output the result

other

  • has([symbol]) return boolean

Validator

interface

validator(str:string,options:object)

example

validator("abc123~!", {
    isOptional: true,
    isNumeric: true,
});
// => false
validator(null, {
    isOptional: true,
});
// => true

options

{
    isOptional : true,        // 可选的,匹配'',null,undefined
    len: [2,10]或5或'5',      // 仅允许指定长度或在指定区间的值
    notEmpty:true,            // 不允许出现空字符串

    is: /^[a-z]+$/i,          // 匹配这个 RegExp
    not: /^[a-z]+$/i,         // 不匹配 RegExp

    isAlpha: true,            // 只允许字母
    isAlphanumeric: true,     // 将仅允许使用字母数字,因此 '_abc' 将失败

    isNumeric: true,          // 只允许数字
    isInt: true,              // 检查有效的整数
    isFloat: true,            // 检查有效的浮点数,可以为整数
    max: 23,                  // 仅允许值 <= 23
    min: 23,                  // 仅允许值 >= 23

    isIn: ['foo', 'bar'],     // 检查值是其中之一
    notIn: ['foo', 'bar'],    // 检查值不是这些之一

    //中文
    isEmail: true,            // 限英文域名但支持中文用户名
    isChinese: true,          // 限简体中文字符
    isIdentityCard: true,     // 限大陆身份证(需二次校验有效性)
    isMobilePhone: true,      // 限中国大陆手机号(需验证码校验有效性)
}