@@ -6,6 +6,8 @@ import {escapeKey, escapeValue} from './escape'
6
6
export type Properties = {
7
7
/**
8
8
* Plain text unparsed lines.
9
+ *
10
+ * Must not contain newline (`\r` and `\n`) characters.
9
11
*/
10
12
lines : string [ ]
11
13
}
@@ -25,14 +27,14 @@ export type KeyValuePair = {
25
27
}
26
28
27
29
/**
28
- * Returns an empty object .
30
+ * Byte-order mark .
29
31
*/
30
- export const empty = ( ) : Properties => ( { lines : [ ] } )
32
+ export const BOM = 0xfeff
31
33
32
34
/**
33
- * Byte-order mark .
35
+ * Returns an empty object .
34
36
*/
35
- export const BOM = 0xfeff
37
+ export const empty = ( ) : Properties => ( { lines : [ ] } )
36
38
37
39
/**
38
40
* Parses java properties file contents.
@@ -299,7 +301,7 @@ function* listPairs(lines: string[]): Generator<{
299
301
if ( state . unicode ) {
300
302
// Handle incomplete sequence
301
303
if ( char === 'EOL' ) {
302
- throw new Error ( `Invalid unicode sequence at line ${ lineNumber } ` )
304
+ throw newUnicodeError ( lineNumber )
303
305
}
304
306
305
307
// Append and consume until it has correct length
@@ -491,9 +493,13 @@ const unescapeControlChar = (c: string): string => {
491
493
}
492
494
}
493
495
494
- const parseUnicode = ( sequence : string , line : number ) : string => {
496
+ const parseUnicode = ( sequence : string , lineNumber : number ) : string => {
495
497
if ( ! sequence . match ( / ^ 0 x [ \d a - f A - F ] { 4 } $ / ) ) {
496
- throw new Error ( `Invalid unicode sequence at line ${ line } ` )
498
+ throw newUnicodeError ( lineNumber )
497
499
}
498
500
return String . fromCodePoint ( parseInt ( sequence , 16 ) )
499
501
}
502
+
503
+ const newUnicodeError = ( lineNumber : number ) : Error => {
504
+ return new Error ( `Invalid unicode sequence at line ${ lineNumber } ` )
505
+ }
0 commit comments