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

word-to-number-node

v1.0.3

Published

Convert word-phrases to a string of digits

Downloads

17

Readme

WordToNumber (node) Build Status

Convert any phrase word-numbers to all their digits

WordToNumber lets you parse any string for all of its word-numbers into an array of their digit representations. Covers all possibilities up to millinillion

"five" => [ "5" ]
"Four score and seven years ago..." => [ "4", "7" ]

Table of contents

Installation

WordToNumber in on npm, so its as simple as npm install word-to-number-node

Usage

The main function you'll be using with WordToNumber is the parse function.
It takes a string, and will return an array of all the numbers it finds in their digit form, as a string

var WordToNumber = require( "word-to-number-node" );
var w2n = new WordToNumber();

w2n.parse( "fifteen" ); // [ "15" ]
w2n.parse( "sixty-nine thousand and three" ); // [ "69003" ]
w2n.parse( "One Fish, Two Fish, Red Fish, Blue Fish " ); // [ "1", "2" ]

Languages

WordToNumber comes with US English by default, with several convenience functions to manipulate that data.

listLanguages()
//  return an array of the available languages
  
setLanguage ( (string) language )
//  set the current language

getLanguageData( (string) language )
//  return the data for the specified/current language

updateLanguageData( (string) language, (object) data )
//  replace the specified language data with your own

Note: While it may possible to drop in new languages and have them work (Like UK English for example),
the algorithm is tuned for US English, and as such other languages would have to follow the same pattern to work correctly

Validation

WordToNumber allows you to set custom white/blacklists to validate against

setValidatorWhitelist( (array/string) regex )
//		Takes a single, or array of regexes to test numbers against before parsing.
//		Only matching values will be included.
//		Blacklist takes precedence over Whitelist
//		Passing a falsey value will clear this list.

setValidatorBlacklist( (array/string) regex )
//		Takes a single, or array of regexes to test numbers against before parsing.
//		Matching values will be excluded.
//		Blacklist takes precedence over Whitelist
//		Passing a falsey value will clear this list.

setSideChars( (string) regex )
//		takes a regex of allowed characters surrounding the word-number
//		this MUST include *at least* /a-z/i, so that you aren't matching words
//		like "attend", or "tone", that would otherwise match as 10, and 1

Scientific Notation

Optionally output scientific notation at the specified exponent level

setExponent ( number )
//		takes a number that signifies the exponent at which scientific notation starts