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

yup-password

v0.4.0

Published

Yup, dead simple password validation.

Downloads

92,174

Readme

Yup-Password

Yup, dead simple password validation.

Install

Using npm:

$ npm install yup-password

Using yarn:

$ yarn add yup-password

Usage

Plug and play:

// MJS / TS
import * as yup from 'yup'
import YupPassword from 'yup-password'
YupPassword(yup) // extend yup
// CJS
const yup = require('yup')
require('yup-password')(yup) // extend yup
// Build schema
const schema = yup.object().shape({
    username: yup.string().email().required(),
    password: yup.string().password().required(),
})

const input = {
    username: '[email protected]',
    password: 'secret',
}

try {
    // validate
    const res = await schema.validate(input, { abortEarly: false })
    //  ...
} catch (e) {
    console.log(e.errors) // => [
    //   'password must be at least 8 characters',
    //   'password must contain at least 1 uppercase letter',
    //   'password must contain at least 1 number',
    //   'password must contain at least 1 symbol',
    // ]
}

Override, disable or add additional rules:

const schema = yup.string().password()
    .minLowercase(8) // raise the lowercase requirement to 8
    .min(0) // disable minimum characters completely
    .minWords(2) // add an additional rule

try {
    const res = await schema.validate('secret', { abortEarly: false })
    //  ...
} catch(e) {
    console.log(e.errors) // => [
    //   'password must contain at least 2 words',              <-- added
    //   'password must contain at least 8 lowercase letters',  <-- overridden
    //   'password must contain at least 1 uppercase letter',
    //   'password must contain at least 1 number',
    //   'password must contain at least 1 symbol',
    // ]
}

Pick and choose your password rules:

const schema = yup.string().min(6).minUppercase(3).maxRepeating(2).minWords(2)

await schema.isValid('Now, THIS is some password.') // => true
await schema.isValid('But thiiis is not.') // => false

Localize your error messages:

yup.setLocale({
    string: {
        minLowercase: 'Localized message (path=${path};length=${length})',
        minUppercase: 'Localized message (path=${path};length=${length})',
        minNumbers: 'Localized message (path=${path};length=${length})',
        minSymbols: 'Localized message (path=${path};length=${length})',
        maxRepeating: 'Localized message (path=${path};length=${length})',
        minWords: 'Localized message (path=${path};length=${length})',
    }, // when using typescript, you may want to append `as any` to the end
       // of this object to avoid type errors.
})

API

.password()

Password must meet the default requirements: at least 8 characters, at most 250 characters, at least 1 lowercase letter, at least 1 uppercase letter, at least 1 number and at least 1 symbol.

const schema = yup.string().password()

.minLowercase(length?: number = 1, message?: string)

Password must contain X amount of lowercase letters or more.

const schema = yup.string().minLowercase(3, 'custom message')

.minUppercase(length?: number = 1, message?: string)

Password must contain X amount of uppercase letters or more.

const schema = yup.string().minUppercase(3, 'custom message')

.minNumbers(length?: number = 1, message?: string)

Password must contain X amount of numbers or more.

const schema = yup.string().minNumbers(3, 'custom message')

.minSymbols(length?: number = 1, message?: string)

Password must contain X amount of symbols or more.

const schema = yup.string().minSymbols(3, 'custom message')

.maxRepeating(length?: number = 2, message?: string)

Password must not contain a sequence of X amount of repeated characters. For example, if the limit is 2 thiis will pass but thiiis will not.

const schema = yup.string().maxRepeating(3, 'custom message')

.minWords(length?: number = 2, message?: string)

Password must contain X amount of words or more. So long as a sequence of characters contains letters or numbers, it will be recognized as a word. For example secret, 1st! and 1337 count as words, but !@#$% does not.

const schema = yup.string().minWords(3, 'custom message')

License

This project is open-sourced software licensed under the MIT license.