MCPcopy Create free account
hub / github.com/GoogleChrome/samples / cleanString

Method cleanString

google-drive-embeddings/src/parser.js:44–59  ·  view source on GitHub ↗

* Cleans a filename by removing extensions and normalizing spacers.

(str)

Source from the content-addressed store, hash-verified

42 * Cleans a filename by removing extensions and normalizing spacers.
43 */
44 static cleanString(str) {
45 if (!str) return '';
46 // Strip .mp3 extension if present
47 let cleaned = str.replace(/\.mp3$/i, '');
48 // Replace underscores with spaces
49 cleaned = cleaned.replace(/_/g, ' ');
50
51 // Strip leading numeric track index if followed by spacer punctuation (dot/dash/spaces)
52 // e.g. "01. Linkin Park" -> "Linkin Park", "02-Pink Floyd" -> "Pink Floyd"
53 cleaned = cleaned.replace(/^\s*\d+[\s.-]*[.-]+\s*(?=[a-zA-Z0-9])/, '');
54
55 // Remove typical enclosing characters like brackets/quotes
56 cleaned = cleaned.replace(/[\[\]\(\)"']/g, ' ');
57 // Normalize spaces
58 return cleaned.replace(/\s+/g, ' ').trim();
59 }
60
61 /**
62 * Checks if a specific string part is generic or uninformative.

Callers 1

parseMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected