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/lib/properties.js CHANGED
@@ -1,218 +1,52 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.KeyCollisions = exports.Properties = exports.getFirstEolCharacter = exports.DEFAULT_END_OF_LINE_CHARACTER = exports.BOM_CODE_POINT = exports.BOM = void 0;
31
- var property_1 = require("./property");
32
- var property_line_1 = require("./property-line");
33
- /**
34
- * Byte-order mark.
35
- */
36
- exports.BOM = '\uFEFF';
37
- exports.BOM_CODE_POINT = exports.BOM.codePointAt(0);
38
- /** The default end of line character. */
39
- exports.DEFAULT_END_OF_LINE_CHARACTER = '\n';
40
- /**
41
- * Get the first end of line (EOL) character from multiline content.
42
- *
43
- * @param content - The content of a `.properties` file.
44
- *
45
- * @returns The multiline content's first end of line (EOL) character.
46
- */
47
- var getFirstEolCharacter = function (content) {
48
- var newlineIndex = content.indexOf('\n');
49
- return newlineIndex < 0 ? undefined : "".concat(content[newlineIndex - 1] === '\r' ? '\r' : '', "\n");
50
- };
51
- exports.getFirstEolCharacter = getFirstEolCharacter;
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 = Buffer.isBuffer(content) ? content.toString() : content;
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;
@@ -1,48 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PropertyLine = void 0;
4
- /**
5
- * Object representing a line from the content of .properties file.
6
- */
7
- var PropertyLine = /** @class */ (function () {
8
- /**
9
- * Create a new line object.
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.defineProperty(exports, "__esModule", { value: true });
3
- exports.Property = void 0;
4
- var unescape_1 = require("./unescape");
5
- /**
6
- * Object representing a property (key/value).
7
- */
8
- var Property = /** @class */ (function () {
9
- /**
10
- * Create a new property object.
11
- *
12
- * @param propertyLine - A property line object.
13
- * @param startingLineNumber - The line number at which the property starts.
14
- */
15
- function Property(propertyLine, startingLineNumber, previousProperty) {
16
- /** The property key (unescaped). */
17
- this.key = '';
18
- /** The property key, including its escaped characters. */
19
- this.escapedKey = '';
20
- /** Is the key empty? */
21
- this.hasNoKey = false;
22
- /** Does the key definition spread across multiple lines? */
23
- this.hasMultilineKey = false;
24
- /** Starting line numbers of property objects with the same key. */
25
- this.keyCollisionLines = [];
26
- /** Was the property's key used more than once? */
27
- this.hasKeyCollisions = false;
28
- /** The property value (unescaped). */
29
- this.value = '';
30
- /** The property value, including its escaped characters. */
31
- this.escapedValue = '';
32
- /** Is the value empty? */
33
- this.hasNoValue = false;
34
- /** Positions of the newline characters if any. */
35
- this.newlinePositions = [];
36
- this.linesContent = propertyLine.content;
37
- this.startingLineNumber = startingLineNumber;
38
- this.endingLineNumber = startingLineNumber;
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;
@@ -1,69 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unescapeContent = void 0;
4
- /**
5
- * Unescape the content from either key or value of a property.
6
- *
7
- * @param escapedContent - The content to unescape.
8
- *
9
- * @returns The unescaped content.
10
- *
11
- * @throws {@link Error}
12
- * This exception is thrown if malformed escaped unicode characters are present.
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;