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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fieldsafe

v1.0.8

Published

Security and reliability of the data in your form

Readme

FieldSafe

🔒 Security and reliability of the data in your form.

  • A general-purpose library when it comes to data validation.
  • This package allows you to easily validate a wide range of existing data formats.

Install

NPM

$ npm install fieldsafe
import { email } from "fieldsafe";

const isEmail = email("[email protected]");
console.log(isEmail); // true

or:

CDN

<script src="https://unpkg.com/[email protected]/index.js"></script>
<script type="module">
const { email } = FieldSafe;

const isEmail = email("[email protected]");
console.log(isEmail); // true
</script>

When attempting to validate data using the API's internal methods, it's important to keep in mind that not all functions are located within the validation classes, such as email. The function for validating the email format is not located in any validation class, only in a utilities file.

Validation

  • Credit card
  • Identification number
  • Password
  • Phone
  • Postal code
  • Email

💳 Credit card

Support is provided for validating different types of credit cards, they are all included in the CreditCardValidation class.

import { CreditCardValidation } from "fieldsafe";

const isValid = CreditCardValidation.mastercard("5432123456789012");
console.log(isValid); // true

Available methods:

  • CreditCardValidation.mastercard
  • CreditCardValidation.visa
  • CreditCardValidation.american_express
  • CreditCardValidation.elo
  • CreditCardValidation.hiper_card

📱 Phone

Mobile phone number validation is defined in the PhoneNumberValidation class and uses each country's name to verify the format.

import { PhoneNumberValidation } from "fieldsafe";

const isBrazilianPhone = PhoneNumberValidation.brazil("+55 (12) 91234-5678");
console.log(isBrazilianPhone); // true

Available methods:

  • PhoneNumberValidation.brazil
  • PhoneNumberValidation.usa

🪪 Identification number

The identification number can be selected by the IdentificationNumberValidation class, with the method names being the data types to be validated.

import { IdentificationNumberValidation } from "fieldsafe";

const isValid = IdentificationNumberValidation.cpf("213.232.345-10");
console.log(isValid); // true

Available methods:

  • IdentificationNumberValidation.cpf
  • IdentificationNumberValidation.cnpj

📫 Postal code

The postal code is found in the PostalCodeValidation class and may contain validation options for various countries.

import { PostalCodeValidation } from "fieldsafe";

const isZipcode = PostalCodeValidation.zipcode("90210");
console.log(isZipcode); // true

Available methods:

  • PostalCodeValidation.cep
  • PostalCodeValidation.zipcode
  • PostalCodeValidation.postal_code_canada

🔑 Password

The password will be validated according to the PasswordValidation class. This contains useful methods for password manipulation.

import { PasswordValidation } from "fieldsafe";

const validator = new PasswordValidation("Mystrongpass21@&");
validator
  .min(8, "Password must contain at least 8 characters")
  .mustContainDigits(1, "Password must contain at least 1 number")
  .mustContainSpecialChars(1, "Password must contain at least 1 special character")
  .mustContainUppercase(1, "Password must contain at least 1 uppercase");

console.log(validator.check()); // true

Available methods:

  • addPassword()
    • It insert the password content
    • This method can receive the clean password: addPassword("mypass")
  • min()
    • Minimum number of characters required
    • It receives the minimum quantity and an error message as parameters.
  • max()
    • Maximum number of characters required
    • It receives the maximum quantity and an error message as parameters.
  • mustContainDigits()
    • It defines that password must contain at least one digit
    • It receives the digit quantity and an error message as parameters.
  • mustContainSpecialChars()
    • It requires at least one special character on password.
    • It receives the quantity and an error message as parameters.
  • mustContainUppercase()
    • It requires at least one uppercase character on password.
    • It receives the uppercase quantity and an error message as parameters.
  • mustContainLowercase()
    • Requires at least one lowercase character on password.
    • It receives the lowercase quantity and an error message as parameters.
  • check()
    • Check if the password is valid.

🎭 Masks

You can customize the fields with masks and make the user experience more intuitive.

fs-mask property allow adjust the right value format inside input. Each "#" represents a number.

<input type="text" name="cpf" placeholder="cpf" id="cpf" fs-mask="###.###.###-##" />

You can use the Mask class to initialize the input auto-formatting.

import { Mask } from "fieldsafe";

new Mask(
  document.getElementById("cpf")
);