properties-file 3.1.1 → 3.2.1

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.
@@ -1,286 +1,75 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __read = (this && this.__read) || function (o, n) {
18
- var m = typeof Symbol === "function" && o[Symbol.iterator];
19
- if (!m) return o;
20
- var i = m.call(o), r, ar = [], e;
21
- try {
22
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
- }
24
- catch (error) { e = { error: error }; }
25
- finally {
26
- try {
27
- if (r && !r.done && (m = i["return"])) m.call(i);
28
- }
29
- finally { if (e) throw e.error; }
30
- }
31
- return ar;
32
- };
33
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
- if (ar || !(i in from)) {
36
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
- ar[i] = from[i];
38
- }
39
- }
40
- return to.concat(ar || Array.prototype.slice.call(from));
41
- };
42
- Object.defineProperty(exports, "__esModule", { value: true });
43
- exports.PropertiesEditor = exports.DEFAULT_COMMENT_DELIMITER = exports.DEFAULT_SEPARATOR = void 0;
44
- var escape_1 = require("../escape");
45
- var properties_1 = require("../properties");
46
- /** The default separator between keys and values. */
47
- exports.DEFAULT_SEPARATOR = '=';
48
- /** The default character used as comment delimiter. */
49
- exports.DEFAULT_COMMENT_DELIMITER = '#';
50
- /**
51
- * A .properties file editor.
52
- */
53
- var PropertiesEditor = /** @class */ (function (_super) {
54
- __extends(PropertiesEditor, _super);
55
- /**
56
- * Create `PropertiesEditor` object.
57
- *
58
- * @param content - The content of a `.properties` file.
59
- */
60
- function PropertiesEditor(content) {
61
- return _super.call(this, content) || this;
62
- }
63
- /**
64
- * Insert a new property in the existing object (by default it will be at the end).
65
- *
66
- * @param key - A property key (unescaped).
67
- * @param value - A property value (unescaped).
68
- * @param options - Additional options.
69
- *
70
- * @returns True if the key was inserted, otherwise false.
71
- */
72
- PropertiesEditor.prototype.insert = function (key, value, options) {
73
- var _a;
74
- var _b, _c;
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;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)// eslint-disable-next-line unicorn/prefer-string-replace-all
28
+ .replace(/\r?\n/g,"\n".concat(e)).split(/\n/);// Allow multiline comments.
29
+ if(void 0===c)return this.lines.push(...f),this.parseLines(),!0;else{// Find the last occurrence of the reference key.
30
+ const a=[...this.collection].reverse().find(a=>a.key===c);// Insert the new comment when a reference key defined only when found.
31
+ 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}}/**
32
+ * Delete the last occurrence of a given key from the existing object.
33
+ *
34
+ * @param key - The name of the key to delete.
35
+ * @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
36
+ *
37
+ * @returns True if the key was deleted, otherwise false.
38
+ */delete(a){let b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];// Find the last occurrence of the key.
39
+ 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}/**
40
+ * Restore the original newline characters of a key.
41
+ *
42
+ * @param property - A property object.
43
+ *
44
+ * @returns The key with its original newlines characters restored.
45
+ */getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce
46
+ [...a.key].reduce((b,c,d)=>// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
47
+ "".concat(b).concat(a.newlinePositions.includes(d)?"\n":"").concat(c),"")}/**
48
+ * Restore the original newline characters of a value.
49
+ *
50
+ * @param property - A property object.
51
+ *
52
+ * @returns The value with its original newlines characters restored.
53
+ */getValueWithNewlines(a){return 0===a.newlinePositions.length||a.valuePosition===void 0?a.value:// eslint-disable-next-line unicorn/no-array-reduce
54
+ [...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
55
+ ).concat(c),"")}/**
56
+ * Update the last occurrence of a given key from the existing object.
57
+ *
58
+ * @param key - The name of the key to update.
59
+ * @param options - Additional options.
60
+ *
61
+ * @returns True if the key was updated, otherwise false.
62
+ */update(a,b){var c,d,e,f;// Find the last occurrence of the key to update.
63
+ 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.
64
+ // Allow multiline values.
65
+ // Allow multiline comments.
66
+ // Replace the existing property with the new one.
67
+ 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}/**
68
+ * Update a key if it exist, otherwise add it at the end.
69
+ *
70
+ * @param key - A property key (unescaped).
71
+ * @param value - A property value (unescaped).
72
+ * @param options - Additional options.
73
+ *
74
+ * @returns True if the key was updated or inserted, otherwise false.
75
+ */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;
@@ -1,96 +1,26 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.escapeValue = exports.escapeKey = void 0;
4
- /**
5
- * Escape a property key.
6
- *
7
- * @param unescapedKey - A property key to be escaped.
8
- * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
9
- *
10
- * @return The escaped key.
11
- */
12
- var escapeKey = function (unescapedKey, escapeUnicode) {
13
- if (escapeUnicode === void 0) { escapeUnicode = false; }
14
- return escapeContent(unescapedKey, true, escapeUnicode);
15
- };
16
- exports.escapeKey = escapeKey;
17
- /**
18
- * Escape property value.
19
- *
20
- * @param unescapedValue - Property value to be escaped.
21
- * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
22
- *
23
- * @return The escaped value.
24
- */
25
- var escapeValue = function (unescapedValue, escapeUnicode) {
26
- if (escapeUnicode === void 0) { escapeUnicode = false; }
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
@@ -1,5 +1,4 @@
1
1
  /// <reference types="./properties-file" />
2
-
3
2
  /// <reference types="node" />
4
3
  export { Properties } from './properties';
5
4
  /**
package/lib/index.js CHANGED
@@ -1,17 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getProperties = exports.Properties = void 0;
4
- var properties_1 = require("./properties");
5
- var properties_2 = require("./properties");
6
- Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_2.Properties; } });
7
- /**
8
- * Converts the content of a `.properties` file to a key-value pair object.
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;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="../properties-file" />
2
-
3
2
  /**
4
3
  * Webpack file loader for `.properties` files.
5
4
  *
@@ -1,14 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var __1 = require("..");
4
- /**
5
- * Webpack file loader for `.properties` files.
6
- *
7
- * @param content - the content of a `.properties` file.
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;
@@ -91,5 +91,5 @@ export declare class KeyCollisions {
91
91
  /**
92
92
  * Get the number of the line from which the value will be used.
93
93
  */
94
- getApplicableLineNumber(): number;
94
+ getApplicableLineNumber(): number | undefined;
95
95
  }