1.0.2 • Published 8 years ago

npm-number-parser v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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
});
1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago