parse-numeric

node v10.24.1
version: master
endpointsharetweet
Convert numeric strings into Numbers (or return the original value when not-possible). GitHub 🌐 https://github.com/gregswindle/parse-numeric#readme NPM 🌐 https://www.npmjs.com/package/parse-numeric
const parseNumeric = require('parse-numeric')
🔢 Numeric strings
const stringifiedNumbers = [ '12.3', // Floating point '123', // Integer '0b11', // Binary '0o11', // Octal '0x11', // Hexidecimal '123e-1', // Exponentiation ]
Parse numeric strings
stringifiedNumbers.forEach((str) => { const number = parseNumeric(str) console.log(number) })
🔡 Non-numeric data-types
const nonNumericStrings = [ 'Rainbows', '', // Empty string null, undefined ]
Parse non-numeric strings
nonNumericStrings.forEach((nan) => { const untouchedNaN = parseNumeric(nan) console.log(untouchedNaN) })
Loading…

no comments

    sign in to comment