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

opticore-validator

v1.0.3

Published

Validator schema with many rule, and custom message

Downloads

44

Readme

OptiCore Validator

It a validator that allow to validate a data schema by many rule and customized message.

Install

npm i opticore-validator

ES6

import validator from 'opticore-validator';

Example

const schema = {
    name: [
        { rule: 'required', message: 'The name can not be empty' },
        { rule: 'minLength', args: [3] }
    ],
    password: [
        { rule: 'required', message: 'You must provide a value' },
        { rule: 'minLength', args: [8], message: 'A password must contain min 8 char.' },
        { rule: 'containsUppercase', message: 'You must to add upper case char in the password' },
        { rule: 'containsLowercase', message: 'you need to add lower case char' }
    ],
}
const dataPayload = {
    name: 'Jo',
    password: 'word1!',
}

result

{
  name: [ 'Field name failed validation rule minLength  with arguments 3.' ], // Th a default message
  password: [
    'A password must contain min 8 char.',
    'You must to add upper case char in the password'
  ]
}

Security sues

Validators

Here a lt of the validators currently available.

| Rule Validator | Description | |-------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | contains(value: any, seed: string) | check if the value contains the seed. | | equals(value: any, comparon: any) | check if the value matches the comparon. | | abaRouting(value: any) | check if the value an ABA routing number for US bank account / cheque. | | alpha(value: any) | check if the value contains only letters (a-zA-Z). | | alphanumeric(value: any) | check if the value contains only letters and numbers (A-Za-z0-9). | | ascii(value: any) | check if the value contains ASCII chars only. | | array(value: any) | check if the value an array. | | base32(value: any) | check if the value base32 encoded. | | base58(value: any) | check if the value base58 encoded. | | base64(value: any) | check if the value base64 encoded. | | bic(value: any) | check if the value a BIC (Bank Identification Code) or SWIFT code. | | boolean(value: any) | check if the value a boolean. If loose set to false, the validator will strictly match ['true', 'false', '0', '1']. If loose set to true, the validator will also match 'yes', 'no', and will match a valid boolean value of any case. (e.g.: ['true', 'True', 'TRUE']). | | btcAddress(value: any) | check if the value a valid BTC address. | | byteLength(value: any, min: number, max?: number) | check if the value's length (in UTF-8 bytes) falls in a range.you can define min: 0, max: undefined. | | **creditCard(value: any)** | check if the value a credit card number. | | **currency(value: any)** | check if the value a valid currency amount. | | **dataURI(value: any)** | check if the value a [data uri format][Data URI Format]. | | **date(value: any)** | check if the value a valid date. e.g. [2002-07-15, new Date()].<br/><br/> options an object which can contain the keysformat, strictModeand/ordelimiters.<br/><br/>format a value and defaults toYYYY/MM/DD.<br/><br/>strictMode a boolean and defaults tofalse. If strictMode set to true, the validator will reject strings different fromformat.<br/><br/> delimiters an array of allowed date delimiters and defaults to['/', '-']. | | **email(str [, options])** | check if the value an email.<br/><br/>options an object which defaults to{ allow_dplay_name: false, require_dplay_name: false, allow_utf8_local_part: true, require_tld: true, allow_ip_domain: false, allow_underscores: false, domain_specific_validation: false, blacklted_chars: '', host_blacklt: [] }. If allow_dplay_name set to true, the validator will also matchDplay Name . If require_dplay_name set to true, the validator will reject strings without the formatDplay Name . If allow_utf8_local_part set to false, the validator will not allow any non-Englh UTF8 character in email address' local part. Ifrequire_tld set to false, email addresses without a TLD in their domain will also be matched. Ifignore_max_length set to true, the validator will not check for the standard max length of an email. Ifallow_ip_domain set to true, the validator will allow IP addresses in the host part. Ifdomain_specific_validation true, some additional validation will be enabled, e.g. dallowing certain syntactically valid email addresses that are rejected by Gmail. Ifblacklted_charsreceives a value, then the validator will reject emails that include any of the characters in the value, in the name part. Ifhost_blacklt set to an array of strings and the part of the email after the@symbol matches one of the strings defined in it, the validation fails. Ifhost_whitelt set to an array of strings and the part of the email after the@ symbol matches none of the strings defined in it, the validation fails. | | **notBlank(str [, options])** | check if the value has a length of zero.<br/><br/>options an object which defaults to{ ignore_whitespace: false }. | | **ethereumAddress(str)** | check if the value an [Ethereum][Ethereum] address. Does not validate address checksums. | | **float(str [, options])** | check if the value a float.<br/><br/>options an object which can contain the keysmin, max, gt, and/or ltto validate the float within boundaries (e.g.{ min: 7.22, max: 9.55 }) it also has locale as an option.<br/><br/>minandmaxare equivalent to 'greater or equal' and 'less or equal', respectively whilegtandlt are their strict counterparts.<br/><br/>localedetermines the decimal separator and one of['ar', 'ar-AE', 'ar-BH', 'ar-DZ', 'ar-EG', 'ar-IQ', 'ar-JO', 'ar-KW', 'ar-LB', 'ar-LY', 'ar-MA', 'ar-QA', 'ar-QM', 'ar-SA', 'ar-SD', 'ar-SY', 'ar-TN', 'ar-YE', 'bg-BG', 'cs-CZ', 'da-DK', 'de-DE', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NZ', 'en-US', 'en-ZA', 'en-ZM', 'eo', 'es-ES', 'fr-CA', 'fr-FR', 'hu-HU', 'it-IT', 'nb-NO', 'nl-NL', 'nn-NO', 'pl-PL', 'pt-BR', 'pt-PT', 'ru-RU', 'sl-SI', 'sr-RS', 'sr-RS@latin', 'sv-SE', 'tr-TR', 'uk-UA']. Locale lt validator.FloatLocales. | | **fqdn(str [, options])** | check if the value a fully qualified domain name (e.g. domain.com).<br/><br/>options an object which defaults to{ require_tld: true, allow_underscores: false, allow_trailing_dot: false, allow_numeric_tld: false, allow_wildcard: false, ignore_max_length: false }. If allow_wildcard set to true, the validator will allow domain starting with.(e.g..example.comor*.shop.example.com). | | **freightContainerID(str)** | alias for O6346, check if the value a valid [O 6346](https://en.wikipedia.org/wiki/O_6346) shipping container identification. | | **fullWidth(str)** | check if the value contains any full-width chars. | | **halfWidth(str)** | check if the value contains any half-width chars. | | **hash(str, algorithm)** | check if the value a hash of type algorithm.<br/><br/>Algorithm one of ['crc32', 'crc32b', 'md4', 'md5', 'ripemd128', 'ripemd160', 'sha1', 'sha256', 'sha384', 'sha512', 'tiger128', 'tiger160', 'tiger192']. | | **hexadecimal(str)** | check if the value a hexadecimal number. | | **hexColor(str)** | check if the value a hexadecimal color. | | **hsl(str)** | check if the value an HSL (hue, saturation, lightness, optional alpha) color based on [CSS Colors Level 4 specification][CSS Colors Level 4 Specification].<br/><br/>Comma-separated format supported. Space-separated format supported with the exception of a few edge cases (ex: hsl(200grad+.1%62%/1)). | | **IBAN(str, [, options])** | check if the value an IBAN (International Bank Account Number).<br/><br/>options an object which accepts two attributes:whitelt: where you can restrict IBAN codes you want to receive data from and blacklt: where you can remove some of the countries from the current lt. For both you can use an array with the following values ['AD','AE','AL','AT','AZ','BA','BE','BG','BH','BR','BY','CH','CR','CY','CZ','DE','DK','DO','EE','EG','ES','FI','FO','FR','GB','GE','GI','GL','GR','GT','HR','HU','IE','IL','IQ','IR','','IT','JO','KW','KZ','LB','LC','LI','LT','LU','LV','MC','MD','ME','MK','MR','MT','MU','MZ','NL','NO','PK','PL','PS','PT','QA','RO','RS','SA','SC','SE','SI','SK','SM','SV','TL','TN','TR','UA','VA','VG','XK']`.