MCPcopy
hub / github.com/webpack/webpack / getName

Function getName

lib/util/deterministicGrouping.js:51–73  ·  view source on GitHub ↗
(a, b, usedNames)

Source from the content-addressed store, hash-verified

49 * @returns {string} the common part and a single char for the difference
50 */
51const getName = (a, b, usedNames) => {
52 const l = Math.min(a.length, b.length);
53 let i = 0;
54 while (i < l) {
55 if (a.charCodeAt(i) !== b.charCodeAt(i)) {
56 i++;
57 break;
58 }
59 i++;
60 }
61 while (i < l) {
62 const name = a.slice(0, i);
63 const lowerName = name.toLowerCase();
64 if (!usedNames.has(lowerName)) {
65 usedNames.add(lowerName);
66 return name;
67 }
68 i++;
69 }
70 // names always contain a hash, so this is always unique
71 // we don't need to check usedNames nor add it
72 return a;
73};
74
75/** @typedef {Record<string, number>} Sizes */
76

Callers 3

applyMethod · 0.85
assignDeterministicIdsFunction · 0.85

Calls 3

sliceMethod · 0.80
hasMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected