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

string-sanitizer-fix

v2.0.1

Published

An intuitive & tiny string sanitizer to remove any special characters or convert strings to create filename or url πŸŽ‰πŸŽ‰

Downloads

5

Readme

String Sanitizer

I DO NOT OWN THIS, I AM FIXING A VERY ANNOYING BUG

An intuitive & tiny string sanitizer to remove any special characters or convert strings to create filename or url. Validate email, password & username too. πŸŽ‰πŸŽ‰

βœ… Update: 2.0.0 is launched with major updates. No breaking changes. Email, password and username validation is added. Everything is tested.

Use Case

Converting or sanitizing string is easier than ever with the help of this package. You can use this utility package to sanitize even foreign languages other than English. Under the hood, regex is heavily used in this library. You can convert your string to url or filename frindly string. Besides you can validate email, passwords and username too. πŸŽ‰πŸŽ‰

Installation

You can download this package from here - string-sanitizer npm

npm i string-sanitizer

Yarn installation

yarn add string-sanitizer

Usage πŸ‘€πŸ‘€πŸ‘€

Just pass your string as the argument. The method will return a sanitized or converted string instantly.

var string = require("string-sanitizer");
let someString = "@abcde$f$gh";
string.sanitize(someString); // abcdefgh

Sanitization use cases

var string = require("string-sanitizer");

string.sanitize("a.bc@d efg#h"); // abcdefgh
string.sanitize.keepSpace("a.bc@d efg#h"); // abcd efgh
string.sanitize.keepUnicode("a.bc@d efg#hক"); // abcd efghক
string.sanitize.addFullstop("a.bc@d efg#h"); // abcd.efgh
string.sanitize.addUnderscore("a.bc@d efg#h"); // abcd_efgh
string.sanitize.addDash("a.bc@d efg#h"); // abcd-efgh
string.sanitize.removeNumber("@abcd efgh123"); // abcdefgh
string.sanitize.keepNumber("@abcd efgh123"); // abcdefgh123
string.addFullstop("abcd efgh"); // abcd.efgh
string.addUnderscore("@abcd efgh"); // @abcd_efgh
string.addDash("@abcd efgh"); // @abcd-efgh
string.removeSpace("@abcd efgh"); // @abcdefgh
string.removeUnderscore("@ab__cd ef_gh_"); // @abcd efgh

βœ… Screenshot

string-sanitizer

Validation πŸ‘€πŸ‘€πŸ‘€

Added in version 2.0.0

Most of the time we have to validate email, password and username in our codebase. So string sanitizer starts offering validation along with sanitization. You pass your user generated email, username or password in this method. If it passes the filter, it will return the string as it is. If it doesn't pass the filter, it will return false.

Email Validation βœ…

var string = require("string-sanitizer");

string.validate.isEmail("[email protected]"); //  [email protected]
string.validate.isEmail("jhongmail.com"); // false
string.validate.isEmail("jhon@gmailcom"); // false
string.validate.isEmail("jhon@@gmail.com"); // false

Username Validation βœ…

Username must be free from any special characters. There will be no space and must be at least 2 characters long. Combination of numbers and letters is acceptable. Only numbers (i.e 123) are not acceptable. But only letters (i.e ea) wil be acceptable.

var string = require("string-sanitizer");

string.validate.isUsername("fazlulka"); // fazlulka
string.validate.isUsername("Fazlulka"); //  fazlulka (Automatically lowerstring method applied.)
string.validate.isUsername("f"); //  false (Minimum 2 letters)
string.validate.isUsername("123"); //  false (Only number is not acceptable)
string.validate.isUsername("fazlulka@"); //  false (Special Character not accpeted)
string.validate.isUsername("fazlulka_"); // false (Special Character not accepted)

Why minimum 2 letters not 3 letters? Because some of the username like (@ea) is still most popular.

Why automatically lowerstring applied? Because, most of the end user still don't understand the meaning of username. Sometimes they use upper letter. We just sanitized it. Nothing more.

Password Validation βœ…

1. Most popular: To check a password between 6 to 15 characters which contain at least one numeric digit and a special character

string.validate.isPassword6to15("password1@"); //  password1@
string.validate.isPassword6to15("password1"); //  false

2. Most Secure: To check a password between 8 to 15 characters which contain at least one lowercase letter, one uppercase letter, one numeric digit, and one special character

string.validate.isPassword8to15("password1Aa_"); //  password1Aa_
string.validate.isPassword8to15("password1"); // false

3. Simpler Password: To check a password between 6 to 20 characters which contain at least one numeric digit, one uppercase and one lowercase letter

string.validate.isPassword6to20("password1Aa"); //  password1Aa
string.validate.isPassword6to20("password1"); // false

4. Easy Password: To check a password between 7 to 20 characters which contain only characters, numeric digits, underscore and first character must be a letter. No special character accepted here.

string.validate.isPassword7to20("password1"); //  password1
string.validate.isPassword7to20("password1@_"); //  false (No special character allowed)

Typescript compatitibility

Thanks to @kewitz for typescript compatibility

Thanks to @JohannesDev for removeUnderscore function

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate. πŸƒβ€πŸƒβ€

License

MIT