properties-file 2.0.7 → 2.1.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Avansai
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Avansai
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -40,9 +40,9 @@ Both APIs (`getProperties` and `propertiesToJson`) directly under `properties-fi
40
40
  This API is probably the most used. You have a `.properties` file that you want to open and access like a simple key/value JSON object. Here is how this can be done with a single API call:
41
41
 
42
42
  ```ts
43
- import { propertiesToJson } from 'properties-file';
43
+ import { propertiesToJson } from 'properties-file'
44
44
 
45
- console.log(propertiesToJson('hello-world.properties'));
45
+ console.log(propertiesToJson('hello-world.properties'))
46
46
  ```
47
47
 
48
48
  Output:
@@ -54,11 +54,11 @@ Output:
54
54
  If you cannot use `fs` and already have the content of a `.properties` file, your code would look like this instead:
55
55
 
56
56
  ```ts
57
- import { propertiesToJson } from 'properties-file/content';
57
+ import { propertiesToJson } from 'properties-file/content'
58
58
 
59
59
  // ...some code to get the .properties file content into a variable called `propertiesFileContent`
60
60
 
61
- console.log(propertiesToJson(propertiesFileContent));
61
+ console.log(propertiesToJson(propertiesFileContent))
62
62
  ```
63
63
 
64
64
  ### `getProperties` (advanced use case)
@@ -84,13 +84,13 @@ world: world3
84
84
  ```
85
85
 
86
86
  ```ts
87
- import { getProperties } from 'properties-file';
87
+ import { getProperties } from 'properties-file'
88
88
 
89
- const properties = getProperties('assets/tests/collisions-test.properties');
89
+ const properties = getProperties('assets/tests/collisions-test.properties')
90
90
 
91
91
  properties.collection.forEach((property) => {
92
- console.log(`${property.key} => '${property.value}'`);
93
- });
92
+ console.log(`${property.key} => '${property.value}'`)
93
+ })
94
94
 
95
95
  /**
96
96
  * Outputs:
@@ -100,7 +100,7 @@ properties.collection.forEach((property) => {
100
100
  *
101
101
  */
102
102
 
103
- const keyCollisions = properties.getKeyCollisions();
103
+ const keyCollisions = properties.getKeyCollisions()
104
104
 
105
105
  keyCollisions.forEach((keyCollision) => {
106
106
  console.warn(
@@ -109,8 +109,8 @@ keyCollisions.forEach((keyCollision) => {
109
109
  }' on lines ${keyCollision.startingLineNumbers.join(
110
110
  ', '
111
111
  )} (will use the value at line ${keyCollision.getApplicableLineNumber()}).`
112
- );
113
- });
112
+ )
113
+ })
114
114
 
115
115
  /**
116
116
  * Outputs:
@@ -140,7 +140,7 @@ module.exports = {
140
140
  },
141
141
  ],
142
142
  },
143
- };
143
+ }
144
144
  ```
145
145
 
146
146
  As soon as you configure Webpack, the `.properties` type should be available in your IDE when using `import`. If you ever need to add it manually, you can add a `*.properties` type declaration file at the root of your application, like this:
@@ -156,9 +156,9 @@ declare module '*.properties' {
156
156
  By adding these configurations you should now be able to import directly `.properties` files just like this:
157
157
 
158
158
  ```ts
159
- import helloWorld from './hello-world.properties';
159
+ import helloWorld from './hello-world.properties'
160
160
 
161
- console.dir(helloWorld);
161
+ console.dir(helloWorld)
162
162
  ```
163
163
 
164
164
  Output:
@@ -13,7 +13,7 @@ var property_line_1 = require("../property-line");
13
13
  */
