npm-number-parser

1.0.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i npm-number-parser

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • vcostin