properties-file 3.1.0 → 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/README.md +5 -2
- 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/README.md
CHANGED
|
@@ -168,13 +168,16 @@ properties.insert('newKey2', 'こんにちは', {
|
|
|
168
168
|
})
|
|
169
169
|
|
|
170
170
|
properties.delete('hello')
|
|
171
|
+
properties.update('world', {
|
|
172
|
+
newValue: 'new world',
|
|
173
|
+
})
|
|
171
174
|
console.log(properties.format())
|
|
172
175
|
|
|
173
176
|
/**
|
|
174
177
|
* Outputs:
|
|
175
178
|
*
|
|
176
179
|
* # This is a comment
|
|
177
|
-
* world = world
|
|
180
|
+
* world = new world
|
|
178
181
|
* ! Below are the new keys being edited
|
|
179
182
|
* newKey1 = This is my first new key
|
|
180
183
|
* newKey2 = \u3053\u3093\u306b\u3061\u306f
|
|
@@ -184,7 +187,7 @@ console.log(properties.format())
|
|
|
184
187
|
*/
|
|
185
188
|
```
|
|
186
189
|
|
|
187
|
-
|
|
190
|
+
For convenience, we also added an `upsert` method that allows updating a key if it exists or adding it at the end, when it doesn't. Make sure to check in your IDE for all available methods and options in our TSDoc.
|
|
188
191
|
|
|
189
192
|
### Webpack File Loader
|
|
190
193
|
|
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