JSPM

  • Created
  • Published
  • Downloads 5634
  • Score
    100M100P100Q129595F
  • License MIT

Parses a string argument and returns an integer of the specified radix.

Package Exports

  • parse-int-x

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-int-x) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Travis status Dependency status devDependency status npm version

parse-int-x

Parses a string argument and returns an integer of the specified radix.

Version: 1.1.0
Author: Xotic750 Xotic750@gmail.com
License: MIT
Copyright: Xotic750

module.exportsnumber

This method parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems).

Kind: Exported member
Returns: number - An integer number parsed from the given string. If the first character cannot be converted to a number, NaN is returned.
Throws:

  • TypeError If target is a Symbol or is not coercible.
Param Type Description
string string The value to parse. If the string argument is not a string, then it is converted to a string (using the ToString abstract operation). Leading whitespace in the string argument is ignored.
radix number An integer between 2 and 36 that represents the radix (the base in mathematical numeral systems) of the above mentioned string. Specify 10 for the decimal numeral system commonly used by humans. Always specify this parameter to eliminate reader confusion and to guarantee predictable behavior. Different implementations produce different results when a radix is not specified, usually defaulting the value to 10.

Example

var $parseInt = require('parse-int-x');

// The following examples all return 15
$parseInt(' 0xF', 16);
$parseInt(' F', 16);
$parseInt('17', 8);
$parseInt(021, 8);
$parseInt('015', 10);   // $parseInt(015, 10); will return 15
$parseInt(15.99, 10);
$parseInt('15,123', 10);
$parseInt('FXX123', 16);
$parseInt('1111', 2);
$parseInt('15 * 3', 10);
$parseInt('15e2', 10);
$parseInt('15px', 10);
$parseInt('12', 13);

//The following examples all return NaN:
$parseInt('Hello', 8); // Not a number at all
$parseInt('546', 2);   // Digits are not valid for binary representations