MCPcopy Create free account
hub / github.com/rollup/plugins / makeLegalIdentifier

Function makeLegalIdentifier

packages/pluginutils/src/makeLegalIdentifier.ts:11–21  ·  view source on GitHub ↗
(str)

Source from the content-addressed store, hash-verified

9forbiddenIdentifiers.add('');
10
11const makeLegalIdentifier: MakeLegalIdentifier = function makeLegalIdentifier(str) {
12 let identifier = str
13 .replace(/-(\w)/g, (_, letter) => letter.toUpperCase())
14 .replace(/[^$_a-zA-Z0-9]/g, '_');
15
16 if (/\d/.test(identifier[0]) || forbiddenIdentifiers.has(identifier)) {
17 identifier = `_${identifier}`;
18 }
19
20 return identifier || '_';
21};
22
23export { makeLegalIdentifier as default };

Callers 7

handleReferenceFunction · 0.90
deconflictFunction · 0.90
getNameFunction · 0.90
transformFunction · 0.90
serializeObjectFunction · 0.85
dataToEsmFunction · 0.85

Calls 1

hasMethod · 0.80

Tested by

no test coverage detected