Code Monkey home page Code Monkey logo

npm-string-to-number's Introduction

string-to-number

This is an npm module for converting string representations of numbers to numbers.

Examples

var string_to_number = require('string-to-number');
var s2n = new string_to_number();

// Simple example
s2n.convert('seven hundred');
// Output: 700

// Works with negatives
s2n.convert('negative six hundred eighty three');
// Output: -683

// Works with dashes
s2n.convert('three-hundred-thousand');
// Output: 300000

// Works with ands
s2n.convert('three-hundred thousand and forty two');
// Output: 300042

// A bigger number
s2n.convert('seven hundred and ninety nine billion five hundred thirty two million six hundred thousand and seven');
// Output: 799532600007

// Invlaid numbers return undefined
s2n.convert('ten gazillion');
// Output: undefined

// Only supports whole numbers
s2n.convert('ten point two');
// Output: undefined

// Also invalid
s2n.convert('half a million');
// Output: undefined

Download

Install using Node Package Manager (npm):

npm install string-to-number

npm-string-to-number's People

Contributors

tylerpachal avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

jjesusfilho

npm-string-to-number's Issues

Unable to process integers

I'm currently using string-to-number in a BDD project to manage numbers spelt out in Gherkin, such as Given I attempt to log in with invalid credentials three times and Given I attempt to log in with invalid credentials 3 times.

On the second example the convert() function will return undefined instead of the integer 3.

The reason I'm using the string-to-number library is to manage scenarios that will use a mixture of digit and string representations of numbers coming from non-technical people.

Is it possible to try and use parseInt() or parseFloat() before to manage this use case?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.