MCPcopy
hub / github.com/webpack/webpack / avoidNumber

Function avoidNumber

lib/ids/IdHelpers.js:40–55  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

38 * @returns {string} string prefixed by an underscore if it is a number
39 */
40const 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.

Callers 1

getShortModuleNameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected