properties-file 2.1.1 → 2.1.4

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,21 +1,21 @@
1
- /// <reference types="node" />
2
- import { KeyValueObject, Properties } from '../';
3
- export { KeyValueObject } from '../';
4
- /**
5
- * Get a `Properties` object from the content of a `.properties` file.
6
- *
7
- * @param filePath - The file path of the `.properties` file.
8
- * @param encoding - The encoding of the file to parse (default is UTF-8).
9
- *
10
- * @returns A `Properties` object representing the content of a `.properties` file.
11
- */
12
- export declare function getProperties(filePath: string, encoding?: BufferEncoding): Properties;
13
- /**
14
- * Converts the content of a `.properties` file to JSON.
15
- *
16
- * @param filePath - The file path of the `.properties` file.
17
- * @param encoding - The encoding of the file to parse (default is UTF-8).
18
- *
19
- * @returns A (JSON) key/value object representing the content of a `.properties` file.
20
- */
21
- export declare function propertiesToJson(filePath: string, encoding?: BufferEncoding): KeyValueObject;
1
+ /// <reference types="node" />
2
+ import { KeyValueObject, Properties } from '../';
3
+ export { KeyValueObject } from '../';
4
+ /**
5
+ * Get a `Properties` object from the content of a `.properties` file.
6
+ *
7
+ * @param filePath - The file path of the `.properties` file.
8
+ * @param encoding - The encoding of the file to parse (default is UTF-8).
9
+ *
10
+ * @returns A `Properties` object representing the content of a `.properties` file.
11
+ */
12
+ export declare function getProperties(filePath: string, encoding?: BufferEncoding): Properties;
13
+ /**
14
+ * Converts the content of a `.properties` file to JSON.
15
+ *
16
+ * @param filePath - The file path of the `.properties` file.
17
+ * @param encoding - The encoding of the file to parse (default is UTF-8).
18
+ *
19
+ * @returns A (JSON) key/value object representing the content of a `.properties` file.
20
+ */
21
+ export declare function propertiesToJson(filePath: string, encoding?: BufferEncoding): KeyValueObject;
package/lib/file/index.js CHANGED
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.propertiesToJson = exports.getProperties = void 0;
4
- var node_fs_1 = require("node:fs");
5
- var content_1 = require("../content/");
6
- /**
7
- * Get a `Properties` object from the content of a `.properties` file.
8
- *
9
- * @param filePath - The file path of the `.properties` file.
10
- * @param encoding - The encoding of the file to parse (default is UTF-8).
11
- *
12
- * @returns A `Properties` object representing the content of a `.properties` file.
13
- */
14
- function getProperties(filePath, encoding) {
15
- if (!(0, node_fs_1.existsSync)(filePath)) {
16
- throw new Error("file not found at ".concat(filePath));
17
- }
18
- return (0, content_1.getProperties)((0, node_fs_1.readFileSync)(filePath, encoding !== null && encoding !== void 0 ? encoding : 'utf8'));
19
- }
20
- exports.getProperties = getProperties;
21
- /**
22
- * Converts the content of a `.properties` file to JSON.
23
- *
24
- * @param filePath - The file path of the `.properties` file.
25
- * @param encoding - The encoding of the file to parse (default is UTF-8).
26
- *
27
- * @returns A (JSON) key/value object representing the content of a `.properties` file.
28
- */
29
- function propertiesToJson(filePath, encoding) {
30
- return getProperties(filePath, encoding).toJson();
31
- }
32
- exports.propertiesToJson = propertiesToJson;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.propertiesToJson = exports.getProperties = void 0;
4
+ var node_fs_1 = require("node:fs");
5
+ var content_1 = require("../content/");
6
+ /**
7
+ * Get a `Properties` object from the content of a `.properties` file.
8
+ *
9
+ * @param filePath - The file path of the `.properties` file.
10
+ * @param encoding - The encoding of the file to parse (default is UTF-8).
11
+ *
12
+ * @returns A `Properties` object representing the content of a `.properties` file.
13
+ */
14
+ function getProperties(filePath, encoding) {
15
+ if (!(0, node_fs_1.existsSync)(filePath)) {
16
+ throw new Error("file not found at ".concat(filePath));
17
+ }
18
+ return (0, content_1.getProperties)((0, node_fs_1.readFileSync)(filePath, encoding !== null && encoding !== void 0 ? encoding : 'utf8'));
19
+ }
20
+ exports.getProperties = getProperties;
21
+ /**
22
+ * Converts the content of a `.properties` file to JSON.
23
+ *
24
+ * @param filePath - The file path of the `.properties` file.
25
+ * @param encoding - The encoding of the file to parse (default is UTF-8).
26
+ *
27
+ * @returns A (JSON) key/value object representing the content of a `.properties` file.
28
+ */
29
+ function propertiesToJson(filePath, encoding) {
30
+ return getProperties(filePath, encoding).toJson();
31
+ }
32
+ exports.propertiesToJson = propertiesToJson;
package/lib/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /// <reference types="./properties-file" />
2
2
 
