1- import { build as buildPattern } from './utils/pattern' ;
2- import { build as buildTrie } from './utils/trie' ;
1+ import { condense , condenseIgnoreCase } from './index' ;
32import { parseString , WhitespaceHandling } from './utils/wordList' ;
43
54const { Preserve, TrimLeadingAndTrailing } = WhitespaceHandling ;
@@ -11,21 +10,24 @@ const $caseSensitive = document.querySelector<HTMLInputElement>('.js-case');
1110const $trim = document . querySelector < HTMLInputElement > ( '.js-trim' ) ;
1211const $output = document . querySelector < HTMLTextAreaElement > ( '.js-output' ) ;
1312
14- function generatePattern (
15- words : string ,
16- delimiter : string ,
17- whitespace : WhitespaceHandling
18- ) : string {
13+ function generatePattern ( words : string ) : RegExp {
14+ const delimiter = $delimiter . options [ $delimiter . selectedIndex ] . value ;
15+ const isCaseSensitive = $caseSensitive . checked ;
16+ const isWhitespaceTrimmed = $trim . checked ;
17+
18+ const whitespace = isWhitespaceTrimmed ? TrimLeadingAndTrailing : Preserve ;
19+
1920 const wordList = parseString ( words , delimiter , whitespace ) ;
20- const wordTrie = buildTrie ( wordList ) ;
21- const pattern = buildPattern ( wordTrie ) ;
21+
22+ const fnCondense = isCaseSensitive ? condense : condenseIgnoreCase ;
23+ const pattern = fnCondense ( wordList ) ;
2224
2325 return pattern ;
2426}
2527
2628let clearSuccessIndicatorHandle : number ;
27- function displayPattern ( pattern : string ) : void {
28- $output . value = pattern ;
29+ function displayPattern ( pattern : RegExp ) : void {
30+ $output . value = pattern . toString ( ) ;
2931
3032 // Temporarily style the output box as valid
3133 $output . classList . add ( 'is-valid' ) ;
@@ -46,19 +48,8 @@ function onClickGenerate(): void {
4648 // Ignore browsers that don't support reportValidity()
4749 }
4850
49- let words = $input . value ;
50- const delimiter = $delimiter . options [ $delimiter . selectedIndex ] . value ;
51- const isCaseSensitive = $caseSensitive . checked ;
52- const isWhitespaceTrimmed = $trim . checked ;
53-
54- if ( ! isCaseSensitive ) {
55- words = words . toLowerCase ( ) ;
56- }
57-
58- const whitespace = isWhitespaceTrimmed ? TrimLeadingAndTrailing : Preserve ;
59-
60- const pattern = generatePattern ( words , delimiter , whitespace ) ;
61-
51+ const words = $input . value ;
52+ const pattern = generatePattern ( words ) ;
6253 displayPattern ( pattern ) ;
6354}
6455
@@ -72,6 +63,6 @@ document
7263 'Colorado, Connecticut, Delaware, Florida, Georgia' ;
7364
7465 $input . value = exampleInput ;
75- const pattern = generatePattern ( exampleInput , ',' , TrimLeadingAndTrailing ) ;
66+ const pattern = generatePattern ( exampleInput ) ;
7667 displayPattern ( pattern ) ;
7768} ) ( ) ;
0 commit comments