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

text-cleaner

v1.2.1

Published

Easily clean text for analysis

Downloads

4,216

Readme

Text Cleaner

A small tool for easily cleaning text.

npm version Build Status

Installation

npm install text-cleaner --save

Example

const TextCleaner = require('text-cleaner');

TextCleaner('Some <b>  TEXT to Clean</b>').stripHtml().condense().toLowerCase().valueOf();
// some text to clean

Usage

Constructor: TextCleaner(string)

const cleanString = TextCleaner('string');

Returns an object, with the following methods:

#valueOf() and #toString()

Returns the current working value of the string being cleaned

TextCleaner('STRING').valueOf()
// "STRING"
TextCleaner('STRING').toString()
// "STRING"

#length

TextCleaner('string').length
// 6

#remove(search string)

TextCleaner('string').remove('tr').valueOf()
// "sing"

#replace(search string, replace string)

TextCleaner('string').replace('tr', 'l').valueOf()
// "sling"

#trim()

TextCleaner(' string ').trim().valueOf()
// "string"

#toLowerCase()

TextCleaner('STRING').toLowerCase().valueOf()
// "string"

#toUpperCase()

TextCleaner('string').toUpperCase().valueOf()
// "STRING"

#truncate(length)

TextCleaner('a long string').truncate(6).valueOf()
// "a long"

#condense()

Condenses all white space to a single space

TextCleaner('s  \t t 	\nr i n g').condense().valueOf()
// "s t r i n g"

#stripEmails()

TextCleaner('Email me at: [email protected]').stripEmails().valueOf()
// "Email me at: "

#stripHtml()

TextCleaner('<b>string<lb>').stripHtml().valueOf()
// "string"

#removeChars(options)

Remove all non-alpha characters, including numbers. Only letters, white space and characters specified in the exclude option will not be removed.

Options (object):

  • replaceWith (default: "") Character to replace matched characters with. Allows for characters to be replaced by a space, preventing words from merging on character removal.
  • exclude: (default: "") String of characters to exclude. These are added to a regular expression; e.g. "0-9" would exclude numbers from replacement
TextCleaner('~string1!').removeChars({ exclude: '!' }).valueOf()
// "string!"

#removeApostrophes()

Remove apostrophes from the text, but leave other single quotes in the text.

TextCleaner("a quote: 'he didn't'").removeApostrophes().valueOf()
// "a quote: 'he didnt'"

Allows words containing apostrophes to be treated separately to removeChars(), such as when replacing characters with a space with removeChars({ replaceWith: ' ' }), preserving the word.

/* undesired behaviour */
TextCleaner("don't(text)").removeChars({ replaceWith: ' ' }).trim().valueOf()
// "don t text"

/* desired behaviour */
TextCleaner("don't(text)").removeApostrophes().removeChars({ replaceWith: ' ' }).trim().valueOf()
// "dont text"

#removeStopWords()

Remove common stop words from the text for textual/sentiment anlysis. Uses stopword.

TextCleaner("the test string with some words").removeStopWords().valueOf()
// "test string words"