3
- export { getProperties, propertiesToJson } from './file';
4
- export { KeyLineNumbers, Properties } from './properties';
5
- export { Property } from './property';
6
- export { PropertyLine } from './property-line';
7
- /**
8
- * A simple "key/value" object.
9
- */
10
- export declare type KeyValueObject = {
11
- [key: string]: string;
12
- };
3
+ export { getProperties, propertiesToJson } from './file';
4
+ export { KeyLineNumbers, Properties } from './properties';
5
+ export { Property } from './property';
6
+ export { PropertyLine } from './property-line';
7
+ /**
8
+ * A simple "key/value" object.
9
+ */
10
+ export declare type KeyValueObject = {
11
+ [key: string]: string;
12
+ };
package/lib/index.js CHANGED
@@ -1,12 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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; } });
7
- var properties_1 = require("./properties");
8
- Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_1.Properties; } });
9
- var property_1 = require("./property");
10
- Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return property_1.Property; } });
11
- var property_line_1 = require("./property-line");
12
- Object.defineProperty(exports, "PropertyLine", { enumerable: true, get: function () { return property_line_1.PropertyLine; } });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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; } });
7
+ var properties_1 = require("./properties");
8
+ Object.defineProperty(exports, "Properties", { enumerable: true, get: function () { return properties_1.Properties; } });
9
+ var property_1 = require("./property");
10
+ Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return property_1.Property; } });
11
+ var property_line_1 = require("./property-line");
12
+ Object.defineProperty(exports, "PropertyLine", { enumerable: true, get: function () { return property_line_1.PropertyLine; } });
@@ -1,10 +1,10 @@
1
1
  /// <reference types="../properties-file" />
2
2
 
