Skip to content

vcostin/npm-number-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm-number-parser

Module that parse all types of number from a string, returns an array of numbers. Inspired from this post

Build Status

Installation

$ npm install --save npm-number-parser

Usage

var parseNumbers = require('npm-number-parser');

var numbers = parseNumbers('12 32 3.5 test test2');
console.log(numbers);
//=> [12, 32, 3.5, 2]

numbers = parseNumbers('a string without numbers');
console.log(numbers);
//=> []

//trows error if input it's not a string, see tests
numbers = parseNumbers(null);
//=> TypeError: Input data is not a string

Usage with callback

var parseNumbers = require('npm-number-parser');

parseNumbers('12 32 3.5 test test2', function(error, output){
    console.log(error);
    //=> null
    
    console.log(output);
    //=> [12, 32, 3.5, 2]
});

parseNumbers('a string without numbers', function(error, output){
    console.log(error);
    //=> null

    console.log(output);
    //=> []
});

//other type of data that is not a string  
parseNumbers(null, function(error, output){
    console.log(error);
    //=> TypeError: Input data is not a string

    //with callback the output is null
    console.log(output);
    //=> null
});

About

Module that parse all types of number from a string

Resources

License

Stars

Watchers

Forks

Packages

No packages published