File tree Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Expand file tree Collapse file tree 1 file changed +9
-13
lines changed Original file line number Diff line number Diff line change 1
1
// DOM properties that should NOT have "px" added when numeric
2
2
export const IS_NON_DIMENSIONAL = / a c i t | e x (?: s | g | n | p | $ ) | r p h | g r i d | o w s | m n c | n t w | i n e [ c h ] | z o o | ^ o r d | ^ - - / i;
3
3
4
+ const HTML_ENTITY_REG = / [ & < > " ] / g;
5
+ const tagsToReplace = {
6
+ '&' : '&' ,
7
+ '<' : '<' ,
8
+ '>' : '>' ,
9
+ '"' : '"'
10
+ } ;
11
+ const replaceTag = ( tag ) => tagsToReplace [ tag ] || tag ;
4
12
export function encodeEntities ( s ) {
5
13
if ( typeof s !== 'string' ) s = String ( s ) ;
6
- let out = '' ;
7
- for ( let i = 0 ; i < s . length ; i ++ ) {
8
- let ch = s [ i ] ;
9
- // prettier-ignore
10
- switch ( ch ) {
11
- case '<' : out += '<' ; break ;
12
- case '>' : out += '>' ; break ;
13
- case '"' : out += '"' ; break ;
14
- case '&' : out += '&' ; break ;
15
- default : out += ch ;
16
- }
17
- }
18
- return out ;
14
+ return s . replace ( HTML_ENTITY_REG , replaceTag ) ;
19
15
}
20
16
21
17
export let indent = ( s , char ) =>
You can’t perform that action at this time.
0 commit comments