(str)
| 38 | * @returns {string} string prefixed by an underscore if it is a number |
| 39 | */ |
| 40 | const avoidNumber = (str) => { |
| 41 | // max length of a number is 21 chars, bigger numbers a written as "...e+xx" |
| 42 | if (str.length > 21) return str; |
| 43 | const firstChar = str.charCodeAt(0); |
| 44 | // skip everything that doesn't look like a number |
| 45 | // charCodes: "-": 45, "1": 49, "9": 57 |
| 46 | if (firstChar < 49) { |
| 47 | if (firstChar !== 45) return str; |
| 48 | } else if (firstChar > 57) { |
| 49 | return str; |
| 50 | } |
| 51 | if (str === String(Number(str))) { |
| 52 | return `_${str}`; |
| 53 | } |
| 54 | return str; |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * Returns id representation. |
no outgoing calls
no test coverage detected