MCPcopy Create free account
hub / github.com/GCWing/BitFun / extractStringArrayConstant

Function extractStringArrayConstant

scripts/i18n-contract.test.mjs:100–108  ·  view source on GitHub ↗
(source, exportName)

Source from the content-addressed store, hash-verified

98}
99
100function extractStringArrayConstant(source, exportName) {
101 const marker = `export const ${exportName} = [`;
102 const start = source.indexOf(marker);
103 assert.notEqual(start, -1, `missing ${exportName} constant`);
104 const body = source.slice(start + marker.length);
105 const end = body.indexOf('] as const');
106 assert.notEqual(end, -1, `${exportName} must be an as const string array`);
107 return [...body.slice(0, end).matchAll(/'([^']+)'/g)].map((entry) => entry[1]);
108}
109
110function escapeRegExp(value) {
111 return String(value).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');

Callers 1

Calls 1

sliceMethod · 0.80

Tested by

no test coverage detected