8 lines
399 B
TypeScript
8 lines
399 B
TypeScript
// A cell that starts with one of these is read as a formula by spreadsheet programs once the text is pasted or converted.
|
|
const FORMULA_START = /^[=+\-@\t\r]/;
|
|
|
|
/** Text that is safe to write into a spreadsheet cell: a leading formula character is neutralised with an apostrophe. */
|
|
export function neutralizeFormula(text: string): string {
|
|
return FORMULA_START.test(text) ? `'${text}` : text;
|
|
}
|