14
14
  function getProperties(content) {
15
15
  // Remove BOM character if present and create an array from lines.
16
- var lines = (content.charCodeAt(0) === 0xfeff ? content.slice(1) : content).split(/\r?\n/);
16
+ var lines = (content.codePointAt(0) === 0xfeff ? content.slice(1) : content).split(/\r?\n/);
17
17
  /** Line number while parsing properties file content. */
18
18
  var lineNumber = 0;
19
19
  /** The current property object being parsed. */
package/lib/file/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.propertiesToJson = exports.getProperties = void 0;
4
- var fs_1 = require("fs");
4
+ var node_fs_1 = require("node:fs");
5
5
  var content_1 = require("../content/");
6
6
  /**
7
7
  * Get a `Properties` object from the content of a `.properties` file.
@@ -12,10 +12,10 @@ var content_1 = require("../content/");
12
12
  * @returns A `Properties` object representing the content of a `.properties` file.
13
13
  */
14
14
  function getProperties(filePath, encoding) {
15
- if (!(0, fs_1.existsSync)(filePath)) {
16
- throw Error("file not found at ".concat(filePath));
15
+ if (!(0, node_fs_1.existsSync)(filePath)) {
16
+ throw new Error("file not found at ".concat(filePath));
17
17
  }
18
- return (0, content_1.getProperties)((0, fs_1.readFileSync)(filePath, encoding ? encoding : 'utf-8'));
18
+ return (0, content_1.getProperties)((0, node_fs_1.readFileSync)(filePath, encoding !== null && encoding !== void 0 ? encoding : 'utf8'));
19
19
  }
20
20
  exports.getProperties = getProperties;
21
21
  /**
package/lib/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  /// <reference types="./properties-file" />
2
2
 
3
- export { Properties, KeyLineNumbers } from './properties';
3
+ export { getProperties, propertiesToJson } from './file';
4
+ export { KeyLineNumbers, Properties } from './properties';
4
5
  export { Property } from './property';
5
6
  export { PropertyLine } from './property-line';
6
- export { getProperties } from './file';
7
- export { propertiesToJson } from './file';
8
7
  /**
9
8
  * A simple "key/value" object.
10
9
  */
package/lib/index.js CHANGED
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertiesToJson = exports.getProperties = exports.PropertyLine = exports.Property = exports.Properties = void 0;
3
+ exports.PropertyLine = exports.Property = exports.Properties = exports.propertiesToJson = exports.getProperties = void 0;
4
+ var file_1 = require("./file");
5
+ Object.defineProperty(exports, "getProperties", { enumerable: true, get: function () { return file_1.getProperties; } });
6
+ Object.defineProperty(exports, "propertiesToJson", { enumerable: true, get: function () { return file_1.propertiesToJson; } });
4
7
  var properties_1 = require("./properties");
5
8
  Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_1.Properties; } });
6
9
  var property_1 = require("./property");
7
10
  Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return property_1.Property; } });
8
11
  var property_line_1 = require("./property-line");
9
12
  Object.defineProperty(exports, "PropertyLine", { enumerable: true, get: function () { return property_line_1.PropertyLine; } });
10
- var file_1 = require("./file");
11
- Object.defineProperty(exports, "getProperties", { enumerable: true, get: function () { return file_1.getProperties; } });
12
- var file_2 = require("./file");
13
- Object.defineProperty(exports, "propertiesToJson", { enumerable: true, get: function () { return file_2.propertiesToJson; } });
@@ -1,7 +1,7 @@
1
- /** This allows to get the correct type when using `import` on `.properties` files. */
2
- declare module '*.properties' {
3
- const properties: {
4
- readonly [key: string]: string;
5
- };
6
- export default properties;
7
- }
1
+ /** This allows to get the correct type when using `import` on `.properties` files. */
2
+ declare module '*.properties' {
3
+ const properties: {
4
+ readonly [key: string]: string
5
+ }
6
+ export default properties
7
+ }
@@ -4,10 +4,10 @@ import { Property } from './property';
4
4
  * A class representing the content of a .properties file.
5
5
  */
6
6
  export declare class Properties {
7
- /** Object associating keys with their starting line numbers. */
8
- keyLineNumbers: KeyLineNumbers;
9
7
  /** The collection of property object. */
10
8
  collection: Property[];
9
+ /** Object associating keys with their starting line numbers. */
10
+ keyLineNumbers: KeyLineNumbers;
11
11
  /**
12
12
  * Add a property object into a properties object collection.
13
13
  *
@@ -16,16 +16,16 @@ export declare class Properties {
16
16
  * @returns Undefined so that we conveniently overwrite the property object.
17
17
  */
18
18
  add(property: Property | undefined): undefined;
19
+ /**
20
+ * Get keys that have collisions (more than one occurrence).
21
+ */
22
+ getKeyCollisions(): KeyCollisions[];
19
23
  /**
20
24
  * Get the JSON (key/value) representation of the properties.
21
25
  *
22
26
  * @returns A key/value representing the properties of the object.
23
27
  */
24
28
  toJson(): KeyValueObject;
25
- /**
26
- * Get keys that have collisions (more than one occurrence).
27
- */
28
- getKeyCollisions(): KeyCollisions[];
29
29
  }
