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

kleen-js

v1.0.9

Published

Readable String Sanitizer

Downloads

184

Readme

Kleen JS

Readable String Sanitizer

Installation

npm install kleen-js
// or
yarn add kleen-js

Usage

import kleen from 'kleen-js'

kleen.toSSN('123456789') // returns '123-45-6789'

Documentation

Functions are split into two types: core and utilities. Core functions transform strings in customizable ways. Utility functions are built with core functions and transform the strings in concrete ways.

Core Functions

Utility Functions

Core Functions

Remove By Regex

removeByRegex(String)

removes any of the found regex

kleen.removeByRegex('abc123', /\d/g) // returns 'abc'

Remove Non Digits

removeNonDigits(String)

remove all non-digit characters (anything except 0-9)

kleen.removeNonDigits('abc123') // returns '123'

Limit to Length

limitToLength(String, maxLength:Int)

limits the string to the given maxLength

kleen.limitToLength('abc123', 3) // returns 'abc'
kleen.limitToLength('ab', 3) // returns 'ab'

Add String at Position

addStringAtPosition(String, stringToAdd:String, position:Int)

adds the given string at the position

if the original string length is not as long as the position, does nothing

kleen.addStringAtPosition('123456789', '-', 5) // returns '12345-6789'
kleen.addStringAtPosition('12345', '-', 5) // returns '12345-'
kleen.addStringAtPosition('123', '-', 5) // returns '123'

Add String at Position If Length

addStringAtPositionIfLength(String, stringToAdd:String, position:Int, length:Int)

adds the given string at the position if the original string is of the given length

if the original string length is not as long as the given length, does nothing

if the original string length is not as long as the position, does nothing

kleen.addStringAtPositionIfLength('123456789', '-', 5) // returns '12345-6789'
kleen.addStringAtPositionIfLength('12345', '-', 5, 6) // returns '12345'
kleen.addStringAtPositionIfLength('123', '-', 5, 6) // returns '123'

Utility Functions

To Short US Postal Code

toShortUSPostalCode(String)

formats the string to as close to a 5 digit postal code as possible

kleen.toShortUSPostalCode('abc123') // returns '123'
kleen.toShortUSPostalCode('123456-789') // returns '12345'

To Long US Postal Code

toLongUSPostalCode(String)

formats the string to as close to a 5-4 digit postal code as possible

kleen.toLongUSPostalCode('abc12345678987') // returns '12345-6789'
kleen.toLongUSPostalCode('ab23') // returns '23'

To SSN

toSSN(String)

formats the string to a US SSN

kleen.toSSN('123456789') // returns '123-45-6789'
kleen.toSSN('a2b456') // returns '245-6'

To Phone

toPhone(String)

formats the string to a US Phone Number

kleen.toPhone('1234567890') // returns '(123) 456-7890'
kleen.toPhone('a2b456') // returns '(245) 6'

Development

PR's Welcome!

Please update code, tests, README, and bump the version number. I'll handle yarn build'ing and npm publish'ing after the PR is in.

yarn test --watch to run jest tests (and watch for future changes to those tests)