3
- /**
4
- * Webpack file loader for `.properties` files.
5
- *
6
- * @param content - the content of a `.properties` file.
7
- *
8
- * @returns A Webpack file loader string containing the content of a `.properties` file.
9
- */
10
- export default function (content: string): string;
3
+ /**
4
+ * Webpack file loader for `.properties` files.
5
+ *
6
+ * @param content - the content of a `.properties` file.
7
+ *
8
+ * @returns A Webpack file loader string containing the content of a `.properties` file.
9
+ */
10
+ export default function (content: string): string;
@@ -1,14 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var content_1 = require("../content");
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
- function default_1(content) {
12
- return "module.exports = ".concat(JSON.stringify((0, content_1.propertiesToJson)(content)), ";");
13
- }
14
- exports.default = default_1;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var content_1 = require("../content");
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
+ function default_1(content) {
12
+ return "module.exports = ".concat(JSON.stringify((0, content_1.propertiesToJson)(content)), ";");
13
+ }
14
+ exports.default = default_1;
@@ -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
+ }
@@ -1,55 +1,55 @@
1
- import { KeyValueObject } from './';
2
- import { Property } from './property';
3
- /**
4
- * A class representing the content of a .properties file.
5
- */
6
- export declare class Properties {
7
- /** The collection of property object. */
8
- collection: Property[];
9
- /** Object associating keys with their starting line numbers. */
10
- keyLineNumbers: KeyLineNumbers;
11
- /**
12
- * Add a property object into a properties object collection.
13
- *
14
- * @param property - A property object, or undefined.
15
- *
16
- * @returns Undefined so that we conveniently overwrite the property object.
17
- */
18
- add(property: Property | undefined): undefined;
19
- /**
20
- * Get keys that have collisions (more than one occurrence).
21
- */
22
- getKeyCollisions(): KeyCollisions[];
23
- /**
24
- * Get the JSON (key/value) representation of the properties.
25
- *
26
- * @returns A key/value representing the properties of the object.
27
- */
28
- toJson(): KeyValueObject;
29
- }
30
- /**
31
- * Object associating keys with their line numbers.
32
- */
33
- export declare type KeyLineNumbers = {
34
- [key: string]: number[];
35
- };
36
- /**
37
- * A class representing key within a .properties file that had collisions (more than one occurrence).
38
- */
39
- export declare class KeyCollisions {
40
- /** The key with collisions. */
41
- key: string;
42
- /** The starting line numbers where collisions are found. */
43
- startingLineNumbers: number[];
44
- /**
45
- * Create a new key collision object.
46
- *
47
- * @param key - The key with collisions.
48
- * @param startingLineNumbers - The starting line numbers where collisions are found.
49
- */
50
- constructor(key: string, startingLineNumbers: number[]);
51
- /**
52
- * Get the number of the line from which the value will be used.
53
- */
54
- getApplicableLineNumber(): number;
55
- }
1
+ import { KeyValueObject } from './';
2
+ import { Property } from './property';
3
+ /**
4
+ * A class representing the content of a .properties file.
5
+ */
6
+ export declare class Properties {
7
+ /** The collection of property object. */
8
+ collection: Property[];
9
+ /** Object associating keys with their starting line numbers. */
10
+ keyLineNumbers: KeyLineNumbers;
11
+ /**
12
+ * Add a property object into a properties object collection.
13
+ *
14
+ * @param property - A property object, or undefined.
15
+ *
16
+ * @returns Undefined so that we conveniently overwrite the property object.
17
+ */
18
+ add(property: Property | undefined): undefined;
19
+ /**
20
+ * Get keys that have collisions (more than one occurrence).
21
+ */
22
+ getKeyCollisions(): KeyCollisions[];
23
+ /**
24
+ * Get the JSON (key/value) representation of the properties.
25
+ *
26
+ * @returns A key/value representing the properties of the object.
27
+ */
28
+ toJson(): KeyValueObject;
29
+ }
30
+ /**
31
+ * Object associating keys with their line numbers.
32
+ */
33
+ export declare type KeyLineNumbers = {
34
+ [key: string]: number[];
35
+ };
36
+ /**
37
+ * A class representing key within a .properties file that had collisions (more than one occurrence).
38
+ */
39
+ export declare class KeyCollisions {
40
+ /** The key with collisions. */
41
+ key: string;
42
+ /** The starting line numbers where collisions are found. */
43
+ startingLineNumbers: number[];
44
+ /**
45
+ * Create a new key collision object.
46
+ *
47
+ * @param key - The key with collisions.
48
+ * @param startingLineNumbers - The starting line numbers where collisions are found.
49
+ */
50
+ constructor(key: string, startingLineNumbers: number[]);
51
+ /**
52
+ * Get the number of the line from which the value will be used.
53
+ */
54
+ getApplicableLineNumber(): number;
55
+ }
package/lib/properties.js CHANGED
@@ -1,91 +1,91 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KeyCollisions = exports.Properties = void 0;
4
- /**
5
- * A class representing the content of a .properties file.
6
- */
7
- var Properties = /** @class */ (function () {
8
- function Properties() {
9
- /** The collection of property object. */
10
- this.collection = [];
11
- /** Object associating keys with their starting line numbers. */
12
- this.keyLineNumbers = {};
13
- }
14
- /**
15
- * Add a property object into a properties object collection.
16
- *
17
- * @param property - A property object, or undefined.
18
- *
19
- * @returns Undefined so that we conveniently overwrite the property object.
20
- */
21
- Properties.prototype.add = function (property) {
22
- var _a;
23
- if (property === undefined)
24
- return undefined;
25
- property.setKeyAndValue();
26
- if ((_a = this.keyLineNumbers[property.key]) === null || _a === void 0 ? void 0 : _a.length) {
27
- this.keyLineNumbers[property.key].push(property.startingLineNumber);
28
- property.hasKeyCollisions = true;
29
- property.keyCollisionLines = this.keyLineNumbers[property.key];
30
- // Remove collision so that we can overwrite it with the latest object.
31
- this.collection = this.collection.filter(function (existingPropertyObject) { return existingPropertyObject.key !== property.key; });
32
- }
33
- else {
34
- // Initialize the key line numbers.
35
- this.keyLineNumbers[property.key] = [property.startingLineNumber];
36
- }
37
- // Add the property to the collection.
38
- this.collection.push(property);
39
- return undefined;
40
- };
41
- /**
42
- * Get keys that have collisions (more than one occurrence).
43
- */
44
- Properties.prototype.getKeyCollisions = function () {
45
- var keyCollisions = [];
46
- for (var _i = 0, _a = Object.entries(this.keyLineNumbers); _i < _a.length; _i++) {
47
- var _b = _a[_i], key = _b[0], startingLineNumbers = _b[1];
48
- if (startingLineNumbers.length > 1) {
49
- keyCollisions.push(new KeyCollisions(key, startingLineNumbers));
50
- }
51
- }
52
- return keyCollisions;
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
- return Properties;
67
- }());
68
- exports.Properties = Properties;
69
- /**
70
- * A class representing key within a .properties file that had collisions (more than one occurrence).
71
- */
72
- var KeyCollisions = /** @class */ (function () {
73
- /**
74
- * Create a new key collision object.
75
- *
76
- * @param key - The key with collisions.
77
- * @param startingLineNumbers - The starting line numbers where collisions are found.
78
- */
79
- function KeyCollisions(key, startingLineNumbers) {
80
- this.key = key;
81
- this.startingLineNumbers = startingLineNumbers;
82
- }
83
- /**
84
- * Get the number of the line from which the value will be used.
85
- */
86
- KeyCollisions.prototype.getApplicableLineNumber = function () {
87
- return this.startingLineNumbers.slice(-1)[0];
88
- };
89
- return KeyCollisions;
90
- }());
91
- exports.KeyCollisions = KeyCollisions;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyCollisions = exports.Properties = void 0;
4
+ /**
5
+ * A class representing the content of a .properties file.
6
+ */
7
+ var Properties = /** @class */ (function () {
8
+ function Properties() {
9
+ /** The collection of property object. */
10
+ this.collection = [];
11
+ /** Object associating keys with their starting line numbers. */
12
+ this.keyLineNumbers = {};
13
+ }
14
+ /**
15
+ * Add a property object into a properties object collection.
16
+ *
17
+ * @param property - A property object, or undefined.
18
+ *
19
+ * @returns Undefined so that we conveniently overwrite the property object.
20
+ */
21
+ Properties.prototype.add = function (property) {
22
+ var _a;
23
+ if (property === undefined)
24
+ return undefined;
25
+ property.setKeyAndValue();
26
+ if ((_a = this.keyLineNumbers[property.key]) === null || _a === void 0 ? void 0 : _a.length) {
27
+ this.keyLineNumbers[property.key].push(property.startingLineNumber);
28
+ property.hasKeyCollisions = true;
29
+ property.keyCollisionLines = this.keyLineNumbers[property.key];
30
+ // Remove collision so that we can overwrite it with the latest object.
31
+ this.collection = this.collection.filter(function (existingPropertyObject) { return existingPropertyObject.key !== property.key; });
32
+ }
33
+ else {
34
+ // Initialize the key line numbers.
35
+ this.keyLineNumbers[property.key] = [property.startingLineNumber];
36
+ }
37
+ // Add the property to the collection.
38
+ this.collection.push(property);
39
+ return undefined;
40
+ };
41
+ /**
42
+ * Get keys that have collisions (more than one occurrence).
43
+ */
44
+ Properties.prototype.getKeyCollisions = function () {
45
+ var keyCollisions = [];
46
+ for (var _i = 0, _a = Object.entries(this.keyLineNumbers); _i < _a.length; _i++) {
47
+ var _b = _a[_i], key = _b[0], startingLineNumbers = _b[1];
48
+ if (startingLineNumbers.length > 1) {
49
+ keyCollisions.push(new KeyCollisions(key, startingLineNumbers));
50
+ }
51
+ }
52
+ return keyCollisions;
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
+ return Properties;
67
+ }());
68
+ exports.Properties = Properties;
69
+ /**
70
+ * A class representing key within a .properties file that had collisions (more than one occurrence).
71
+ */
72
+ var KeyCollisions = /** @class */ (function () {
73
+ /**
74
+ * Create a new key collision object.
75
+ *
76
+ * @param key - The key with collisions.
77
+ * @param startingLineNumbers - The starting line numbers where collisions are found.
78
+ */
79
+ function KeyCollisions(key, startingLineNumbers) {
80
+ this.key = key;
81
+ this.startingLineNumbers = startingLineNumbers;
82
+ }
83
+ /**
84
+ * Get the number of the line from which the value will be used.
85
+ */
86
+ KeyCollisions.prototype.getApplicableLineNumber = function () {
87
+ return this.startingLineNumbers.slice(-1)[0];
88
+ };
89
+ return KeyCollisions;
90
+ }());
91
+ exports.KeyCollisions = KeyCollisions;
@@ -1,22 +1,22 @@
1
- /**
2
- * Object representing a line from the content of .properties file.
3
- */
4
- export declare class PropertyLine {
5
- /** The line content, minus the trailing \ that identifies that the line continues. */
6
- content: string;
7
- /** True if the line continues, otherwise false. */
8
- continues: boolean;
9
- /** True if the line is blank, otherwise false. */
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
- /**
16
- * Create a new line object.
17
- *
18
- * @param line - The raw content of a line.
19
- * @param isMultiline - Is the line spreading on multiple lines?
20
- */
21
- constructor(line: string, isMultiline: boolean);
22
- }
1
+ /**
2
+ * Object representing a line from the content of .properties file.
3
+ */
4
+ export declare class PropertyLine {
5
+ /** The line content, minus the trailing \ that identifies that the line continues. */
6
+ content: string;
7
+ /** True if the line continues, otherwise false. */
8
+ continues: boolean;
9
+ /** True if the line is blank, otherwise false. */
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
+ /**
16
+ * Create a new line object.
17
+ *
18
+ * @param line - The raw content of a line.
19
+ * @param isMultiline - Is the line spreading on multiple lines?
20
+ */
21
+ constructor(line: string, isMultiline: boolean);
22
+ }