parse-int-x
Parses a string argument and returns an integer of the specified radix.
Last updated 5 years ago by xotic750 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install parse-int-x 
SYNC missed versions from official npm registry.

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

parse-int-x

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

module.exports(string, number)number

parse-int-xnumber

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

Kind: static property of parse-int-x
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

import $parseInt from 'parse-int-x';

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

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

Current Tags

  • 3.2.2                                ...           latest (5 years ago)

33 Versions

  • 3.2.2                                ...           5 years ago
  • 3.2.1                                ...           5 years ago
  • 3.2.0                                ...           5 years ago
  • 3.1.0                                ...           5 years ago
  • 3.0.26                                ...           5 years ago
  • 3.0.25                                ...           5 years ago
  • 3.0.24                                ...           5 years ago
  • 3.0.23                                ...           5 years ago
  • 3.0.22                                ...           5 years ago
  • 3.0.21                                ...           5 years ago
  • 3.0.20                                ...           5 years ago
  • 3.0.19                                ...           5 years ago
  • 3.0.18                                ...           5 years ago
  • 3.0.17                                ...           5 years ago
  • 3.0.15                                ...           5 years ago
  • 3.0.14                                ...           5 years ago
  • 3.0.13                                ...           5 years ago
  • 3.0.12                                ...           5 years ago
  • 3.0.11                                ...           5 years ago
  • 3.0.10                                ...           5 years ago
  • 3.0.9                                ...           5 years ago
  • 3.0.8                                ...           5 years ago
  • 3.0.7                                ...           5 years ago
  • 3.0.6                                ...           5 years ago
  • 3.0.5                                ...           5 years ago
  • 3.0.4                                ...           5 years ago
  • 3.0.3                                ...           5 years ago
  • 3.0.2                                ...           5 years ago
  • 3.0.1                                ...           5 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.0                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Total 1
Today 1
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (67)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE