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

@gurpratapsmagh/safe-pass

v0.1.2

Published

Password validation + strict allow-list input filter and safe text helpers.

Readme


safe-pass

A zero-dependency TypeScript/JavaScript library for password strength validation and safe input handling.


Features

  • Password validation with entropy estimation and weak-pattern detection.
  • Strict input filtering with configurable allow-lists.
  • Safe rendering helpers for untrusted data.
  • Server-side validation utilities.

Installation

npm install @gurpratap/safe-pass

Usage

Password Validation (frontend or API server)

import { validatePassword } from "safe-pass";

const res = validatePassword("P@ssw0rd1234");
console.log(res);

/*
{
  ok: false,
  score: 1,
  entropyBits: 78,
  issues: ["common_password", "sequential_chars"],
  suggestions: ["Avoid common passwords...", "Avoid sequences like..."]
}
*/

Inputs: string password Outputs: { ok, score, entropyBits, issues[], suggestions[] }

Input Filtering (frontend form fields)

import { createSafeXssInput } from "safe-pass";

// only a–z0–9, space, _, -
const { filter, bind } = createSafeXssInput("abcdefghijklmnopqrstuvwxyz0123456789 _-", {
  toLower: true, maxLength: 24
});

console.log(filter("Hello<script>WORLD!!"));
// { value: "hello world", rejected: ["<","s","c",...,"!"], isClean: false }

const input = document.querySelector("#username");
bind(input); // dynamically enforces allowed chars

Inputs: raw string or DOM input Outputs: cleaned value, rejected characters, boolean isClean

Safe Rendering (frontend)

import { setText, escapeHTML, setSafeAttr } from "safe-pass";

setText(document.getElementById("out"), "<b>Not bold</b>"); 
// rendered literally as text

console.log(escapeHTML("<img>")); 
// "&lt;img&gt;"

const link = document.createElement("a");
setSafeAttr(link, "href", "http://example.com"); 
// valid href, unsafe protocols are blocked

Server-Side Validation (API)

import { validateAllowedServer } from "safe-pass";

// validate username server-side
const username = validateAllowedServer("hello123", "abcdefghijklmnopqrstuvwxyz0123456789", 3, 24);

if (!username) {
  // reject request
} else {
  // safe normalized value
}

Inputs: raw string, allowed characters, min and max length Outputs: normalized string or null


API

  • validatePassword(password, opts?) → object with ok, score, entropyBits, issues[], suggestions[]
  • createSafeXssInput(allowed, opts?){ filter(raw), bind(element) }
  • setText(el, value) → safely sets text content
  • escapeHTML(str) → returns HTML-escaped string
  • setSafeAttr(el, name, value) → sets attributes safely, blocks dangerous protocols
  • validateAllowedServer(raw, allowed, min, max) → returns normalized value or null

Notes

  • Client-side filtering is for UX only; always validate on the server.
  • Use safe rendering (textContent, setText) to avoid Cross-Site Scripting (XSS).
  • Pair with a Content-Security-Policy (CSP) for stronger protection.