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

@eli.richardson/pass-js

v1.0.3

Published

A simple password generator.

Downloads

5

Readme

Pass-JS

A complete Node.js password generator.

Installation

npm i @eli.richardson/pass-js

Usage

Word generator mode:


Note: await or .then is only needed for loading the dictionary for word generator mode


With await

import PassJS from "@eli.richardson/pass-js";

const password = new PassJS();

await password.init();
console.log(password.make(options));

With .then

import PassJS from "@eli.richardson/pass-js";

const password = new PassJS();

password.init().then(() =>
    console.log(password.make(options))
    );

"Traditional" mode:

import PassJS from "@eli.richardson/pass-js";

const options = {traditional: true};
const password = new PassJS();

console.log(password.make(options));

Examples:

Word generator:

import PassJS from "@eli.richardson/pass-js";
const password = new PassJS();
await password.init();
console.log(password.make({
    words: 3,
    separator: "-",
    amount: 2
}));

Output:

[ 'jesuits-chest-hope', 'split-earring-bury' ]

Traditional:

import PassJS from "@eli.richardson/pass-js";
const password = new PassJS();
console.log(password.make({
    traditional: true,
    min: 8,
    lower: true,
    upper: true,
    number: true,
    symbol: true,
    amount: 2
}));

Output:

[ 'J*SH7ObM', 'eb%fhbl1' ]

Using a custom dictionary

PassJS comes preinstalled with a GZIP'd dictionary of popular.txt (words < 4 characters are removed).

PassJS can load a custom dictionary file, with each word separated by a newline \n

The dictionary file must be either plaintext or GZIP. I recommend GZIPing any large dictionaries to save space.

Creating a GZIP:

import { createGzip } from "zlib";
import fs from "fs";

const gzip = createGzip();
/*
uppers.txt.gz:
A
B
C
D
.
.
.
Z
*/

const read = fs.createReadStream("./uppers.txt");
const write = fs.createWriteStream("./uppers.txt.gz");

read.pipe(gzip).pipe(write);
// Creates "./uppers.txt.gz"
import PassJS from "@eli.richardson/pass-js";

const password = new PassJS();
await password.init("./uppers.txt");
// OR: "./uppers.txt.gz"
console.log(password.make({
    words: 4,
    amount: 2,
    separator: "-"
}));

Example output:

[ 'O_H_E_V', 'L_Z_P_Q' ]

PassJS Validator

PassJS comes with a password validator.

Usage

import PassJS from "@eli.richardson/pass-js";

const password = new PassJS();
const options = {
    number: true,
    lower: true,
    min: 4
}
password.validate("h3llo-world-maker", options);
// true
password.validate("hello-word-maker", options);
// false

Options

.make(<options>)

traditional - default: false

/*
Enables traditional mode.
Generates a password of specified min value.

Note: you can also set the words property to 0 for traditional mode.
*/
password.make({
    traditional: true
});
// Example value: "lnzdi9fp"

min - default: 8

/*
Resulting password length.

Note: only applied in traditional mode.
*/
password.make({
    traditional: true, 
    lower: true
    min: 30
});
// Example value: "aoajuovysrtxhuubdfsuvqxciwzymp"

words - default: 4

/*
Specifies the number of words in resulting password.

Note: you can also set the words property to 0 for traditional mode.
*/
password.make({
    words: 2
});
// Example value: "himself_depending"

separator - default: _

/*
Set the separator for word mode.
Ex: If value is set to `!` result would be `<word>!<word>`

Note: ignored in traditional mode.
*/
password.make({
    separator: "!"
});
// Example value: "single!crashed!seats!unhand"

lower - default: false

/*
Allows lowercase characters.

Note: ignored in word mode.
*/
password.make({
    lower: false,
    upper: true
});
// Example value: "TGJLFRSZ"

upper - default: false

/*
Allows uppercase characters.

Note: in word mode, this will capitalize the first letter of the first word.
*/
password.make({
    traditional: true,
    upper: true,
    number: true
});
// Example value: "Q0VOBLIY"
password.make({
    words: 3,
    upper: true
});
// Example value: "Breakwater_canary_racial"

number - default: false

/*
Inserts a number into a random position in the password.

Note: in word mode, this appends a number to the end of the last word.
*/
password.make({
    traditional: true,
    lower: true,
    number: true
});
// Example value: "4aihgnyl"
password.make({
    words: 2,
    number: true
});
// Example value: "buster_snacks5"

symbol - default: false

/*
Inserts a symbol into a random position in the password.

Note: in word mode, this appends a symbol to the end of the last word.
*/
password.make({
    traditional: true,
    lower: true,
    symbol: true
});
// Example value: "fpbcc^fj"
password.make({
    words: 2,
    symbol: true
});
// Example value: "accusation_infantile&"

space - default: false

/*
Inserts a space into a random position in the password.

Note: in word mode, this adds a space to a random word.
*/
password.make({
    words: 0,
    lower: true,
    space: true
});
// Example value: "ctxow ng"
password.make({
    words: 3,
    space: true
});
// Example value: "counselors_headlines_vit al"

amount - default: 1

/*
The amount of passwords to output.
*/
password.make({
    words: 2,
    amount: 2
});
// Example value: [ 'railroad_unintelligible', 'embarrass_claimed' ]
password.make({
    words: 0,
    amount: 2,
    lower: true
});
// Example value: [ 'cuzwxpin', 'lcxalhsa' ]

Validation Options


The validator has the following boolean options:

  • symbol - default: false
  • upper - default: false
  • lower - default: false
  • number - default: false
  • space - default: false

If enabled, it will return true if it is found at least once within the password.

The validator has the following numerical options:

  • max - default: Infinity
  • min - default: 0

If specified, the validator will return true if it is within the boundries.