mirror of https://github.com/sveltejs/svelte
[chore]: store regexp as variable instead of defining it inline (#7716)
* store regexp as variable instead of defining it inline * fix naming of `regex_quoted_value` * some more variables * optimize `.replace() calls * restore formatting changes * optimize `parser.*` calls * small refactor * optimize `.test() calls * rename some variables * fix tests * rename pattern variables * extract common regexes into `patters.ts` * rename variables to use snake_case * fix trimpull/7942/head
parent
26a428972b
commit
0eba57113b
@ -1,6 +1,24 @@
|
||||
export const whitespace = /[ \t\r\n]/;
|
||||
export const start_whitespace = /^[ \t\r\n]*/;
|
||||
export const end_whitespace = /[ \t\r\n]*$/;
|
||||
export const start_newline = /^\r?\n/;
|
||||
export const regex_whitespace = /\s/;
|
||||
export const regex_whitespaces = /\s+/;
|
||||
export const regex_starts_with_whitespace = /^\s/;
|
||||
export const regex_starts_with_whitespaces = /^[ \t\r\n]*/;
|
||||
export const regex_ends_with_whitespace = /\s$/;
|
||||
export const regex_ends_with_whitespaces = /[ \t\r\n]*$/;
|
||||
export const regex_only_whitespaces = /^\s+$/;
|
||||
|
||||
export const dimensions = /^(?:offset|client)(?:Width|Height)$/;
|
||||
export const regex_whitespace_characters = /\s/g;
|
||||
export const regex_non_whitespace_character = /\S/;
|
||||
|
||||
export const regex_starts_with_newline = /^\r?\n/;
|
||||
export const regex_not_newline_characters = /[^\n]/g;
|
||||
|
||||
export const regex_double_quotes = /"/g;
|
||||
|
||||
export const regex_backslashes = /\\/g;
|
||||
|
||||
export const regex_starts_with_underscore = /^_/;
|
||||
export const regex_ends_with_underscore = /_$/;
|
||||
|
||||
export const regex_invalid_variable_identifier_characters = /[^a-zA-Z0-9_$]/g;
|
||||
|
||||
export const regex_dimensions = /^(?:offset|client)(?:Width|Height)$/;
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { start_whitespace, end_whitespace } from './patterns';
|
||||
import { regex_starts_with_whitespaces, regex_ends_with_whitespaces } from './patterns';
|
||||
|
||||
export function trim_start(str: string) {
|
||||
return str.replace(start_whitespace, '');
|
||||
return str.replace(regex_starts_with_whitespaces, '');
|
||||
}
|
||||
|
||||
export function trim_end(str: string) {
|
||||
return str.replace(end_whitespace, '');
|
||||
return str.replace(regex_ends_with_whitespaces, '');
|
||||
}
|
||||
|
Loading…
Reference in new issue