File tree Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Expand file tree Collapse file tree 3 files changed +21
-9
lines changed Original file line number Diff line number Diff line change 1
1
export const whitespace = / [ \t \r \n ] / ;
2
+ export const start_whitespace = / ^ [ \t \r \n ] * / ;
3
+ export const end_whitespace = / [ \t \r \n ] * $ / ;
2
4
3
5
export const dimensions = / ^ (?: o f f s e t | c l i e n t ) (?: W i d t h | H e i g h t ) $ / ;
Original file line number Diff line number Diff line change 1
- import { whitespace } from './patterns' ;
1
+ import { start_whitespace , end_whitespace } from './patterns' ;
2
2
3
3
export function trim_start ( str : string ) {
4
- let i = 0 ;
5
- while ( whitespace . test ( str [ i ] ) ) i += 1 ;
6
-
7
- return str . slice ( i ) ;
4
+ return str . replace ( start_whitespace , '' ) ;
8
5
}
9
6
10
7
export function trim_end ( str : string ) {
11
- let i = str . length ;
12
- while ( whitespace . test ( str [ i - 1 ] ) ) i -= 1 ;
13
-
14
- return str . slice ( 0 , i ) ;
8
+ return str . replace ( end_whitespace , '' ) ;
15
9
}
Original file line number Diff line number Diff line change
1
+ import * as assert from 'assert' ;
2
+ import { trim_start , trim_end } from '../../src/compiler/utils/trim' ;
3
+
4
+ describe ( 'utils' , ( ) => {
5
+ describe ( 'trim' , ( ) => {
6
+ it ( 'trim_start' , ( ) => {
7
+ const value = trim_start ( ' \r\n\t svelte content \r\n\t ' ) ;
8
+ assert . equal ( value , 'svelte content \r\n\t ' ) ;
9
+ } ) ;
10
+
11
+ it ( 'trim_end' , ( ) => {
12
+ const value = trim_end ( ' \r\n\t svelte content \r\n\t ' ) ;
13
+ assert . equal ( value , ' \r\n\t svelte content' ) ;
14
+ } ) ;
15
+ } ) ;
16
+ } ) ;
You can’t perform that action at this time.
0 commit comments