diff options
Diffstat (limited to 'packages/astro-parser/src/utils/trim.ts')
-rw-r--r-- | packages/astro-parser/src/utils/trim.ts | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/packages/astro-parser/src/utils/trim.ts b/packages/astro-parser/src/utils/trim.ts new file mode 100644 index 000000000..480cc99a8 --- /dev/null +++ b/packages/astro-parser/src/utils/trim.ts @@ -0,0 +1,17 @@ +import { whitespace } from './patterns.js'; + +/** Trim whitespace from start of string */ +export function trim_start(str: string) { + let i = 0; + while (whitespace.test(str[i])) i += 1; + + return str.slice(i); +} + +/** Trim whitespace from end of string */ +export function trim_end(str: string) { + let i = str.length; + while (whitespace.test(str[i - 1])) i -= 1; + + return str.slice(0, i); +} |