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

suf-password

v0.7.0

Published

Password Check utility.

Downloads

16

Readme

Password Utility Functions

Custom codecov circleci npmV min install githubLastCommit

Usage

const checks: Password.ValidateCheck[] = [
  {
    type: 'customRegex',
    customRegex: /123/g,
    invertCheck: true,
    customError: 'cannot contain 123'
  },
  { type: 'uppercase' },
  { type: 'numbers' },
  {
    type: 'custom',
    custom: password => password !== '123456',
    customError: 'password cannot be 123456'
  }
];
Password.Validate('123456', checks); // doesn't pass
Password.Validate('Abcd', checks); // doesn't pass
Password.Validate('Abcd321', checks); // passes

const password = 'theBestPassword123$';
Password.ValidateSimple(password); // should meet all the requirements and return true.

Docs

index

Password
namespace Password {
  /** Defines the properties of a Password.Validate Check  */
  interface PasswordCheck {
    /** Type of the check  */
    type:
      | 'custom'
      | 'numbers'
      | 'letters'
      | 'lowercase'
      | 'uppercase'
      | 'spaces'
      | 'symbols'
      | 'customRegex';
    /**
     * if the type is one of  **`'numbers' | 'letters' | 'lowercase' | 'uppercase' | 'spaces' | 'symbols'`** then this
     * property defines the times that the type can occur without failing the check, if invertCheck is true then
     * this property defines how many time this type is allowed.
     */
    times?: number;
    /**
     * if true then the result of **`'numbers' | 'letters' | 'lowercase' | 'uppercase' | 'spaces' | 'symbols' | 'customRegex'`**
     * will be inverted, example if the type is  **`customRegex`** and customRegex =  **`/123/g`** then the password cannot contain  **`123`**.
     */
    invertCheck?: boolean;
    /** if the type is **`custom`** then this function will be executed.  */
    custom?: (password: string) => boolean;
    /** if the type is **`customRegex`** then this regex will be tested.  */
    customRegex?: RegExp;
    /** if the type is **`custom | customRegex`** then this will be the error the if the check fail's.   */
    customError?: string;
  }
  /** Options for the Password.Validate function. */
  interface ValidateOptions {
    /** the maximum length of the password. */
    maxLength?: number;
    /** the minimum length of the password. */
    minLength?: number;
    /** if true additional data will be returned. */
    passData?: boolean;
  }
  interface ValidateReturn {
    /** array that contains the error messages of all the failed checks. */
    errors: string[];
    /** true if all the checks have passed successfully. */
    passed: boolean;
    /** array with the additional data about each test. */
    validationData?: {
      invertCheck: boolean;
      errType: string;
    }[];
  }
  /**
   * Validates a password or other strings with checks that have to be provided in the checks array,
   * if the **`passed`** key of the returned object is true
   * then all checks have been passed successfully.
   *
   * @param password password or other string to be checked.
   * @param checks array of checks that will be performed.
   * @param options min and max length and other stuff.
   */
  function Validate(
    password: string,
    checks: PasswordCheck[],
    options?: ValidateOptions
  ): ValidateReturn;
  /**
   * The password has to contain an uppercase letter, number and cannot contain any spaces.
   * @param password password or string to check.
   */
  function ValidateSimple(password: string): boolean;
}

Generated with suf-cli

Copyright (c) 2020 Leonard Grosoli Licensed under the MIT license.