@@ -8,7 +8,11 @@ const { nowDateTime } = require('./time');
88const HTML_ESCAPE_REGEXP = new RegExp ( '[&<>"\'/]' , 'g' ) ;
99
1010const HTML_ESCAPE_CHARS = {
11- '&' : '&' , '<' : '<' , '>' : '>' , '"' : '"' , '\'' : '''
11+ '&' : '&' ,
12+ '<' : '<' ,
13+ '>' : '>' ,
14+ '"' : '"' ,
15+ "'" : ''' ,
1216} ;
1317
1418const ALPHA_UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ;
@@ -19,19 +23,16 @@ const ALPHA_DIGIT = ALPHA + DIGIT;
1923
2024const htmlEscape = (
2125 // Escape html characters
22- content // string, to escape
26+ content , // string, to escape
2327 // Returns: string
2428 // Example: htmlEscape('5>=5') = '5<=5'
25- ) => (
26- content . replace ( HTML_ESCAPE_REGEXP , ( char ) => HTML_ESCAPE_CHARS [ char ] )
27- ) ;
28-
29+ ) => content . replace ( HTML_ESCAPE_REGEXP , ( char ) => HTML_ESCAPE_CHARS [ char ] ) ;
2930const subst = (
3031 // Substitute variables
3132 tpl , // string, template body
3233 data , // hash, data structure to visualize
3334 dataPath , // string, current position in data structure
34- escapeHtml // boolean, escape html special characters if true
35+ escapeHtml , // boolean, escape html special characters if true
3536 // Returns: string
3637) => {
3738 let start = 0 ;
@@ -90,95 +91,78 @@ const subst = (
9091
9192const fileExt = (
9293 // Extract file extension in lower case with no dot
93- fileName // string, file name
94+ fileName , // string, file name
9495 // Returns: string
9596 // Example: fileExt('/dir/file.txt')
9697 // Result: 'txt'
97- ) => (
98- path . extname ( fileName ) . replace ( '.' , '' ) . toLowerCase ( )
99- ) ;
100-
98+ ) => path . extname ( fileName ) . replace ( '.' , '' ) . toLowerCase ( ) ;
10199const removeExt = (
102100 // Remove file extension from file name
103- fileName // string, file name
101+ fileName , // string, file name
104102 // Returns: string
105103 // Example: fileExt('file.txt')
106104 // Result: 'file'
107- ) => (
108- fileName . substr ( 0 , fileName . lastIndexOf ( '.' ) )
109- ) ;
110-
105+ ) => fileName . substr ( 0 , fileName . lastIndexOf ( '.' ) ) ;
111106const CAPITALIZE_REGEXP = / \w + / g;
112107
113108const capitalize = (
114109 // Capitalize string
115- s // string
110+ s , // string
116111 // Returns: string
117- ) => (
118- s . replace ( CAPITALIZE_REGEXP , ( word ) => (
119- word . charAt ( 0 ) . toUpperCase ( ) + word . substr ( 1 ) . toLowerCase ( )
120- ) )
121- ) ;
122-
112+ ) =>
113+ s . replace (
114+ CAPITALIZE_REGEXP ,
115+ ( word ) => word . charAt ( 0 ) . toUpperCase ( ) + word . substr ( 1 ) . toLowerCase ( ) ,
116+ ) ;
123117const UNDERLINE_REGEXP = / _ / g;
124118
125119const spinalToCamel = (
126120 // Convert spinal case to camel case
127- name // string
121+ name , // string
128122 // Returns: string
129- ) => (
123+ ) =>
130124 name
131125 . replace ( UNDERLINE_REGEXP , '-' )
132126 . split ( '-' )
133127 . map ( ( part , i ) => ( i > 0 ? capitalize ( part ) : part ) )
134- . join ( '' )
135- ) ;
136-
128+ . join ( '' ) ;
137129const ESCAPE_REGEXP_SPECIALS = [
138130 // order matters for these
139131 '-' , '[' , ']' ,
140132 // order doesn't matter for any of these
141- '/' , '{' , '}' , '(' , ')' , '*' , '+' , '?' , '.' , '\\' , '^' , '$' , '|'
133+ '/' , '{' , '}' , '(' , ')' , '*' , '+' , '?' , '.' , '\\' , '^' , '$' , '|' ,
142134] ;
143135
144136const ESCAPE_REGEXP = new RegExp (
145- '[' + ESCAPE_REGEXP_SPECIALS . join ( '\\' ) + ']' , 'g'
137+ '[' + ESCAPE_REGEXP_SPECIALS . join ( '\\' ) + ']' , 'g' ,
146138) ;
147139
148140const escapeRegExp = (
149141 // Escape regular expression control characters
150- s // string
142+ s , // string
151143 // Returns: string
152144 // Example: escapeRegExp('/path/to/res?search=this.that')
153- ) => (
154- s . replace ( ESCAPE_REGEXP , '\\$&' )
155- ) ;
156-
145+ ) => s . replace ( ESCAPE_REGEXP , '\\$&' ) ;
157146const newEscapedRegExp = (
158147 // Generate escaped regular expression
159- s // string
148+ s , // string
160149 // Returns: RegExp, instance
161- ) => (
162- new RegExp ( escapeRegExp ( s ) , 'g' )
163- ) ;
164-
150+ ) => new RegExp ( escapeRegExp ( s ) , 'g' ) ;
165151const addTrailingSlash = (
166152 // Add trailing slash at the end if there isn't one
167- s // string
153+ s , // string
168154 // Returns: string
169155) => s + ( s . endsWith ( '/' ) ? '' : '/' ) ;
170156
171157const stripTrailingSlash = (
172158 // Remove trailing slash from string
173- s // string
159+ s , // string
174160 // Returns: string
175- ) => (
176- s . endsWith ( '/' ) ? s . substr ( 0 , s . length - 1 ) : s
177- ) ;
161+ ) => ( s . endsWith ( '/' ) ? s . substr ( 0 , s . length - 1 ) : s ) ;
178162
179163const dirname = (
180164 // Get directory name with trailing slash from path
181- filePath // string
165+ filePath , // string
182166 // Returns: string
183167) => {
184168 let dir = path . dirname ( filePath ) ;
@@ -190,7 +174,7 @@ const between = (
190174 // Extract substring between prefix and suffix
191175 s , // string, source
192176 prefix , // string, before needed fragment
193- suffix // string, after needed fragment
177+ suffix , // string, after needed fragment
194178 // Returns: string
195179) => {
196180 let i = s . indexOf ( prefix ) ;
@@ -208,23 +192,21 @@ const BOM_REGEXP = /^[\uBBBF\uFEFF]*/;
208192
209193const removeBOM = (
210194 // Remove UTF-8 BOM
211- s // string, possibly starts with BOM
195+ s , // string, possibly starts with BOM
212196 // Returns: string
213- ) => (
214- typeof s === 'string' ? s . replace ( BOM_REGEXP , '' ) : s
215- ) ;
197+ ) => ( typeof s === 'string' ? s . replace ( BOM_REGEXP , '' ) : s ) ;
216198
217199const ITEM_ESCAPE_REGEXP = / \\ \* / g;
218200
219201const arrayRegExp = (
220202 // Generate RegExp from array with '*' wildcards
221- items // array of strings
203+ items , // array of strings
222204 // Returns: RegExp, instance
223205 // Example: ['/css/*', '/index.html']
224206) => {
225207 if ( ! items || items . length === 0 ) return null ;
226- items = items . map (
227- ( item ) => escapeRegExp ( item ) . replace ( ITEM_ESCAPE_REGEXP , '.*' )
208+ items = items . map ( ( item ) =>
209+ escapeRegExp ( item ) . replace ( ITEM_ESCAPE_REGEXP , '.*' ) ,
228210 ) ;
229211 const ex = items . length === 1 ? items [ 0 ] : '((' + items . join ( ')|(' ) + '))' ;
230212 return new RegExp ( '^' + ex + '$' ) ;
@@ -233,7 +215,7 @@ const arrayRegExp = (
233215const section = (
234216 // Split string by the first occurrence of separator
235217 s , // string
236- separator // string, or char
218+ separator , // string, or char
237219 // Returns: array of strings
238220 // Example: rsection('All you need is JavaScript', 'is')
239221 // Result: ['All you need ', ' JavaScript']
@@ -246,7 +228,7 @@ const section = (
246228const rsection = (
247229 // Split string by the last occurrence of separator
248230 s , // string
249- separator // string, or char
231+ separator , // string, or char
250232 // Returns: array of strings
251233 // Example: rsection('All you need is JavaScript', 'a')
252234 // Result: ['All you need is Jav', 'Script']
@@ -260,21 +242,18 @@ const split = (
260242 // Split string by multiple occurrence of separator
261243 s , // string
262244 separator = ',' , // string (optional), default: ','
263- limit = - 1 // number (optional), max length of result array
245+ limit = - 1 , // number (optional), max length of result array
264246 // Returns: array of strings
265247 // Example: split('a,b,c,d')
266248 // Result: ['a', 'b', 'c', 'd']
267249 // Example: split('a,b,c,d', ',', 2)
268250 // Result: ['a', 'b']
269- ) => (
270- s . split ( separator , limit )
271- ) ;
272-
251+ ) => s . split ( separator , limit ) ;
273252const rsplit = (
274253 // Split string by multiple occurrences of separator
275254 s , // string
276255 separator = ',' , // string (optional), default: ','
277- limit = - 1 // number (optional), max length of result array
256+ limit = - 1 , // number (optional), max length of result array
278257 // Returns: array of strings
279258 // Example: split('a,b,c,d', ',', 2)
280259 // Result: ['c', 'd']
0 commit comments