(raw: string, fallbackPrefix = 'col')
| 164 | * is a letter or underscore (prefixing with `fallbackPrefix` otherwise). |
| 165 | */ |
| 166 | export function sanitizeName(raw: string, fallbackPrefix = 'col'): string { |
| 167 | let name = raw |
| 168 | .trim() |
| 169 | .replace(/[^a-zA-Z0-9_]/g, '_') |
| 170 | .replace(/_+/g, '_') |
| 171 | .replace(/^_+|_+$/g, '') |
| 172 | |
| 173 | if (!name || /^\d/.test(name)) { |
| 174 | name = `${fallbackPrefix}_${name}` |
| 175 | } |
| 176 | |
| 177 | return name |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * Returns column definitions inferred from CSV headers + sample rows. Duplicate |
no test coverage detected