10 examples of 'which function is used to parse a string to int?' in JavaScript

Every line of 'which function is used to parse a string to int?' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
58function int(str) {
59 if (!str) {
60 return 0;
61 }
62 return parseInt(str, 10);
63}
8function int(str) {
9 return parseInt(str, 10);
10}
70function int(s) {
71 return parseInt(s);
72}
480function stringToInteger(string) {
481 var total = 0;
482 for(var i = 0; i !== string.length; i++){
483 if(total >= Number.MAX_SAFE_INTEGER){
484 break;
485 }
486 total += string.charCodeAt(i);
487 }
488 return total;
489}
4function int(str) {
5 return parseInt(str, 10);
6}
1458function parseInteger(str) {
1459 var x = parseInt(str, 10);
1460 return {
1461 value: x,
1462 msg: isNaN(x) ? ("Integer expected: " + str) : null,
1463 };
1464}
8function notParseableAsInt(str) {
9 return parseInt(str).toString() !== str;
10}
1function int (value) {
2 return parseInt(value, 10)
3}
112function int(val) {
113 return parseInt(val, 10);
114}
44export function parse_int(inputString: string, radix: number) {
45 const parsed = parseInt(inputString, radix)
46 if (inputString && radix && parsed) {
47 // the two arguments are provided, and parsed is not NaN
48 return parsed
49 } else {
50 throw new Error('parseInt expects two arguments a string s, and a positive integer i')
51 }
52}

Related snippets