properties-file 3.1.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/editor/index.js +74 -286
- package/lib/escape/index.js +26 -96
- package/lib/index.d.ts +0 -1
- package/lib/index.js +9 -17
- package/lib/loader/webpack.d.ts +0 -1
- package/lib/loader/webpack.js +7 -14
- package/lib/properties.d.ts +1 -1
- package/lib/properties.js +52 -218
- package/lib/property-line.js +9 -48
- package/lib/property.js +38 -171
- package/lib/unescape/index.js +13 -69
- package/package.json +13 -8
package/lib/editor/index.js
CHANGED
|
@@ -1,286 +1,74 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
var escapeUnicode = (options === null || options === void 0 ? void 0 : options.escapeUnicode) || false;
|
|
76
|
-
var separator = (options === null || options === void 0 ? void 0 : options.separator)
|
|
77
|
-
? options.separator === ' '
|
|
78
|
-
? ' '
|
|
79
|
-
: " ".concat(options.separator, " ")
|
|
80
|
-
: " ".concat(exports.DEFAULT_SEPARATOR, " ").replace(' ', ' ');
|
|
81
|
-
var referenceKey = options === null || options === void 0 ? void 0 : options.referenceKey;
|
|
82
|
-
var position = (options === null || options === void 0 ? void 0 : options.position) || 'after';
|
|
83
|
-
// Allow multiline keys.
|
|
84
|
-
var multilineKey = key
|
|
85
|
-
.split(/\r?\n/)
|
|
86
|
-
.map(function (key) { return (0, escape_1.escapeKey)(key, escapeUnicode); })
|
|
87
|
-
.join('\\\n');
|
|
88
|
-
// Allow multiline values.
|
|
89
|
-
var multilineValue = value
|
|
90
|
-
.split(/\r?\n/)
|
|
91
|
-
.map(function (value) { return (0, escape_1.escapeValue)(value, escapeUnicode); })
|
|
92
|
-
.join('\\\n');
|
|
93
|
-
// Allow multiline comments.
|
|
94
|
-
var commentPrefix = "".concat((options === null || options === void 0 ? void 0 : options.commentDelimiter) || exports.DEFAULT_COMMENT_DELIMITER, " ");
|
|
95
|
-
var multilineComment = (options === null || options === void 0 ? void 0 : options.comment) === undefined
|
|
96
|
-
? ''
|
|
97
|
-
: "".concat("".concat(commentPrefix).concat(options.comment).split(/\r?\n/).join("\n".concat(commentPrefix)), "\n");
|
|
98
|
-
var newLines = "".concat(multilineComment).concat(multilineKey).concat(separator).concat(multilineValue).split(/\n/);
|
|
99
|
-
if (referenceKey === undefined) {
|
|
100
|
-
// Insert the new property at the end if the reference key was not defined.
|
|
101
|
-
(_a = this.lines).push.apply(_a, __spreadArray([], __read(newLines), false));
|
|
102
|
-
this.parseLines();
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// Find the last occurrence of the reference key.
|
|
107
|
-
var property = __spreadArray([], __read(this.collection), false).reverse()
|
|
108
|
-
.find(function (property) { return property.key === referenceKey; });
|
|
109
|
-
// Insert the new property when a reference key defined only when found.
|
|
110
|
-
if (property) {
|
|
111
|
-
var insertPosition = position === 'after'
|
|
112
|
-
? property.endingLineNumber
|
|
113
|
-
: (_c = (_b = property.previousProperty) === null || _b === void 0 ? void 0 : _b.endingLineNumber) !== null && _c !== void 0 ? _c : 0;
|
|
114
|
-
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, insertPosition)), false), __read(newLines), false), __read(this.lines.slice(insertPosition)), false);
|
|
115
|
-
this.parseLines();
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
return false;
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
/**
|
|
122
|
-
* Insert a new comment in the existing object (by default it will be at the end).
|
|
123
|
-
*
|
|
124
|
-
* @param comment - The comment to add.
|
|
125
|
-
* @param options - Additional options.
|
|
126
|
-
*
|
|
127
|
-
* @returns True if the comment was inserted, otherwise false.
|
|
128
|
-
*/
|
|
129
|
-
PropertiesEditor.prototype.insertComment = function (comment, options) {
|
|
130
|
-
var _a;
|
|
131
|
-
var _b, _c;
|
|
132
|
-
var referenceKey = options === null || options === void 0 ? void 0 : options.referenceKey;
|
|
133
|
-
var position = (options === null || options === void 0 ? void 0 : options.position) || 'after';
|
|
134
|
-
// Allow multiline comments.
|
|
135
|
-
var commentPrefix = "".concat((options === null || options === void 0 ? void 0 : options.commentDelimiter) || exports.DEFAULT_COMMENT_DELIMITER, " ");
|
|
136
|
-
var newLines = "".concat(commentPrefix).concat(comment)
|
|
137
|
-
.replace(/\r?\n/g, "\n".concat(commentPrefix))
|
|
138
|
-
.split(/\n/);
|
|
139
|
-
if (referenceKey === undefined) {
|
|
140
|
-
// Insert the new comment at the end if the reference key was not defined.
|
|
141
|
-
(_a = this.lines).push.apply(_a, __spreadArray([], __read(newLines), false));
|
|
142
|
-
this.parseLines();
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
else {
|
|
146
|
-
// Find the last occurrence of the reference key.
|
|
147
|
-
var property = __spreadArray([], __read(this.collection), false).reverse()
|
|
148
|
-
.find(function (property) { return property.key === referenceKey; });
|
|
149
|
-
// Insert the new comment when a reference key defined only when found.
|
|
150
|
-
if (property) {
|
|
151
|
-
var insertPosition = position === 'after'
|
|
152
|
-
? property.endingLineNumber
|
|
153
|
-
: (_c = (_b = property.previousProperty) === null || _b === void 0 ? void 0 : _b.endingLineNumber) !== null && _c !== void 0 ? _c : 0;
|
|
154
|
-
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, insertPosition)), false), __read(newLines), false), __read(this.lines.slice(insertPosition)), false);
|
|
155
|
-
this.parseLines();
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
return false;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
/**
|
|
162
|
-
* Delete the last occurrence of a given key from the existing object.
|
|
163
|
-
*
|
|
164
|
-
* @param key - The name of the key to delete.
|
|
165
|
-
* @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
|
|
166
|
-
*
|
|
167
|
-
* @returns True if the key was deleted, otherwise false.
|
|
168
|
-
*/
|
|
169
|
-
PropertiesEditor.prototype.delete = function (key, deleteCommentsAndWhiteSpace) {
|
|
170
|
-
var _a, _b;
|
|
171
|
-
if (deleteCommentsAndWhiteSpace === void 0) { deleteCommentsAndWhiteSpace = true; }
|
|
172
|
-
// Find the last occurrence of the key.
|
|
173
|
-
var property = __spreadArray([], __read(this.collection), false).reverse().find(function (property) { return property.key === key; });
|
|
174
|
-
if (property) {
|
|
175
|
-
var startLine = deleteCommentsAndWhiteSpace
|
|
176
|
-
? (_b = (_a = property.previousProperty) === null || _a === void 0 ? void 0 : _a.endingLineNumber) !== null && _b !== void 0 ? _b : 0
|
|
177
|
-
: property.startingLineNumber - 1;
|
|
178
|
-
var endLine = property.endingLineNumber;
|
|
179
|
-
this.lines = __spreadArray(__spreadArray([], __read(this.lines.slice(0, startLine)), false), __read(this.lines.slice(endLine)), false);
|
|
180
|
-
this.parseLines();
|
|
181
|
-
return true;
|
|
182
|
-
}
|
|
183
|
-
return false;
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* Restore the original newline characters of a key.
|
|
187
|
-
*
|
|
188
|
-
* @param property - A property object.
|
|
189
|
-
*
|
|
190
|
-
* @returns The key with its original newlines characters restored.
|
|
191
|
-
*/
|
|
192
|
-
PropertiesEditor.prototype.getKeyWithNewlines = function (property) {
|
|
193
|
-
return property.newlinePositions.length === 0
|
|
194
|
-
? property.key
|
|
195
|
-
: // eslint-disable-next-line unicorn/no-array-reduce
|
|
196
|
-
__spreadArray([], __read(property.key), false).reduce(function (accumulator, character, index) {
|
|
197
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
198
|
-
return "".concat(accumulator).concat(property.newlinePositions.includes(index) ? '\n' : '').concat(character);
|
|
199
|
-
}, '');
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* Restore the original newline characters of a value.
|
|
203
|
-
*
|
|
204
|
-
* @param property - A property object.
|
|
205
|
-
*
|
|
206
|
-
* @returns The value with its original newlines characters restored.
|
|
207
|
-
*/
|
|
208
|
-
PropertiesEditor.prototype.getValueWithNewlines = function (property) {
|
|
209
|
-
return property.newlinePositions.length === 0 || property.valuePosition === undefined
|
|
210
|
-
? property.value
|
|
211
|
-
: // eslint-disable-next-line unicorn/no-array-reduce
|
|
212
|
-
__spreadArray([], __read(property.value), false).reduce(function (accumulator, character, index) {
|
|
213
|
-
return "".concat(accumulator).concat(property.newlinePositions.includes(index + property.valuePosition)
|
|
214
|
-
? '\n'
|
|
215
|
-
: ''
|
|
216
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
217
|
-
).concat(character);
|
|
218
|
-
}, '');
|
|
219
|
-
};
|
|
220
|
-
/**
|
|
221
|
-
* Update the last occurrence of a given key from the existing object.
|
|
222
|
-
*
|
|
223
|
-
* @param key - The name of the key to update.
|
|
224
|
-
* @param options - Additional options.
|
|
225
|
-
*
|
|
226
|
-
* @returns True if the key was updated, otherwise false.
|
|
227
|
-
*/
|
|
228
|
-
PropertiesEditor.prototype.update = function (key, options) {
|
|
229
|
-
var _a, _b, _c, _d;
|
|
230
|
-
// Find the last occurrence of the key to update.
|
|
231
|
-
var property = __spreadArray([], __read(this.collection), false).reverse().find(function (property) { return property.key === key; });
|
|
232
|
-
if (!property || !options) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
var escapeUnicode = options.escapeUnicode || false;
|
|
236
|
-
var separator = options.separator
|
|
237
|
-
? options.separator === ' '
|
|
238
|
-
? ' '
|
|
239
|
-
: " ".concat(options.separator, " ")
|
|
240
|
-
: property.separator || " ".concat(exports.DEFAULT_SEPARATOR, " ").replace(' ', ' ');
|
|
241
|
-
// Allow multiline keys.
|
|
242
|
-
var multilineKey = ((_a = options.newKey) !== null && _a !== void 0 ? _a : this.getKeyWithNewlines(property))
|
|
243
|
-
.split(/\r?\n/)
|
|
244
|
-
.map(function (key) { return (0, escape_1.escapeKey)(key, escapeUnicode); })
|
|
245
|
-
.join('\\\n');
|
|
246
|
-
// Allow multiline values.
|
|
247
|
-
var multilineValue = ((_b = options.newValue) !== null && _b !== void 0 ? _b : this.getValueWithNewlines(property))
|
|
248
|
-
.split(/\r?\n/)
|
|
249
|
-
.map(function (value) { return (0, escape_1.escapeValue)(value, escapeUnicode); })
|
|
250
|
-
.join('\\\n');
|
|
251
|
-
// Allow multiline comments.
|
|
252
|
-
var commentPrefix = "".concat(options.commentDelimiter || exports.DEFAULT_COMMENT_DELIMITER, " ");
|
|
253
|
-
var multilineComment = options.newComment === undefined
|
|
254
|
-
? ''
|
|
255
|
-
: "".concat("".concat(commentPrefix).concat(options.newComment).split(/\r?\n/).join("\n".concat(commentPrefix)), "\n");
|
|
256
|
-
var newLines = "".concat(multilineComment).concat(multilineKey).concat(separator).concat(multilineValue).split(/\n/);
|
|
257
|
-
// Replace the existing property with the new one.
|
|
258
|
-
this.lines = __spreadArray(__spreadArray(__spreadArray([], __read(this.lines.slice(0, options.newComment === undefined
|
|
259
|
-
? property.startingLineNumber - 1
|
|
260
|
-
: (_d = (_c = property.previousProperty) === null || _c === void 0 ? void 0 : _c.endingLineNumber) !== null && _d !== void 0 ? _d : 0)), false), __read(newLines), false), __read(this.lines.slice(property.endingLineNumber)), false);
|
|
261
|
-
this.parseLines();
|
|
262
|
-
return true;
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* Update a key if it exist, otherwise add it at the end.
|
|
266
|
-
*
|
|
267
|
-
* @param key - A property key (unescaped).
|
|
268
|
-
* @param value - A property value (unescaped).
|
|
269
|
-
* @param options - Additional options.
|
|
270
|
-
*
|
|
271
|
-
* @returns True if the key was updated or inserted, otherwise false.
|
|
272
|
-
*/
|
|
273
|
-
PropertiesEditor.prototype.upsert = function (key, value, options) {
|
|
274
|
-
return this.keyLineNumbers[key]
|
|
275
|
-
? this.update(key, {
|
|
276
|
-
newValue: value,
|
|
277
|
-
newComment: options === null || options === void 0 ? void 0 : options.comment,
|
|
278
|
-
commentDelimiter: options === null || options === void 0 ? void 0 : options.commentDelimiter,
|
|
279
|
-
separator: options === null || options === void 0 ? void 0 : options.separator,
|
|
280
|
-
escapeUnicode: options === null || options === void 0 ? void 0 : options.escapeUnicode,
|
|
281
|
-
})
|
|
282
|
-
: this.insert(key, value, options);
|
|
283
|
-
};
|
|
284
|
-
return PropertiesEditor;
|
|
285
|
-
}(properties_1.Properties));
|
|
286
|
-
exports.PropertiesEditor = PropertiesEditor;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertiesEditor=exports.DEFAULT_SEPARATOR=exports.DEFAULT_COMMENT_DELIMITER=void 0,require("core-js/modules/es.string.replace.js"),require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/esnext.string.replace-all.js");var _escape=require("../escape"),_properties=require("../properties");/** The default separator between keys and values. */const DEFAULT_SEPARATOR="=";/** The default character used as comment delimiter. */exports.DEFAULT_SEPARATOR="=";const DEFAULT_COMMENT_DELIMITER="#";/** Characters that can be used as key-value pair separators. */ /** Characters that can be used as comment delimiters. */ /** Options on the `Properties.insert` method. */ /** Options on the `Properties.insertComment` method. */ /** Options on the `Properties.update` method. */ /** Options on the `Properties.upsert` method. */exports.DEFAULT_COMMENT_DELIMITER="#";/**
|
|
2
|
+
* A .properties file editor.
|
|
3
|
+
*/class PropertiesEditor extends _properties.Properties{/**
|
|
4
|
+
* Create `PropertiesEditor` object.
|
|
5
|
+
*
|
|
6
|
+
* @param content - The content of a `.properties` file.
|
|
7
|
+
*/constructor(a){super(a)}/**
|
|
8
|
+
* Insert a new property in the existing object (by default it will be at the end).
|
|
9
|
+
*
|
|
10
|
+
* @param key - A property key (unescaped).
|
|
11
|
+
* @param value - A property value (unescaped).
|
|
12
|
+
* @param options - Additional options.
|
|
13
|
+
*
|
|
14
|
+
* @returns True if the key was inserted, otherwise false.
|
|
15
|
+
*/insert(a,b,c){const d=(null===c||void 0===c?void 0:c.escapeUnicode)||!1,e=null!==c&&void 0!==c&&c.separator?" "===c.separator?" ":" ".concat(c.separator," "):" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),f=null===c||void 0===c?void 0:c.referenceKey,g=(null===c||void 0===c?void 0:c.position)||"after",h=a.split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,d)).join("\\\n"),i=b.split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,d)).join("\\\n"),j="".concat((null===c||void 0===c?void 0:c.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),k=(null===c||void 0===c?void 0:c.comment)===void 0?"":"".concat("".concat(j).concat(c.comment).split(/\r?\n/).join("\n".concat(j)),"\n"),l="".concat(k).concat(h).concat(e).concat(i).split(/\n/);// Allow multiline keys.
|
|
16
|
+
// Allow multiline values.
|
|
17
|
+
// Allow multiline comments.
|
|
18
|
+
if(void 0===f)return this.lines.push(...l),this.parseLines(),!0;else{// Find the last occurrence of the reference key.
|
|
19
|
+
const a=[...this.collection].reverse().find(a=>a.key===f);// Insert the new property when a reference key defined only when found.
|
|
20
|
+
if(a){var m,n;const b="after"===g?a.endingLineNumber:null!==(m=null===(n=a.previousProperty)||void 0===n?void 0:n.endingLineNumber)&&void 0!==m?m:0;return this.lines=[...this.lines.slice(0,b),...l,...this.lines.slice(b)],this.parseLines(),!0}return!1}}/**
|
|
21
|
+
* Insert a new comment in the existing object (by default it will be at the end).
|
|
22
|
+
*
|
|
23
|
+
* @param comment - The comment to add.
|
|
24
|
+
* @param options - Additional options.
|
|
25
|
+
*
|
|
26
|
+
* @returns True if the comment was inserted, otherwise false.
|
|
27
|
+
*/insertComment(a,b){const c=null===b||void 0===b?void 0:b.referenceKey,d=(null===b||void 0===b?void 0:b.position)||"after",e="".concat((null===b||void 0===b?void 0:b.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),f="".concat(e).concat(a).replaceAll(/\r?\n/g,"\n".concat(e)).split(/\n/);// Allow multiline comments.
|
|
28
|
+
if(void 0===c)return this.lines.push(...f),this.parseLines(),!0;else{// Find the last occurrence of the reference key.
|
|
29
|
+
const a=[...this.collection].reverse().find(a=>a.key===c);// Insert the new comment when a reference key defined only when found.
|
|
30
|
+
if(a){var g,h;const b="after"===d?a.endingLineNumber:null!==(g=null===(h=a.previousProperty)||void 0===h?void 0:h.endingLineNumber)&&void 0!==g?g:0;return this.lines=[...this.lines.slice(0,b),...f,...this.lines.slice(b)],this.parseLines(),!0}return!1}}/**
|
|
31
|
+
* Delete the last occurrence of a given key from the existing object.
|
|
32
|
+
*
|
|
33
|
+
* @param key - The name of the key to delete.
|
|
34
|
+
* @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
|
|
35
|
+
*
|
|
36
|
+
* @returns True if the key was deleted, otherwise false.
|
|
37
|
+
*/delete(a){let b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];// Find the last occurrence of the key.
|
|
38
|
+
const c=[...this.collection].reverse().find(b=>b.key===a);if(c){var d,e;const a=b?null!==(d=null===(e=c.previousProperty)||void 0===e?void 0:e.endingLineNumber)&&void 0!==d?d:0:c.startingLineNumber-1,f=c.endingLineNumber;return this.lines=[...this.lines.slice(0,a),...this.lines.slice(f)],this.parseLines(),!0}return!1}/**
|
|
39
|
+
* Restore the original newline characters of a key.
|
|
40
|
+
*
|
|
41
|
+
* @param property - A property object.
|
|
42
|
+
*
|
|
43
|
+
* @returns The key with its original newlines characters restored.
|
|
44
|
+
*/getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce
|
|
45
|
+
[...a.key].reduce((b,c,d)=>// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
46
|
+
"".concat(b).concat(a.newlinePositions.includes(d)?"\n":"").concat(c),"")}/**
|
|
47
|
+
* Restore the original newline characters of a value.
|
|
48
|
+
*
|
|
49
|
+
* @param property - A property object.
|
|
50
|
+
*
|
|
51
|
+
* @returns The value with its original newlines characters restored.
|
|
52
|
+
*/getValueWithNewlines(a){return 0===a.newlinePositions.length||a.valuePosition===void 0?a.value:// eslint-disable-next-line unicorn/no-array-reduce
|
|
53
|
+
[...a.value].reduce((b,c,d)=>"".concat(b).concat(a.newlinePositions.includes(d+a.valuePosition)?"\n":""// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
54
|
+
).concat(c),"")}/**
|
|
55
|
+
* Update the last occurrence of a given key from the existing object.
|
|
56
|
+
*
|
|
57
|
+
* @param key - The name of the key to update.
|
|
58
|
+
* @param options - Additional options.
|
|
59
|
+
*
|
|
60
|
+
* @returns True if the key was updated, otherwise false.
|
|
61
|
+
*/update(a,b){var c,d,e,f;// Find the last occurrence of the key to update.
|
|
62
|
+
const g=[...this.collection].reverse().find(b=>b.key===a);if(!g||!b)return!1;const h=b.escapeUnicode||!1,i=b.separator?" "===b.separator?" ":" ".concat(b.separator," "):g.separator||" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),j=(null!==(c=b.newKey)&&void 0!==c?c:this.getKeyWithNewlines(g)).split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,h)).join("\\\n"),k=(null!==(d=b.newValue)&&void 0!==d?d:this.getValueWithNewlines(g)).split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,h)).join("\\\n"),l="".concat(b.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),m=void 0===b.newComment?"":"".concat("".concat(l).concat(b.newComment).split(/\r?\n/).join("\n".concat(l)),"\n"),n="".concat(m).concat(j).concat(i).concat(k).split(/\n/);// Allow multiline keys.
|
|
63
|
+
// Allow multiline values.
|
|
64
|
+
// Allow multiline comments.
|
|
65
|
+
// Replace the existing property with the new one.
|
|
66
|
+
return this.lines=[...this.lines.slice(0,void 0===b.newComment?g.startingLineNumber-1:null!==(e=null===(f=g.previousProperty)||void 0===f?void 0:f.endingLineNumber)&&void 0!==e?e:0),...n,...this.lines.slice(g.endingLineNumber)],this.parseLines(),!0}/**
|
|
67
|
+
* Update a key if it exist, otherwise add it at the end.
|
|
68
|
+
*
|
|
69
|
+
* @param key - A property key (unescaped).
|
|
70
|
+
* @param value - A property value (unescaped).
|
|
71
|
+
* @param options - Additional options.
|
|
72
|
+
*
|
|
73
|
+
* @returns True if the key was updated or inserted, otherwise false.
|
|
74
|
+
*/upsert(a,b,c){return this.keyLineNumbers[a]?this.update(a,{newValue:b,newComment:null===c||void 0===c?void 0:c.comment,commentDelimiter:null===c||void 0===c?void 0:c.commentDelimiter,separator:null===c||void 0===c?void 0:c.separator,escapeUnicode:null===c||void 0===c?void 0:c.escapeUnicode}):this.insert(a,b,c)}}exports.PropertiesEditor=PropertiesEditor;
|
package/lib/escape/index.js
CHANGED
|
@@ -1,96 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* Escape
|
|
6
|
-
*
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @param
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return escapeContent(unescapedValue, false, escapeUnicode);
|
|
28
|
-
};
|
|
29
|
-
exports.escapeValue = escapeValue;
|
|
30
|
-
/**
|
|
31
|
-
* Escape the content from either key or value of a property.
|
|
32
|
-
*
|
|
33
|
-
* @param unescapedContent - The content to escape.
|
|
34
|
-
* @param escapeSpace - Escape spaces?
|
|
35
|
-
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
36
|
-
*
|
|
37
|
-
* @returns The unescaped content.
|
|
38
|
-
*/
|
|
39
|
-
var escapeContent = function (unescapedContent, escapeSpace, escapeUnicode) {
|
|
40
|
-
var escapedContent = '';
|
|
41
|
-
for (var character = unescapedContent[0], position = 0; position < unescapedContent.length; position++, character = unescapedContent[position]) {
|
|
42
|
-
switch (character) {
|
|
43
|
-
case ' ': {
|
|
44
|
-
// Escape space if required, or if it is first character.
|
|
45
|
-
escapedContent += escapeSpace || position === 0 ? '\\ ' : ' ';
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
// Backslash.
|
|
49
|
-
case '\\': {
|
|
50
|
-
escapedContent += '\\\\';
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
case '\f': {
|
|
54
|
-
// Formfeed.
|
|
55
|
-
escapedContent += '\\f';
|
|
56
|
-
break;
|
|
57
|
-
}
|
|
58
|
-
case '\n': {
|
|
59
|
-
// Newline.
|
|
60
|
-
escapedContent += '\\n';
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
case '\r': {
|
|
64
|
-
// Carriage return.
|
|
65
|
-
escapedContent += '\\r';
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
case '\t': {
|
|
69
|
-
// Tab.
|
|
70
|
-
escapedContent += '\\t';
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case '=':
|
|
74
|
-
case ':':
|
|
75
|
-
case '#':
|
|
76
|
-
case '!': {
|
|
77
|
-
// Escapes =, :, # and !.
|
|
78
|
-
escapedContent += "\\".concat(character);
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
default: {
|
|
82
|
-
if (escapeUnicode) {
|
|
83
|
-
var codePoint = character.codePointAt(0); // Can never be `undefined`.
|
|
84
|
-
if (codePoint < 0x0020 || codePoint > 0x007e) {
|
|
85
|
-
escapedContent += "\\u".concat(codePoint.toString(16).padStart(4, '0'));
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// Non-escapable characters.
|
|
90
|
-
escapedContent += character;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return escapedContent;
|
|
96
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeValue=exports.escapeKey=void 0;/**
|
|
2
|
+
* Escape a property key.
|
|
3
|
+
*
|
|
4
|
+
* @param unescapedKey - A property key to be escaped.
|
|
5
|
+
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
6
|
+
*
|
|
7
|
+
* @return The escaped key.
|
|
8
|
+
*/const escapeKey=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!0,b)};/**
|
|
9
|
+
* Escape property value.
|
|
10
|
+
*
|
|
11
|
+
* @param unescapedValue - Property value to be escaped.
|
|
12
|
+
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
13
|
+
*
|
|
14
|
+
* @return The escaped value.
|
|
15
|
+
*/exports.escapeKey=escapeKey;const escapeValue=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!1,b)};/**
|
|
16
|
+
* Escape the content from either key or value of a property.
|
|
17
|
+
*
|
|
18
|
+
* @param unescapedContent - The content to escape.
|
|
19
|
+
* @param escapeSpace - Escape spaces?
|
|
20
|
+
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
21
|
+
*
|
|
22
|
+
* @returns The unescaped content.
|
|
23
|
+
*/exports.escapeValue=escapeValue;const escapeContent=(a,b,c)=>{let d="";for(let e=a[0],f=0;f<a.length;f++,e=a[f])switch(e){case" ":{d+=b||0===f?"\\ ":" ";break}// Backslash.
|
|
24
|
+
case"\\":{d+="\\\\";break}case"\f":{d+="\\f";break}case"\n":{d+="\\n";break}case"\r":{d+="\\r";break}case"\t":{d+="\\t";break}case"=":case":":case"#":case"!":{d+="\\".concat(e);break}default:{if(c){const a=e.codePointAt(0);// Can never be `undefined`.
|
|
25
|
+
if(32>a||126<a){d+="\\u".concat(a.toString(16).padStart(4,"0"));break}}// Non-escapable characters.
|
|
26
|
+
d+=e;break}}return d};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
* @param content - The content of a `.properties` file.
|
|
11
|
-
*
|
|
12
|
-
* @returns A key/value object representing the content of a `.properties` file.
|
|
13
|
-
*/
|
|
14
|
-
var getProperties = function (content) {
|
|
15
|
-
return new properties_1.Properties(content).toObject();
|
|
16
|
-
};
|
|
17
|
-
exports.getProperties = getProperties;
|
|
1
|
+
"use strict";var _properties=require("./properties");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return _properties.Properties}}),exports.getProperties=void 0;/**
|
|
2
|
+
* A key-value pair object.
|
|
3
|
+
*/ /**
|
|
4
|
+
* Converts the content of a `.properties` file to a key-value pair object.
|
|
5
|
+
*
|
|
6
|
+
* @param content - The content of a `.properties` file.
|
|
7
|
+
*
|
|
8
|
+
* @returns A key/value object representing the content of a `.properties` file.
|
|
9
|
+
*/const getProperties=a=>new _properties.Properties(a).toObject();exports.getProperties=getProperties;
|
package/lib/loader/webpack.d.ts
CHANGED
package/lib/loader/webpack.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
*
|
|
9
|
-
* @returns A Webpack file loader string containing the content of a `.properties` file.
|
|
10
|
-
*/
|
|
11
|
-
var webpackLoader = function (content) {
|
|
12
|
-
return "module.exports = ".concat(JSON.stringify((0, __1.getProperties)(content)), ";");
|
|
13
|
-
};
|
|
14
|
-
exports.default = webpackLoader;
|
|
1
|
+
"use strict";var _=require("..");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/**
|
|
2
|
+
* Webpack file loader for `.properties` files.
|
|
3
|
+
*
|
|
4
|
+
* @param content - the content of a `.properties` file.
|
|
5
|
+
*
|
|
6
|
+
* @returns A Webpack file loader string containing the content of a `.properties` file.
|
|
7
|
+
*/const webpackLoader=a=>"module.exports = ".concat(JSON.stringify((0,_.getProperties)(a)),";");var _default=webpackLoader;exports.default=_default;
|
package/lib/properties.d.ts
CHANGED
package/lib/properties.js
CHANGED
|
@@ -1,218 +1,52 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
* A class representing the content of a .properties file.
|
|
54
|
-
*/
|
|
55
|
-
var Properties = /** @class */ (function () {
|
|
56
|
-
/**
|
|
57
|
-
* Create `Properties` object.
|
|
58
|
-
*
|
|
59
|
-
* @param content - The content of a `.properties` file.
|
|
60
|
-
*/
|
|
61
|
-
function Properties(content) {
|
|
62
|
-
var _a;
|
|
63
|
-
/** The collection of property object. */
|
|
64
|
-
this.collection = [];
|
|
65
|
-
/** Object associating keys with their starting line numbers. */
|
|
66
|
-
this.keyLineNumbers = {};
|
|
67
|
-
var stringContent = typeof content === 'string' ? content : content.toString();
|
|
68
|
-
this.hasBom = stringContent.codePointAt(0) === exports.BOM_CODE_POINT;
|
|
69
|
-
this.eolCharacter = (_a = (0, exports.getFirstEolCharacter)(stringContent)) !== null && _a !== void 0 ? _a : exports.DEFAULT_END_OF_LINE_CHARACTER;
|
|
70
|
-
this.lines = (this.hasBom ? stringContent.slice(1) : stringContent).split(/\r?\n/);
|
|
71
|
-
this.parseLines();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Parse the `.properties` content line by line.
|
|
75
|
-
*/
|
|
76
|
-
Properties.prototype.parseLines = function () {
|
|
77
|
-
var e_1, _a;
|
|
78
|
-
/** reset existing object properties to their initial values. */
|
|
79
|
-
this.collection = [];
|
|
80
|
-
this.keyLineNumbers = {};
|
|
81
|
-
/** Line number while parsing properties file content. */
|
|
82
|
-
var lineNumber = 0;
|
|
83
|
-
/** The current property object being parsed. */
|
|
84
|
-
var property;
|
|
85
|
-
/** The previous property object that was parsed. */
|
|
86
|
-
var previousProperty;
|
|
87
|
-
try {
|
|
88
|
-
for (var _b = __values(this.lines), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
89
|
-
var line = _c.value;
|
|
90
|
-
lineNumber++;
|
|
91
|
-
var propertyLine = new property_line_1.PropertyLine(line, !!property);
|
|
92
|
-
if (property) {
|
|
93
|
-
// Continue parsing an existing property.
|
|
94
|
-
property.addLine(propertyLine);
|
|
95
|
-
if (propertyLine.isContinuing) {
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
// Check if the line is a new property.
|
|
101
|
-
if (propertyLine.isComment || propertyLine.isBlank) {
|
|
102
|
-
continue; // Skip line if its a comment or blank.
|
|
103
|
-
}
|
|
104
|
-
// The line is a new property.
|
|
105
|
-
property = new property_1.Property(propertyLine, lineNumber, previousProperty);
|
|
106
|
-
if (propertyLine.isContinuing) {
|
|
107
|
-
continue; // Continue parsing the next line.
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
// If the line does not continue, add the property to the collection.
|
|
111
|
-
this.addToCollection(property);
|
|
112
|
-
previousProperty = property;
|
|
113
|
-
property = undefined;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
117
|
-
finally {
|
|
118
|
-
try {
|
|
119
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
120
|
-
}
|
|
121
|
-
finally { if (e_1) throw e_1.error; }
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Add a property object into a properties object collection.
|
|
126
|
-
*
|
|
127
|
-
* @param property - A property object, or undefined.
|
|
128
|
-
*
|
|
129
|
-
* @returns Undefined so that we conveniently overwrite the property object.
|
|
130
|
-
*/
|
|
131
|
-
Properties.prototype.addToCollection = function (property) {
|
|
132
|
-
var _a;
|
|
133
|
-
property.setKeyAndValue();
|
|
134
|
-
if ((_a = this.keyLineNumbers[property.key]) === null || _a === void 0 ? void 0 : _a.length) {
|
|
135
|
-
this.keyLineNumbers[property.key].push(property.startingLineNumber);
|
|
136
|
-
property.hasKeyCollisions = true;
|
|
137
|
-
property.keyCollisionLines = this.keyLineNumbers[property.key];
|
|
138
|
-
// Remove the collision from the collection (we only keep latest value).
|
|
139
|
-
this.collection = this.collection.filter(function (existingPropertyObject) { return existingPropertyObject.key !== property.key; });
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
// Initialize the key line numbers.
|
|
143
|
-
this.keyLineNumbers[property.key] = [property.startingLineNumber];
|
|
144
|
-
}
|
|
145
|
-
// Add the property to the collection.
|
|
146
|
-
this.collection.push(property);
|
|
147
|
-
};
|
|
148
|
-
/**
|
|
149
|
-
* Get keys that have collisions (more than one occurrence).
|
|
150
|
-
*/
|
|
151
|
-
Properties.prototype.getKeyCollisions = function () {
|
|
152
|
-
var e_2, _a;
|
|
153
|
-
var keyCollisions = [];
|
|
154
|
-
try {
|
|
155
|
-
for (var _b = __values(Object.entries(this.keyLineNumbers)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
156
|
-
var _d = __read(_c.value, 2), key = _d[0], startingLineNumbers = _d[1];
|
|
157
|
-
if (startingLineNumbers.length > 1) {
|
|
158
|
-
keyCollisions.push(new KeyCollisions(key, startingLineNumbers));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
163
|
-
finally {
|
|
164
|
-
try {
|
|
165
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
166
|
-
}
|
|
167
|
-
finally { if (e_2) throw e_2.error; }
|
|
168
|
-
}
|
|
169
|
-
return keyCollisions;
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Get the key/value object representing the properties.
|
|
173
|
-
*
|
|
174
|
-
* @returns A key/value object representing the properties.
|
|
175
|
-
*/
|
|
176
|
-
Properties.prototype.toObject = function () {
|
|
177
|
-
var keyValueObject = {};
|
|
178
|
-
this.collection.forEach(function (property) {
|
|
179
|
-
keyValueObject[property.key] = property.value;
|
|
180
|
-
});
|
|
181
|
-
return keyValueObject;
|
|
182
|
-
};
|
|
183
|
-
/**
|
|
184
|
-
* Format the object in `.properties`.
|
|
185
|
-
*
|
|
186
|
-
* @param endOfLineCharacter - The character used for end of lines.
|
|
187
|
-
*
|
|
188
|
-
* @returns The object in `.properties` format.
|
|
189
|
-
*/
|
|
190
|
-
Properties.prototype.format = function (endOfLineCharacter) {
|
|
191
|
-
return "".concat(this.hasBom ? exports.BOM : '').concat(this.lines.join(endOfLineCharacter || this.eolCharacter));
|
|
192
|
-
};
|
|
193
|
-
return Properties;
|
|
194
|
-
}());
|
|
195
|
-
exports.Properties = Properties;
|
|
196
|
-
/**
|
|
197
|
-
* A class representing key within a .properties file that had collisions (more than one occurrence).
|
|
198
|
-
*/
|
|
199
|
-
var KeyCollisions = /** @class */ (function () {
|
|
200
|
-
/**
|
|
201
|
-
* Create a new key collision object.
|
|
202
|
-
*
|
|
203
|
-
* @param key - The key with collisions.
|
|
204
|
-
* @param startingLineNumbers - The starting line numbers where collisions are found.
|
|
205
|
-
*/
|
|
206
|
-
function KeyCollisions(key, startingLineNumbers) {
|
|
207
|
-
this.key = key;
|
|
208
|
-
this.startingLineNumbers = startingLineNumbers;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Get the number of the line from which the value will be used.
|
|
212
|
-
*/
|
|
213
|
-
KeyCollisions.prototype.getApplicableLineNumber = function () {
|
|
214
|
-
return this.startingLineNumbers.slice(-1)[0];
|
|
215
|
-
};
|
|
216
|
-
return KeyCollisions;
|
|
217
|
-
}());
|
|
218
|
-
exports.KeyCollisions = KeyCollisions;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getFirstEolCharacter=exports.Properties=exports.KeyCollisions=exports.DEFAULT_END_OF_LINE_CHARACTER=exports.BOM_CODE_POINT=exports.BOM=void 0,require("core-js/modules/web.dom-collections.iterator.js"),require("core-js/modules/esnext.string.at.js");var _property=require("./property"),_propertyLine=require("./property-line");function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/**
|
|
2
|
+
* Byte-order mark.
|
|
3
|
+
*/const BOM="\uFEFF";exports.BOM="\uFEFF";const BOM_CODE_POINT="\uFEFF".codePointAt(0);/** The default end of line character. */exports.BOM_CODE_POINT=65279;const DEFAULT_END_OF_LINE_CHARACTER="\n";/**
|
|
4
|
+
* Get the first end of line (EOL) character from multiline content.
|
|
5
|
+
*
|
|
6
|
+
* @param content - The content of a `.properties` file.
|
|
7
|
+
*
|
|
8
|
+
* @returns The multiline content's first end of line (EOL) character.
|
|
9
|
+
*/exports.DEFAULT_END_OF_LINE_CHARACTER="\n";const getFirstEolCharacter=a=>{const b=a.indexOf("\n");return 0>b?void 0:"".concat("\r"===a[b-1]?"\r":"","\n")};/**
|
|
10
|
+
* A class representing the content of a .properties file.
|
|
11
|
+
*/exports.getFirstEolCharacter=getFirstEolCharacter;class Properties{/**
|
|
12
|
+
* Create `Properties` object.
|
|
13
|
+
*
|
|
14
|
+
* @param content - The content of a `.properties` file.
|
|
15
|
+
*/constructor(a){var b;_defineProperty(this,"collection",[]),_defineProperty(this,"keyLineNumbers",{});const c="string"==typeof a?a:a.toString();this.hasBom=c.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=null!==(b=getFirstEolCharacter(c))&&void 0!==b?b:DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?c.slice(1):c).split(/\r?\n/),this.parseLines()}/**
|
|
16
|
+
* Parse the `.properties` content line by line.
|
|
17
|
+
*/parseLines(){this.collection=[],this.keyLineNumbers={};/** Line number while parsing properties file content. */let a,b,c=0;/** The current property object being parsed. */ /** The previous property object that was parsed. */for(const d of this.lines){c++;const e=new _propertyLine.PropertyLine(d,!!a);if(!a){// Check if the line is a new property.
|
|
18
|
+
if(e.isComment||e.isBlank)continue;// Skip line if its a comment or blank.
|
|
19
|
+
// The line is a new property.
|
|
20
|
+
if(a=new _property.Property(e,c,b),e.isContinuing)continue;// Continue parsing the next line.
|
|
21
|
+
}else if(a.addLine(e),e.isContinuing)continue;// If the line does not continue, add the property to the collection.
|
|
22
|
+
this.addToCollection(a),b=a,a=void 0}}/**
|
|
23
|
+
* Add a property object into a properties object collection.
|
|
24
|
+
*
|
|
25
|
+
* @param property - A property object, or undefined.
|
|
26
|
+
*
|
|
27
|
+
* @returns Undefined so that we conveniently overwrite the property object.
|
|
28
|
+
*/addToCollection(a){var b;// Add the property to the collection.
|
|
29
|
+
a.setKeyAndValue(),null!==(b=this.keyLineNumbers[a.key])&&void 0!==b&&b.length?(this.keyLineNumbers[a.key].push(a.startingLineNumber),a.hasKeyCollisions=!0,a.keyCollisionLines=this.keyLineNumbers[a.key],this.collection=this.collection.filter(b=>b.key!==a.key)):this.keyLineNumbers[a.key]=[a.startingLineNumber],this.collection.push(a)}/**
|
|
30
|
+
* Get keys that have collisions (more than one occurrence).
|
|
31
|
+
*/getKeyCollisions(){const a=[];for(const[b,c]of Object.entries(this.keyLineNumbers))1<c.length&&a.push(new KeyCollisions(b,c));return a}/**
|
|
32
|
+
* Get the key/value object representing the properties.
|
|
33
|
+
*
|
|
34
|
+
* @returns A key/value object representing the properties.
|
|
35
|
+
*/toObject(){const a={};return this.collection.forEach(b=>{a[b.key]=b.value}),a}/**
|
|
36
|
+
* Format the object in `.properties`.
|
|
37
|
+
*
|
|
38
|
+
* @param endOfLineCharacter - The character used for end of lines.
|
|
39
|
+
*
|
|
40
|
+
* @returns The object in `.properties` format.
|
|
41
|
+
*/format(a){return"".concat(this.hasBom?BOM:"").concat(this.lines.join(a||this.eolCharacter))}}/**
|
|
42
|
+
* Object associating keys with their line numbers.
|
|
43
|
+
*/exports.Properties=Properties;/**
|
|
44
|
+
* A class representing key within a .properties file that had collisions (more than one occurrence).
|
|
45
|
+
*/class KeyCollisions{/** The key with collisions. */ /** The starting line numbers where collisions are found. */ /**
|
|
46
|
+
* Create a new key collision object.
|
|
47
|
+
*
|
|
48
|
+
* @param key - The key with collisions.
|
|
49
|
+
* @param startingLineNumbers - The starting line numbers where collisions are found.
|
|
50
|
+
*/constructor(a,b){this.key=a,this.startingLineNumbers=b}/**
|
|
51
|
+
* Get the number of the line from which the value will be used.
|
|
52
|
+
*/getApplicableLineNumber(){return this.startingLineNumbers.at(-1)}}exports.KeyCollisions=KeyCollisions;
|
package/lib/property-line.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
* @param line - The raw content of a line.
|
|
12
|
-
* @param isMultiline - Is the line spreading on multiple lines?
|
|
13
|
-
*/
|
|
14
|
-
function PropertyLine(line, isMultiline) {
|
|
15
|
-
/** True if the line is continuing to the next line, otherwise false. */
|
|
16
|
-
this.isContinuing = false;
|
|
17
|
-
/** True if the line is blank, otherwise false. */
|
|
18
|
-
this.isBlank = false;
|
|
19
|
-
/** True if the line is a comment, otherwise false. */
|
|
20
|
-
this.isComment = false;
|
|
21
|
-
this.content = line.trimStart();
|
|
22
|
-
this.isMultiline = isMultiline;
|
|
23
|
-
if (this.content.length === 0) {
|
|
24
|
-
// Line is blank.
|
|
25
|
-
this.isBlank = true;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
if (!this.isMultiline) {
|
|
29
|
-
// Line is a comment.
|
|
30
|
-
this.isComment = !!/^[!#]/.test(this.content);
|
|
31
|
-
}
|
|
32
|
-
if (!this.isComment) {
|
|
33
|
-
// Otherwise, check if the line is continuing on the next line.
|
|
34
|
-
var backslashMatch = this.content.match(/(?<backslashes>\\+)$/);
|
|
35
|
-
if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) {
|
|
36
|
-
// If the number of backslashes is odd, the line is continuing, otherwise it doesn't.
|
|
37
|
-
this.isContinuing = !!(backslashMatch.groups.backslashes.length % 2);
|
|
38
|
-
if (this.isContinuing) {
|
|
39
|
-
// Remove the trailing slash so that we can concatenate the line with the next one.
|
|
40
|
-
this.content = this.content.slice(0, -1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return PropertyLine;
|
|
47
|
-
}());
|
|
48
|
-
exports.PropertyLine = PropertyLine;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/**
|
|
2
|
+
* Object representing a line from the content of .properties file.
|
|
3
|
+
*/class PropertyLine{/** Is the line object a continuation from a previous line? */ /**
|
|
4
|
+
* Create a new line object.
|
|
5
|
+
*
|
|
6
|
+
* @param line - The raw content of a line.
|
|
7
|
+
* @param isMultiline - Is the line spreading on multiple lines?
|
|
8
|
+
*/constructor(a,b){if(_defineProperty(this,"isContinuing",!1),_defineProperty(this,"isBlank",!1),_defineProperty(this,"isComment",!1),this.content=a.trimStart(),this.isMultiline=b,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=!!/^[!#]/.test(this.content)),!this.isComment){// Otherwise, check if the line is continuing on the next line.
|
|
9
|
+
const a=this.content.match(/(?<backslashes>\\+)$/);null!==a&&void 0!==a&&a.groups&&(this.isContinuing=!!(a.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}}}exports.PropertyLine=PropertyLine;
|
package/lib/property.js
CHANGED
|
@@ -1,171 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.previousProperty = previousProperty;
|
|
40
|
-
previousProperty === null || previousProperty === void 0 ? void 0 : previousProperty.setNextProperty(this);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Set the next property object.
|
|
44
|
-
*
|
|
45
|
-
* @param property - The next property object
|
|
46
|
-
*/
|
|
47
|
-
Property.prototype.setNextProperty = function (property) {
|
|
48
|
-
this.nextProperty = property;
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Add the a line to a multiline property object.
|
|
52
|
-
*
|
|
53
|
-
* @param propertyLine - A property line object.
|
|
54
|
-
*/
|
|
55
|
-
Property.prototype.addLine = function (propertyLine) {
|
|
56
|
-
if (this.linesContent.length > 0) {
|
|
57
|
-
this.newlinePositions.push(this.linesContent.length);
|
|
58
|
-
this.endingLineNumber++;
|
|
59
|
-
}
|
|
60
|
-
this.linesContent += propertyLine.content;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Set the property's key and value.
|
|
64
|
-
*/
|
|
65
|
-
Property.prototype.setKeyAndValue = function () {
|
|
66
|
-
this.findSeparator();
|
|
67
|
-
if (this.separatorPosition !== undefined && this.separatorLength !== undefined) {
|
|
68
|
-
// Set key if present.
|
|
69
|
-
if (!this.hasNoKey) {
|
|
70
|
-
this.escapedKey = this.linesContent.slice(0, this.separatorPosition);
|
|
71
|
-
this.key = this.unescapeLine(this.escapedKey, this.startingLineNumber);
|
|
72
|
-
}
|
|
73
|
-
// Set value if present.
|
|
74
|
-
if (!this.hasNoValue) {
|
|
75
|
-
this.escapedValue = this.linesContent.slice(this.separatorPosition + this.separatorLength);
|
|
76
|
-
this.value = this.unescapeLine(this.escapedValue, this.startingLineNumber);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
else if (this.hasNoValue) {
|
|
80
|
-
// Set key if present (no separator).
|
|
81
|
-
this.escapedKey = this.linesContent;
|
|
82
|
-
this.key = this.unescapeLine(this.escapedKey, this.startingLineNumber);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* Unescape the content from either key or value of a property.
|
|
87
|
-
*
|
|
88
|
-
* @param escapedContent - The content to unescape.
|
|
89
|
-
* @param startingLineNumber - The starting line number of the content being unescaped.
|
|
90
|
-
*
|
|
91
|
-
* @returns The unescaped content.
|
|
92
|
-
*
|
|
93
|
-
* @throws {@link Error}
|
|
94
|
-
* This exception is thrown if malformed escaped unicode characters are present.
|
|
95
|
-
*/
|
|
96
|
-
Property.prototype.unescapeLine = function (escapedContent, startingLineNumber) {
|
|
97
|
-
try {
|
|
98
|
-
return (0, unescape_1.unescapeContent)(escapedContent);
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
101
|
-
throw new Error("".concat(error.message, " in property starting at line ").concat(startingLineNumber));
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Find the character separating the key from the value.
|
|
106
|
-
*/
|
|
107
|
-
Property.prototype.findSeparator = function () {
|
|
108
|
-
var _a, _b;
|
|
109
|
-
// If the separator was already found, skip.
|
|
110
|
-
if (this.hasNoKey || this.hasNoValue || this.separatorPosition) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
for (var character = this.linesContent[0], position = 0; position < this.linesContent.length; position++, character = this.linesContent[position]) {
|
|
114
|
-
// If the character is not a separator, check the next one.
|
|
115
|
-
if (!/[\t\f :=]/.test(character)) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
// Check if the separator might be escaped.
|
|
119
|
-
var prefix = position ? this.linesContent.slice(0, position) : '';
|
|
120
|
-
if (prefix.length > 0) {
|
|
121
|
-
var backslashMatch = prefix.match(/(?<backslashes>\\+)$/);
|
|
122
|
-
if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) {
|
|
123
|
-
var separatorIsEscaped = !!(backslashMatch.groups.backslashes.length % 2);
|
|
124
|
-
if (separatorIsEscaped) {
|
|
125
|
-
// If the separator is escaped, check the next character.
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
var separator = '';
|
|
131
|
-
this.separatorPosition = position;
|
|
132
|
-
// Check if the separator starts with a whitespace.
|
|
133
|
-
var nextContent = this.linesContent.slice(position);
|
|
134
|
-
var leadingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/);
|
|
135
|
-
var leadingWhitespace = ((_a = leadingWhitespaceMatch === null || leadingWhitespaceMatch === void 0 ? void 0 : leadingWhitespaceMatch.groups) === null || _a === void 0 ? void 0 : _a.whitespace) || '';
|
|
136
|
-
// If there is a whitespace, move to the next character.
|
|
137
|
-
if (leadingWhitespace.length > 0) {
|
|
138
|
-
separator += leadingWhitespace;
|
|
139
|
-
nextContent = nextContent.slice(leadingWhitespace.length);
|
|
140
|
-
}
|
|
141
|
-
// Check if there is an equal or colon character.
|
|
142
|
-
if (/[:=]/.test(nextContent[0])) {
|
|
143
|
-
separator += nextContent[0];
|
|
144
|
-
nextContent = nextContent.slice(1);
|
|
145
|
-
// If an equal or colon character was found, try to get trailing whitespace.
|
|
146
|
-
var trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/);
|
|
147
|
-
var trailingWhitespace = ((_b = trailingWhitespaceMatch === null || trailingWhitespaceMatch === void 0 ? void 0 : trailingWhitespaceMatch.groups) === null || _b === void 0 ? void 0 : _b.whitespace) || '';
|
|
148
|
-
separator += trailingWhitespace;
|
|
149
|
-
}
|
|
150
|
-
this.separatorLength = separator.length;
|
|
151
|
-
this.valuePosition = this.separatorPosition + this.separatorLength;
|
|
152
|
-
this.separator = this.linesContent.slice(this.separatorPosition, this.separatorPosition + this.separatorLength);
|
|
153
|
-
// If the line starts with a separator, the property has no key.
|
|
154
|
-
if (!position) {
|
|
155
|
-
this.hasNoKey = true;
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
}
|
|
159
|
-
if (this.separatorPosition === undefined) {
|
|
160
|
-
// If there was no separator found, the property has no value.
|
|
161
|
-
this.hasNoValue = true;
|
|
162
|
-
}
|
|
163
|
-
else if (this.newlinePositions.length > 0 &&
|
|
164
|
-
this.newlinePositions[0] < this.separatorPosition) {
|
|
165
|
-
// If the separator is after the first newline, the key is on multiple lines.
|
|
166
|
-
this.hasMultilineKey = true;
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
return Property;
|
|
170
|
-
}());
|
|
171
|
-
exports.Property = Property;
|
|
1
|
+
"use strict";var _unescape=require("./unescape");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;function _defineProperty(a,b,c){return b=_toPropertyKey(b),b in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function _toPropertyKey(a){var b=_toPrimitive(a,"string");return"symbol"==typeof b?b:b+""}function _toPrimitive(a,b){if("object"!=typeof a||null===a)return a;var c=a[Symbol.toPrimitive];if(c!==void 0){var d=c.call(a,b||"default");if("object"!=typeof d)return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}/**
|
|
2
|
+
* Object representing a property (key/value).
|
|
3
|
+
*/class Property{/** The line number at which the property starts. */ /** The line number at which the property ends. */ /** The previous property object if it exists. */ /** The next property object if it exists. */ /**
|
|
4
|
+
* Create a new property object.
|
|
5
|
+
*
|
|
6
|
+
* @param propertyLine - A property line object.
|
|
7
|
+
* @param startingLineNumber - The line number at which the property starts.
|
|
8
|
+
*/constructor(a,b,c){/** The content of one or multiple lines when applicable. */ /** The property key (unescaped). */ /** The property key, including its escaped characters. */ /** Is the key empty? */ /** Does the key definition spread across multiple lines? */ /** Starting line numbers of property objects with the same key. */ /** Was the property's key used more than once? */ /** The property value (unescaped). */ /** The property value, including its escaped characters. */ /** Is the value empty? */ /** Positions of the newline characters if any. */_defineProperty(this,"key",""),_defineProperty(this,"escapedKey",""),_defineProperty(this,"hasNoKey",!1),_defineProperty(this,"hasMultilineKey",!1),_defineProperty(this,"keyCollisionLines",[]),_defineProperty(this,"hasKeyCollisions",!1),_defineProperty(this,"value",""),_defineProperty(this,"escapedValue",""),_defineProperty(this,"hasNoValue",!1),_defineProperty(this,"newlinePositions",[]),this.linesContent=a.content,this.startingLineNumber=b,this.endingLineNumber=b,this.previousProperty=c,null===c||void 0===c?void 0:c.setNextProperty(this)}/**
|
|
9
|
+
* Set the next property object.
|
|
10
|
+
*
|
|
11
|
+
* @param property - The next property object
|
|
12
|
+
*/setNextProperty(a){this.nextProperty=a}/**
|
|
13
|
+
* Add the a line to a multiline property object.
|
|
14
|
+
*
|
|
15
|
+
* @param propertyLine - A property line object.
|
|
16
|
+
*/addLine(a){0<this.linesContent.length&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=a.content}/**
|
|
17
|
+
* Set the property's key and value.
|
|
18
|
+
*/setKeyAndValue(){this.findSeparator(),this.separatorPosition!==void 0&&this.separatorLength!==void 0?(!this.hasNoKey&&(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),!this.hasNoValue&&(this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber))):this.hasNoValue&&(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))}/**
|
|
19
|
+
* Unescape the content from either key or value of a property.
|
|
20
|
+
*
|
|
21
|
+
* @param escapedContent - The content to unescape.
|
|
22
|
+
* @param startingLineNumber - The starting line number of the content being unescaped.
|
|
23
|
+
*
|
|
24
|
+
* @returns The unescaped content.
|
|
25
|
+
*
|
|
26
|
+
* @throws {@link Error}
|
|
27
|
+
* This exception is thrown if malformed escaped unicode characters are present.
|
|
28
|
+
*/unescapeLine(a,b){try{return(0,_unescape.unescapeContent)(a)}catch(a){throw new Error("".concat(a.message," in property starting at line ").concat(b))}}/**
|
|
29
|
+
* Find the character separating the key from the value.
|
|
30
|
+
*/findSeparator(){// If the separator was already found, skip.
|
|
31
|
+
if(!(this.hasNoKey||this.hasNoValue||this.separatorPosition)){for(let c=this.linesContent[0],d=0;d<this.linesContent.length;d++,c=this.linesContent[d]){var a;// If the character is not a separator, check the next one.
|
|
32
|
+
if(!/[\t\f :=]/.test(c))continue;// Check if the separator might be escaped.
|
|
33
|
+
const e=d?this.linesContent.slice(0,d):"";if(0<e.length){const a=e.match(/(?<backslashes>\\+)$/);if(null!==a&&void 0!==a&&a.groups){const b=!!(a.groups.backslashes.length%2);if(b)// If the separator is escaped, check the next character.
|
|
34
|
+
continue}}let f="";this.separatorPosition=d;// Check if the separator starts with a whitespace.
|
|
35
|
+
let g=this.linesContent.slice(d);const h=g.match(/^(?<whitespace>\s+)/),i=(null===h||void 0===h||null===(a=h.groups)||void 0===a?void 0:a.whitespace)||"";// If there is a whitespace, move to the next character.
|
|
36
|
+
// Check if there is an equal or colon character.
|
|
37
|
+
if(0<i.length&&(f+=i,g=g.slice(i.length)),/[:=]/.test(g[0])){var b;f+=g[0],g=g.slice(1);// If an equal or colon character was found, try to get trailing whitespace.
|
|
38
|
+
const a=g.match(/^(?<whitespace>\s+)/),c=(null===a||void 0===a||null===(b=a.groups)||void 0===b?void 0:b.whitespace)||"";f+=c}this.separatorLength=f.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),d||(this.hasNoKey=!0);break}void 0===this.separatorPosition?this.hasNoValue=!0:0<this.newlinePositions.length&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}}}exports.Property=Property;
|
package/lib/unescape/index.js
CHANGED
|
@@ -1,69 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var unescapeContent = function (escapedContent) {
|
|
15
|
-
var unescapedContent = '';
|
|
16
|
-
for (var character = escapedContent[0], position = 0; position < escapedContent.length; position++, character = escapedContent[position]) {
|
|
17
|
-
if (character === '\\') {
|
|
18
|
-
var nextCharacter = escapedContent[position + 1];
|
|
19
|
-
switch (nextCharacter) {
|
|
20
|
-
case 'f': {
|
|
21
|
-
// Formfeed.
|
|
22
|
-
unescapedContent += '\f';
|
|
23
|
-
position++;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
case 'n': {
|
|
27
|
-
// Newline.
|
|
28
|
-
unescapedContent += '\n';
|
|
29
|
-
position++;
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
case 'r': {
|
|
33
|
-
// Carriage return.
|
|
34
|
-
unescapedContent += '\r';
|
|
35
|
-
position++;
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
case 't': {
|
|
39
|
-
// Tab.
|
|
40
|
-
unescapedContent += '\t';
|
|
41
|
-
position++;
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
case 'u': {
|
|
45
|
-
// Unicode character.
|
|
46
|
-
var codePoint = escapedContent.slice(position + 2, position + 6);
|
|
47
|
-
if (!/[\da-f]{4}/i.test(codePoint)) {
|
|
48
|
-
// Code point can only be within Unicode's Multilingual Plane (BMP).
|
|
49
|
-
throw new Error("malformed escaped unicode characters '\\u".concat(codePoint, "'"));
|
|
50
|
-
}
|
|
51
|
-
unescapedContent += String.fromCodePoint(Number.parseInt(codePoint, 16));
|
|
52
|
-
position += 5;
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
default: {
|
|
56
|
-
// Otherwise the escape character is not required.
|
|
57
|
-
unescapedContent += nextCharacter;
|
|
58
|
-
position++;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
// When there is \, simply add the character.
|
|
64
|
-
unescapedContent += character;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return unescapedContent;
|
|
68
|
-
};
|
|
69
|
-
exports.unescapeContent = unescapeContent;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unescapeContent=void 0;/**
|
|
2
|
+
* Unescape the content from either key or value of a property.
|
|
3
|
+
*
|
|
4
|
+
* @param escapedContent - The content to unescape.
|
|
5
|
+
*
|
|
6
|
+
* @returns The unescaped content.
|
|
7
|
+
*
|
|
8
|
+
* @throws {@link Error}
|
|
9
|
+
* This exception is thrown if malformed escaped unicode characters are present.
|
|
10
|
+
*/const unescapeContent=a=>{let b="";for(let c=a[0],d=0;d<a.length;d++,c=a[d])if("\\"===c){const c=a[d+1];switch(c){case"f":{b+="\f",d++;break}case"n":{b+="\n",d++;break}case"r":{b+="\r",d++;break}case"t":{b+="\t",d++;break}case"u":{// Unicode character.
|
|
11
|
+
const c=a.slice(d+2,d+6);if(!/[\da-f]{4}/i.test(c))// Code point can only be within Unicode's Multilingual Plane (BMP).
|
|
12
|
+
throw new Error("malformed escaped unicode characters '\\u".concat(c,"'"));b+=String.fromCodePoint(Number.parseInt(c,16)),d+=5;break}default:b+=c,d++}}else// When there is \, simply add the character.
|
|
13
|
+
b+=c;return b};exports.unescapeContent=unescapeContent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "properties-file",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": ".properties file parser, editor, formatter and Webpack loader.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
".properties",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
],
|
|
54
54
|
"scripts": {
|
|
55
55
|
"add-import-type": "ts-node ./src/add-import-type.ts && rm -f ./lib/add-import-type.*",
|
|
56
|
-
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run add-import-type && npm run test",
|
|
56
|
+
"build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && babel --config-file ./.babelrc --extensions .ts src -d lib && tsc && npm run add-import-type && npm run test",
|
|
57
57
|
"ci": "npm run build",
|
|
58
58
|
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .",
|
|
59
59
|
"lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json --fix .",
|
|
@@ -63,27 +63,32 @@
|
|
|
63
63
|
"test": "jest --coverage"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
+
"@babel/cli": "^7.21.5",
|
|
67
|
+
"@babel/core": "^7.21.8",
|
|
68
|
+
"@babel/preset-env": "^7.21.5",
|
|
69
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
66
70
|
"@release-it/conventional-changelog": "5.1.1",
|
|
67
71
|
"@types/jest": "29.5.1",
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "5.59.
|
|
69
|
-
"@typescript-eslint/parser": "5.59.
|
|
72
|
+
"@typescript-eslint/eslint-plugin": "5.59.2",
|
|
73
|
+
"@typescript-eslint/parser": "5.59.2",
|
|
74
|
+
"babel-preset-minify": "^0.5.2",
|
|
70
75
|
"dotenv-cli": "7.2.1",
|
|
71
|
-
"eslint": "8.
|
|
76
|
+
"eslint": "8.40.0",
|
|
72
77
|
"eslint-config-prettier": "8.8.0",
|
|
73
78
|
"eslint-import-resolver-node": "0.3.7",
|
|
74
79
|
"eslint-import-resolver-typescript": "3.5.5",
|
|
75
80
|
"eslint-plugin-import": "2.27.5",
|
|
76
81
|
"eslint-plugin-jest": "27.2.1",
|
|
77
|
-
"eslint-plugin-json-files": "2.
|
|
82
|
+
"eslint-plugin-json-files": "2.2.0",
|
|
78
83
|
"eslint-plugin-prefer-arrow-functions": "3.1.4",
|
|
79
84
|
"eslint-plugin-prettier": "4.2.1",
|
|
80
85
|
"eslint-plugin-tsdoc": "0.2.17",
|
|
81
|
-
"eslint-plugin-unicorn": "
|
|
86
|
+
"eslint-plugin-unicorn": "47.0.0",
|
|
82
87
|
"jest": "29.5.0",
|
|
83
88
|
"prettier": "2.8.8",
|
|
84
89
|
"prettier-plugin-organize-imports": "3.2.2",
|
|
85
90
|
"prettier-plugin-sh": "0.12.8",
|
|
86
|
-
"release-it": "15.10.
|
|
91
|
+
"release-it": "15.10.3",
|
|
87
92
|
"ts-jest": "29.1.0",
|
|
88
93
|
"ts-node": "10.9.1",
|
|
89
94
|
"typescript": "5.0.4"
|