numstr

1.0.1 • Public • Published

numstr

Utility to identify english number words in text and to convert them to actual numbers.

This library is based on the Perl libraries Lingua-EN-FindNumber and Lingua-EN-Words2Nums.

Installation

npm install numstr

Usage

words2nums

Takes a number written in english and converts it to a number.

var words2nums = require('numstr').words2nums;
console.log(words2nums('one thousand nine hundred seventy six')); // 1976

extractNumbers

Identifies english numbers in a string and returns an array

var extractNumbers = require('numstr').extractNumbers;
console.log(extractNumbers('He ate five pies')); // [{text: 'five', index: 8}]

numify

Replaces english numbers with actual numbers in a string

var numify = require('numstr').numify;
console.log(numify('I ran twenty six miles')); // I ran 26 miles

Notes

Currently supports negative numbers and numbers up to decillions along with common phrases like 'score', 'gross', 'dozen', 'bakersdozen' and more.

Does not currently support fractions or decimals

Readme

Keywords

none

Package Sidebar

Install

npm i numstr

Weekly Downloads

3

Version

1.0.1

License

ISC

Last publish

Collaborators

  • acdaniel