MCPcopy
hub / github.com/1weiho/open-slide / safeAssetIdentifier

Function safeAssetIdentifier

packages/core/src/editing/edit-ops.ts:104–128  ·  view source on GitHub ↗
(filename: string, taken: Set<string>)

Source from the content-addressed store, hash-verified

102}
103
104export function safeAssetIdentifier(filename: string, taken: Set<string>): string {
105 const stem = filename.replace(/\.[^.]+$/, '');
106 let camel = '';
107 let upper = false;
108 for (const ch of stem) {
109 if (/[A-Za-z0-9]/.test(ch)) {
110 camel += upper ? ch.toUpperCase() : ch;
111 upper = false;
112 } else {
113 upper = camel.length > 0;
114 }
115 }
116 let base = camel;
117 if (!base || !/^[A-Za-z_$]/.test(base)) {
118 base = `asset${base.charAt(0).toUpperCase()}${base.slice(1)}` || 'asset';
119 }
120 base = base.charAt(0).toLowerCase() + base.slice(1);
121 let candidate = base;
122 let i = 2;
123 while (taken.has(candidate)) {
124 candidate = `${base}${i}`;
125 i += 1;
126 }
127 return candidate;
128}
129
130type JsxContainer = t.JSXElement | t.JSXFragment;
131

Callers 2

edit-ops.test.tsFile · 0.90
planAssetImportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected