parse-int-x
Version:
Parses a string argument and returns an integer of the specified radix.
1 lines • 2.6 kB
Source Map (JSON)
{"version":3,"sources":["../src/parse-int-x.js"],"names":[],"mappings":"AAAA,OAAO,GAAP,MAAgB,OAAhB;AACA,OAAO,KAAP,MAAkB,aAAlB;AACA,OAAO,QAAP,MAAqB,aAArB;AACA,OAAO,SAAP,MAAsB,oBAAtB;AAEA,IAAM,cAAc,GAAG,QAAvB;AACA;;AACA,IAAM,UAAU,GAAI,CAAD,EAAI,WAAvB;AACA,IAAM,QAAQ,GAAG,QAAjB;AACA,IAAM,gBAAgB,GAAG,SAAS,CAAC,QAAQ,CAAC,MAAV,CAAlC;AACA,IAAM,QAAQ,GAAG,aAAjB;AACA,IAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,CAAC,IAAV,CAAhC;AAEA;;;;;;;;;;;;;;;;;;AAiBA,IAAM,SAAS,GAAG,SAAS,SAAT,CAAmB,MAAnB,EAA2B,KAA3B,EAAkC;AAClD,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAD,CAAN,CAApB;;AAEA,MAAI,gBAAgB,CAAC,GAAD,EAAM,CAAN,CAAhB,KAA6B,QAAjC,EAA2C;AACzC,WAAO,GAAP;AACD;;AAED,SAAO,cAAc,CAAC,GAAD,EAAM,UAAU,CAAC,KAAD,CAAV,KAAsB,cAAc,CAAC,QAAD,EAAW,GAAX,CAAd,GAAgC,EAAhC,GAAqC,EAA3D,CAAN,CAArB;AACD,CARD;;AAUA,eAAe,SAAf","file":"parse-int-x.esm.js","sourcesContent":["import NAN from 'nan-x';\nimport toStr from 'to-string-x';\nimport trimLeft from 'trim-left-x';\nimport methodize from 'simple-methodize-x';\n\nconst nativeParseInt = parseInt;\n/** @type {Function} */\nconst castNumber = (0).constructor;\nconst BAD_CHAR = '\\u180E';\nconst methodizedCharAt = methodize(BAD_CHAR.charAt);\nconst hexRegex = /^[-+]?0[xX]/;\nconst methodizedTest = methodize(hexRegex.test);\n\n/**\n * This method parses a string argument and returns an integer of the specified\n * radix (the base in mathematical numeral systems). (ES2019).\n *\n * @param {string} [string] - The value to parse. If the string argument is not a\n * string, then it is converted to a string (using the ToString abstract\n * operation). Leading whitespace in the string argument is ignored.\n * @param {number} [radix] - An integer between 2 and 36 that represents the radix\n * (the base in mathematical numeral systems) of the above mentioned string.\n * Specify 10 for the decimal numeral system commonly used by humans. Always\n * specify this parameter to eliminate reader confusion and to guarantee\n * predictable behavior. Different implementations produce different results\n * when a radix is not specified, usually defaulting the value to 10.\n * @throws {TypeError} If target is a Symbol or is not coercible.\n * @returns {number} An integer number parsed from the given string. If the first\n * character cannot be converted to a number, NaN is returned.\n */\nconst $parseInt = function $parseInt(string, radix) {\n const str = trimLeft(toStr(string));\n\n if (methodizedCharAt(str, 0) === BAD_CHAR) {\n return NAN;\n }\n\n return nativeParseInt(str, castNumber(radix) || (methodizedTest(hexRegex, str) ? 16 : 10));\n};\n\nexport default $parseInt;\n"]}