30
30
  /**
31
31
  * Object associating keys with their line numbers.
package/lib/properties.js CHANGED
@@ -6,10 +6,10 @@ exports.KeyCollisions = exports.Properties = void 0;
6
6
  */
7
7
  var Properties = /** @class */ (function () {
8
8
  function Properties() {
9
- /** Object associating keys with their starting line numbers. */
10
- this.keyLineNumbers = {};
11
9
  /** The collection of property object. */
12
10
  this.collection = [];
11
+ /** Object associating keys with their starting line numbers. */
12
+ this.keyLineNumbers = {};
13
13
  }
14
14
  /**
15
15
  * Add a property object into a properties object collection.
@@ -38,18 +38,6 @@ var Properties = /** @class */ (function () {
38
38
  this.collection.push(property);
39
39
  return undefined;
40
40
  };
41
- /**
42
- * Get the JSON (key/value) representation of the properties.
43
- *
44
- * @returns A key/value representing the properties of the object.
45
- */
46
- Properties.prototype.toJson = function () {
47
- var keyValueObject = {};
48
- this.collection.forEach(function (property) {
49
- keyValueObject[property.key] = property.value;
50
- });
51
- return keyValueObject;
52
- };
53
41
  /**
54
42
  * Get keys that have collisions (more than one occurrence).
55
43
  */
@@ -63,6 +51,18 @@ var Properties = /** @class */ (function () {
63
51
  }
64
52
  return keyCollisions;
65
53
  };
54
+ /**
55
+ * Get the JSON (key/value) representation of the properties.
56
+ *
57
+ * @returns A key/value representing the properties of the object.
58
+ */
59
+ Properties.prototype.toJson = function () {
60
+ var keyValueObject = {};
61
+ this.collection.forEach(function (property) {
62
+ keyValueObject[property.key] = property.value;
63
+ });
64
+ return keyValueObject;
65
+ };
66
66
  return Properties;
67
67
  }());
68
68
  exports.Properties = Properties;
@@ -4,14 +4,14 @@
4
4
  export declare class PropertyLine {
5
5
  /** The line content, minus the trailing \ that identifies that the line continues. */
6
6
  content: string;
7
- /** Is the line object a continuation from a previous line? */
8
- isMultiline: boolean;
9
7
  /** True if the line continues, otherwise false. */
10
8
  continues: boolean;
11
- /** True if the line is a comment, otherwise false. */
12
- isComment: boolean;
13
9
  /** True if the line is blank, otherwise false. */
14
10
  isBlank: boolean;
11
+ /** True if the line is a comment, otherwise false. */
12
+ isComment: boolean;
13
+ /** Is the line object a continuation from a previous line? */
14
+ isMultiline: boolean;
15
15
  /**
16
16
  * Create a new line object.
17
17
  *
@@ -14,20 +14,20 @@ var PropertyLine = /** @class */ (function () {
14
14
  function PropertyLine(line, isMultiline) {
15
15
  /** True if the line continues, otherwise false. */
16
16
  this.continues = false;
17
- /** True if the line is a comment, otherwise false. */
18
- this.isComment = false;
19
17
  /** True if the line is blank, otherwise false. */
20
18
  this.isBlank = false;
19
+ /** True if the line is a comment, otherwise false. */
20
+ this.isComment = false;
21
21
  this.content = line.trimStart();
22
22
  this.isMultiline = isMultiline;
23
- if (!this.content.length) {
23
+ if (this.content.length === 0) {
24
24
  // Line is blank.
25
25
  this.isBlank = true;
26
26
  }
27
27
  else {
28
28
  if (!this.isMultiline) {
29
29
  // Line is a comment.
30
- this.isComment = !!this.content.match(/^[!#]/);
30
+ this.isComment = !!/^[!#]/.test(this.content);
31
31
  }
32
32
  if (!this.isComment) {
33
33
  // Otherwise, check if the line continues on the next line.
package/lib/property.d.ts CHANGED
@@ -3,28 +3,28 @@ import { PropertyLine } from './property-line';
3
3
  * Object representing a property (key/value).
4
4
  */
5
5
  export declare class Property {
6
- /** The line number at which the property starts. */
7
- startingLineNumber: number;
8
- /** The content of one or multiple lines when applicable. */
9
- linesContent: string;
10
- /** Positions of the newline characters if any. */
11
- newlinePositions: number[];
12
- /** Starting line numbers of property objects with the same key. */
13
- keyCollisionLines: number[];
14
- /** The starting position of the delimiter separating the key from the value. */
15
- delimiterPosition: number | undefined;
16
6
  /** The length of the delimiter, including its whitespace characters. */
17
7
  delimiterLength: number | undefined;
8
+ /** The starting position of the delimiter separating the key from the value. */
9
+ delimiterPosition: number | undefined;
18
10
  /** The property key, including its escaped characters. */
19
11
  escapedKey: string;
20
12
  /** The property value, including its escaped characters. */
21
13
  escapedValue: string;
14
+ /** Was the property's key used more than once? */
15
+ hasKeyCollisions: boolean;
22
16
  /** The property key (unescaped). */
23
17
  key: string;
18
+ /** Starting line numbers of property objects with the same key. */
19
+ keyCollisionLines: number[];
20
+ /** The content of one or multiple lines when applicable. */
21
+ linesContent: string;
22
+ /** Positions of the newline characters if any. */
23
+ newlinePositions: number[];
24
+ /** The line number at which the property starts. */
25
+ startingLineNumber: number;
24
26
  /** The property value (unescaped). */
25
27
  value: string;
26
- /** Was the property's key used more than once? */
27
- hasKeyCollisions: boolean;
28
28
  /** Does the key definition spread across multiple lines? */
29
29
  private hasMultilineKey;
30
30
  /** Is the key empty? */
package/lib/property.js CHANGED
@@ -12,20 +12,20 @@ var Property = /** @class */ (function () {
12
12
  * @param startingLineNumber - The line number at which the property starts.
13
13
  */
14
14
  function Property(propertyLine, startingLineNumber) {
15
- /** Positions of the newline characters if any. */
16
- this.newlinePositions = [];
17
- /** Starting line numbers of property objects with the same key. */
18
- this.keyCollisionLines = [];
19
15
  /** The property key, including its escaped characters. */
20
16
  this.escapedKey = '';
21
17
  /** The property value, including its escaped characters. */
22
18
  this.escapedValue = '';
19
+ /** Was the property's key used more than once? */
20
+ this.hasKeyCollisions = false;
23
21
  /** The property key (unescaped). */
24
22
  this.key = '';
23
+ /** Starting line numbers of property objects with the same key. */
24
+ this.keyCollisionLines = [];
25
+ /** Positions of the newline characters if any. */
26
+ this.newlinePositions = [];
25
27
  /** The property value (unescaped). */
26
28
  this.value = '';
27
- /** Was the property's key used more than once? */
28
- this.hasKeyCollisions = false;
29
29
  /** Does the key definition spread across multiple lines? */
30
30
  this.hasMultilineKey = false;
31
31
  /** Is the key empty? */
@@ -41,7 +41,7 @@ var Property = /** @class */ (function () {
41
41
  * @param propertyLine - A property line object.
42
42
  */
43
43
  Property.prototype.addLine = function (propertyLine) {
44
- if (this.linesContent.length) {
44
+ if (this.linesContent.length > 0) {
45
45
  this.newlinePositions.push(this.linesContent.length);
46
46
  }
47
47
  this.linesContent += propertyLine.content;
@@ -54,12 +54,12 @@ var Property = /** @class */ (function () {
54
54
  if (this.delimiterPosition !== undefined && this.delimiterLength !== undefined) {
55
55
  // Set key if present.
56
56
  if (!this.hasNoKey) {
57
- this.escapedKey = this.linesContent.substring(0, this.delimiterPosition);
57
+ this.escapedKey = this.linesContent.slice(0, this.delimiterPosition);
58
58
  this.key = this.unescape(this.escapedKey, this.startingLineNumber);
59
59
  }
60
60
  // Set value if present.
61
61
  if (!this.hasNoValue) {
62
- this.escapedValue = this.linesContent.substring(this.delimiterPosition + this.delimiterLength);
62
+ this.escapedValue = this.linesContent.slice(this.delimiterPosition + this.delimiterLength);
63
63
  this.value = this.unescape(this.escapedValue, this.startingLineNumber);
64
64
  }
65
65
  }
@@ -79,43 +79,50 @@ var Property = /** @class */ (function () {
79
79
  */
80
80
  Property.prototype.unescape = function (escapedContent, startingLineNumber) {
81
81
  var unescapedContent = '';
82
- for (var position = 0, character = escapedContent[0]; position < escapedContent.length; position++, character = escapedContent[position]) {
82
+ for (var character = escapedContent[0], position = 0; position < escapedContent.length; position++, character = escapedContent[position]) {
83
83
  if (character === '\\') {
84
84
  var nextCharacter = escapedContent[position + 1];
85
- if (nextCharacter === 'f') {
86
- // Formfeed/
87
- unescapedContent += '\f';
88
- position++;
89
- }
90
- else if (nextCharacter === 'n') {
91
- // Newline.
92
- unescapedContent += '\n';
93
- position++;
94
- }
95
- else if (nextCharacter === 'r') {
96
- // Carriage return.
97
- unescapedContent += '\r';
98
- position++;
99
- }
100
- else if (nextCharacter === 't') {
101
- // Tab.
102
- unescapedContent += '\t';
103
- position++;
104
- }
105
- else if (nextCharacter === 'u') {
106
- // Unicode character.
107
- var codePoint = escapedContent.substring(position + 2, position + 6);
108
- if (!/[0-9a-f]{4}/i.test(codePoint)) {
109
- // Code point can only be within Unicode's Multilingual Plane (BMP).
110
- throw new Error("malformed escaped unicode characters '\\u".concat(codePoint, "' in property starting at line ").concat(startingLineNumber));
85
+ switch (nextCharacter) {
86
+ case 'f': {
87
+ // Formfeed/
88
+ unescapedContent += '\f';
89
+ position++;
90
+ break;
91
+ }
92
+ case 'n': {
93
+ // Newline.
94
+ unescapedContent += '\n';
95
+ position++;
96
+ break;
97
+ }
98
+ case 'r': {
99
+ // Carriage return.
100
+ unescapedContent += '\r';
101
+ position++;
102
+ break;
103
+ }
104
+ case 't': {
105
+ // Tab.
106
+ unescapedContent += '\t';
107
+ position++;
108
+ break;
109
+ }
110
+ case 'u': {
111
+ // Unicode character.
112
+ var codePoint = escapedContent.slice(position + 2, position + 6);
113
+ if (!/[\da-f]{4}/i.test(codePoint)) {
114
+ // Code point can only be within Unicode's Multilingual Plane (BMP).
115
+ throw new Error("malformed escaped unicode characters '\\u".concat(codePoint, "' in property starting at line ").concat(startingLineNumber));
116
+ }
117
+ unescapedContent += String.fromCodePoint(Number.parseInt(codePoint, 16));
118
+ position += 5;
119
+ break;
120
+ }
121
+ default: {
122
+ // Otherwise the escape character is not required.
123
+ unescapedContent += nextCharacter;
124
+ position++;
111
125
  }
112
- unescapedContent += String.fromCharCode(parseInt(codePoint, 16));
113
- position += 5;
114
- }
115
- else {
116
- // Otherwise the escape character is not required.
117
- unescapedContent += nextCharacter;
118
- position++;
119
126
  }
120
127
  }
121
128
  else {
@@ -134,14 +141,14 @@ var Property = /** @class */ (function () {
134
141
  if (this.hasNoKey || this.hasNoValue || this.delimiterPosition) {
135
142
  return;
136
143
  }
137
- for (var position = 0, character = this.linesContent[0]; position < this.linesContent.length; position++, character = this.linesContent[position]) {
144
+ for (var character = this.linesContent[0], position = 0; position < this.linesContent.length; position++, character = this.linesContent[position]) {
138
145
  // If the character is not a delimiter, check the next one.
139
- if (!/[ \t\f=:]/.test(character)) {
146
+ if (!/[\t\f :=]/.test(character)) {
140
147
  continue;
141
148
  }
142
149
  // Check if the delimiter might be escaped.
143
- var prefix = !position ? '' : this.linesContent.substring(0, position);
144
- if (prefix.length) {
150
+ var prefix = !position ? '' : this.linesContent.slice(0, position);
151
+ if (prefix.length > 0) {
145
152
  var backslashMatch = prefix.match(/(?<backslashes>\\+)$/);
146
153
  if (backslashMatch === null || backslashMatch === void 0 ? void 0 : backslashMatch.groups) {
147
154
  var delimiterIsEscaped = !!(backslashMatch.groups.backslashes.length % 2);
@@ -153,20 +160,20 @@ var Property = /** @class */ (function () {
153
160
  }
154
161
  var delimiter = '';
155
162
  this.delimiterPosition = position;
156
- this.hasMultilineKey = !!(this.newlinePositions.length && this.newlinePositions[0] > position);
163
+ this.hasMultilineKey = !!(this.newlinePositions.length > 0 && this.newlinePositions[0] > position);
157
164
  // Check if the delimiter starts with a whitespace.
158
- var nextContent = this.linesContent.substring(position);
165
+ var nextContent = this.linesContent.slice(position);
159
166
  var leadingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/);
160
167
  var leadingWhitespace = ((_a = leadingWhitespaceMatch === null || leadingWhitespaceMatch === void 0 ? void 0 : leadingWhitespaceMatch.groups) === null || _a === void 0 ? void 0 : _a.whitespace) || '';
161
168
  // If there is a whitespace, move to the next character.
162
- if (leadingWhitespace.length) {
169
+ if (leadingWhitespace.length > 0) {
163
170
  delimiter += leadingWhitespace;
164
- nextContent = nextContent.substring(leadingWhitespace.length);
171
+ nextContent = nextContent.slice(leadingWhitespace.length);
165
172
  }
166
173
  // Check if there is an equal or colon character.
167
- if (/[=:]/.test(nextContent[0])) {
174
+ if (/[:=]/.test(nextContent[0])) {
168
175
  delimiter += nextContent[0];
169
- nextContent = nextContent.substring(1);
176
+ nextContent = nextContent.slice(1);
170
177
  // If an equal or colon character was found, try to get trailing whitespace.
171
178
  var trailingWhitespaceMatch = nextContent.match(/^(?<whitespace>\s+)/);
172
179
  var trailingWhitespace = ((_b = trailingWhitespaceMatch === null || trailingWhitespaceMatch === void 0 ? void 0 : trailingWhitespaceMatch.groups) === null || _b === void 0 ? void 0 : _b.whitespace) || '';
@@ -185,7 +192,7 @@ var Property = /** @class */ (function () {
185
192
  }
186
193
  else {
187
194
  // If the delimiter is after the first newline, mark the key as multiline.
188
- if (this.newlinePositions.length) {
195
+ if (this.newlinePositions.length > 0) {
189
196
  var firstLinePosition = this.newlinePositions[0];
190
197
  if (firstLinePosition > this.delimiterPosition) {
191
198
  this.hasMultilineKey = true;
package/package.json CHANGED
@@ -1,70 +1,80 @@
1
- {
2
- "name": "properties-file",
3
- "version": "2.0.7",
4
- "description": ".properties file parser, JSON converter and Webpack loader.",
5
- "author": "Avansai (https://avansai.com)",
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/Avansai/properties-file.git"
9
- },
10
- "main": "lib/index.js",
11
- "types": "lib/index.d.ts",
12
- "exports": {
13
- ".": "./lib/index.js",
14
- "./content": "./lib/content/index.js",
15
- "./webpack-loader": "./lib/loader/webpack.js"
16
- },
17
- "typesVersions": {
18
- "*": {
19
- "content": [
20
- "lib/content/index.d.ts"
21
- ],
22
- "webpack-loader": [
23
- "lib/loader/webpack.d.ts"
24
- ]
25
- }
26
- },
27
- "license": "MIT",
28
- "files": [
29
- "lib"
30
- ],
31
- "keywords": [
32
- ".properties",
33
- "properties",
34
- ".properties file",
35
- "properties file",
36
- "parser",
37
- "Java",
38
- "intl",
39
- "i18n",
40
- "properties Webpack loader",
41
- "Webpack loader",
42
- "internationalization"
43
- ],
44
- "scripts": {
45
- "build": "rm -Rf ./lib && tsc && npm run add-import-type && npm run lint && npm test",
46
- "add-import-type": "node ./src/add-import-type",
47
- "test": "jest --coverage",
48
- "tmp-test": "tsc && node ./lib/tmp.js",
49
- "lint": "eslint . --fix",
50
- "prettier-check": "prettier --check .",
51
- "prettier-fix": "prettier --write .",
52
- "release": "dotenv -- release-it --only-version"
53
- },
54
- "devDependencies": {
55
- "@release-it/conventional-changelog": "^5.0.0",
56
- "@types/jest": "^28.1.6",
57
- "@typescript-eslint/eslint-plugin": "^5.30.7",
58
- "@typescript-eslint/parser": "^5.30.7",
59
- "dotenv-cli": "^6.0.0",
60
- "eslint": "^8.20.0",
61
- "eslint-config-prettier": "^8.5.0",
62
- "eslint-plugin-jest": "^26.6.0",
63
- "jest": "^28.1.3",
64
- "prettier": "2.7.1",
65
- "release-it": "^15.1.3",
66
- "ts-jest": "^28.0.7",
67
- "ts-node": "^10.9.1",
68
- "typescript": "^4.7.4"
69
- }
70
- }
1
+ {
2
+ "name": "properties-file",
3
+ "version": "2.1.0",
4
+ "description": ".properties file parser, JSON converter and Webpack loader.",
5
+ "author": "Avansai (https://avansai.com)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Avansai/properties-file.git"
9
+ },
10
+ "main": "lib/index.js",
11
+ "types": "lib/index.d.ts",
12
+ "exports": {
13
+ ".": "./lib/index.js",
14
+ "./content": "./lib/content/index.js",
15
+ "./webpack-loader": "./lib/loader/webpack.js"
16
+ },
17
+ "typesVersions": {
18
+ "*": {
19
+ "content": [
20
+ "lib/content/index.d.ts"
21
+ ],
22
+ "webpack-loader": [
23
+ "lib/loader/webpack.d.ts"
24
+ ]
25
+ }
26
+ },
27
+ "license": "MIT",
28
+ "files": [
29
+ "lib"
30
+ ],
31
+ "keywords": [
32
+ ".properties",
33
+ "properties",
34
+ ".properties file",
35
+ "properties file",
36
+ "parser",
37
+ "Java",
38
+ "intl",
39
+ "i18n",
40
+ "properties Webpack loader",
41
+ "Webpack loader",
42
+ "internationalization"
43
+ ],
44
+ "scripts": {
45
+ "build": "npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc && npm run add-import-type && npm test",
46
+ "lint-fix": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --fix .",
47
+ "lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx .",
48
+ "lint-print-config": "eslint --print-config ./eslintrc.yaml",
49
+ "prettier": "prettier --write .",
50
+ "add-import-type": "node ./src/add-import-type.mjs",
51
+ "test": "jest --coverage",
52
+ "release": "dotenv -- release-it --only-version"
53
+ },
54
+ "devDependencies": {
55
+ "@release-it/conventional-changelog": "^5.0.0",
56
+ "@types/jest": "^28.1.6",
57
+ "@typescript-eslint/eslint-plugin": "^5.33.0",
58
+ "@typescript-eslint/parser": "^5.33.0",
59
+ "dotenv-cli": "^6.0.0",
60
+ "eslint": "^8.21.0",
61
+ "eslint-config-prettier": "^8.5.0",
62
+ "eslint-import-resolver-node": "^0.3.6",
63
+ "eslint-import-resolver-typescript": "^3.4.0",
64
+ "eslint-plugin-import": "^2.26.0",
65
+ "eslint-plugin-jest": "^26.8.2",
66
+ "eslint-plugin-prettier": "^4.2.1",
67
+ "eslint-plugin-unicorn": "^43.0.2",
68
+ "jest": "^28.1.3",
69
+ "prettier": "^2.7.1",
70
+ "prettier-plugin-organize-imports": "^3.0.3",
71
+ "prettier-plugin-sh": "^0.12.8",
72
+ "release-it": "^15.3.0",
73
+ "ts-jest": "^28.0.7",
74
+ "ts-node": "^10.9.1",
75
+ "typescript": "^4.7.4"
76
+ },
77
+ "engines": {
78
+ "node": "^14.18.1 || ^16.0.0"
79
+ }
80
+ }