properties-file 3.3.2 → 3.3.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.
@@ -61,12 +61,18 @@ export type UpsertOptions = {
61
61
  * A .properties file editor.
62
62
  */
63
63
  export declare class PropertiesEditor extends Properties {
64
+ /** Is line parsing required to re-async the object's properties? */
65
+ private needsLineParsing;
64
66
  /**
65
67
  * Create `PropertiesEditor` object.
66
68
  *
67
69
  * @param content - The content of a `.properties` file.
68
70
  */
69
71
  constructor(content: string);
72
+ /**
73
+ * Parse the `.properties` content line by line only when needed.
74
+ */
75
+ private parseLinesIfNeeded;
70
76
  /**
71
77
  * Insert a new property in the existing object (by default it will be at the end).
72
78
  *
@@ -1,8 +1,12 @@
1
- "use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertiesEditor=exports.DEFAULT_SEPARATOR=exports.DEFAULT_COMMENT_DELIMITER=void 0;var _escape=require("../escape"),_properties=require("../properties");function _toConsumableArray(a){return _arrayWithoutHoles(a)||_iterableToArray(a)||_unsupportedIterableToArray(a)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _iterableToArray(a){if("undefined"!=typeof Symbol&&null!=a[Symbol.iterator]||null!=a["@@iterator"])return Array.from(a)}function _arrayWithoutHoles(a){if(Array.isArray(a))return _arrayLikeToArray(a)}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),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)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createSuper(a){var b=_isNativeReflectConstruct();return function(){var c,d=_getPrototypeOf(a);if(b){var e=_getPrototypeOf(this).constructor;c=Reflect.construct(d,arguments,e)}else c=d.apply(this,arguments);return _possibleConstructorReturn(this,c)}}function _possibleConstructorReturn(a,b){if(b&&("object"===_typeof(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(a){return!1}}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}/** The default separator between keys and values. */var DEFAULT_SEPARATOR=exports.DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER=exports.DEFAULT_COMMENT_DELIMITER="#",PropertiesEditor=exports.PropertiesEditor=/*#__PURE__*/function(a){/**
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=exports.DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER=exports.DEFAULT_COMMENT_DELIMITER="#";/** The default character used as 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. */ /**
2
+ * A .properties file editor.
3
+ */class PropertiesEditor extends _properties.Properties{/** Is line parsing required to re-async the object's properties? */needsLineParsing=!1;/**
2
4
  * Create `PropertiesEditor` object.
3
5
  *
4
6
  * @param content - The content of a `.properties` file.
5
- */function b(a){return _classCallCheck(this,b),c.call(this,a)}/**
7
+ */constructor(a){super(a)}/**
8
+ * Parse the `.properties` content line by line only when needed.
9
+ */parseLinesIfNeeded(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)}/**
6
10
  * Insert a new property in the existing object (by default it will be at the end).
7
11
  *
8
12
  * @param key - A property key (unescaped).
@@ -10,56 +14,56 @@
10
14
  * @param options - Additional options.
11
15
  *
12
16
  * @returns True if the key was inserted, otherwise false.
13
- */_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"insert",value:function insert(a,b,c){var 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(function(a){return(0,_escape.escapeKey)(a,d)}).join("\\\n"),i=b.split(/\r?\n/).map(function(a){return(0,_escape.escapeValue)(a,d)}).join("\\\n"),j="".concat((null===c||void 0===c?void 0:c.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),k=void 0===(null===c||void 0===c?void 0:c.comment)?"":"".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.
14
- // Allow multiline values.
17
+ */insert(a,b,c){const d=c?.escapeUnicode||!1,e=c?.separator?" "===c.separator?" ":` ${c.separator} `:` ${DEFAULT_SEPARATOR} `.replace(" "," "),f=c?.referenceKey,g=c?.position||"after";f&&this.parseLinesIfNeeded();// Allow multiline keys.
18
+ const 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=`${c?.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,k=c?.comment===void 0?"":`${`${j}${c.comment}`.split(/\r?\n/).join(`\n${j}`)}\n`,l=`${k}${h}${e}${i}`.split(/\n/);// Allow multiline values.
15
19
  // Allow multiline comments.
16
- if(void 0===f){var m;return(m=this.lines).push.apply(m,_toConsumableArray(l)),this.parseLines(),!0}// Find the last occurrence of the reference key.
17
- var n=_toConsumableArray(this.collection).reverse().find(function(a){return a.key===f});// Insert the new property when a reference key defined only when found.
18
- if(n){var o,p,q="after"===g?n.endingLineNumber:null!==(o=null===(p=n.previousProperty)||void 0===p?void 0:p.endingLineNumber)&&void 0!==o?o:0;return this.lines=[].concat(_toConsumableArray(this.lines.slice(0,q)),_toConsumableArray(l),_toConsumableArray(this.lines.slice(q))),this.parseLines(),!0}return!1}/**
20
+ if(void 0===f)return this.lines.push(...l),this.needsLineParsing=!0,!0;else{// Find the last occurrence of the reference key.
21
+ const a=[...this.collection].reverse().find(a=>a.key===f);// Insert the new property when a reference key defined only when found.
22
+ if(a){const b="after"===g?a.endingLineNumber:a.previousProperty?.endingLineNumber??0;return this.lines=[...this.lines.slice(0,b),...l,...this.lines.slice(b)],this.needsLineParsing=!0,!0}return!1}}/**
19
23
  * Insert a new comment in the existing object (by default it will be at the end).
20
24
  *
21
25
  * @param comment - The comment to add.
22
26
  * @param options - Additional options.
23
27
  *
24
28
  * @returns True if the comment was inserted, otherwise false.
25
- */},{key:"insertComment",value:function insertComment(a,b){var 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).replace(/\r?\n/g,"\n".concat(e)).split(/\n/);// Allow multiline comments.
26
- if(void 0===c){var g;return(g=this.lines).push.apply(g,_toConsumableArray(f)),this.parseLines(),!0}// Find the last occurrence of the reference key.
27
- var h=_toConsumableArray(this.collection).reverse().find(function(a){return a.key===c});// Insert the new comment when a reference key defined only when found.
28
- if(h){var i,j,k="after"===d?h.endingLineNumber:null!==(i=null===(j=h.previousProperty)||void 0===j?void 0:j.endingLineNumber)&&void 0!==i?i:0;return this.lines=[].concat(_toConsumableArray(this.lines.slice(0,k)),_toConsumableArray(f),_toConsumableArray(this.lines.slice(k))),this.parseLines(),!0}return!1}/**
29
+ */insertComment(a,b){const c=b?.referenceKey,d=b?.position||"after";c&&this.parseLinesIfNeeded();// Allow multiline comments.
30
+ const e=`${b?.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,f=`${e}${a}`.replace(/\r?\n/g,`\n${e}`).split(/\n/);if(void 0===c)return this.lines.push(...f),this.needsLineParsing=!0,!0;else{// Find the last occurrence of the reference key.
31
+ const a=[...this.collection].reverse().find(a=>a.key===c);// Insert the new comment when a reference key defined only when found.
32
+ if(a){const b="after"===d?a.endingLineNumber:a.previousProperty?.endingLineNumber??0;return this.lines=[...this.lines.slice(0,b),...f,...this.lines.slice(b)],this.needsLineParsing=!0,!0}return!1}}/**
29
33
  * Delete the last occurrence of a given key from the existing object.
30
34
  *
31
35
  * @param key - The name of the key to delete.
32
36
  * @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
33
37
  *
34
38
  * @returns True if the key was deleted, otherwise false.
35
- */},{key:"delete",value:function _delete(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],c=_toConsumableArray(this.collection).reverse().find(function(b){return b.key===a});// Find the last occurrence of the key.
36
- if(c){var d,e,f=b?null!==(d=null===(e=c.previousProperty)||void 0===e?void 0:e.endingLineNumber)&&void 0!==d?d:0:c.startingLineNumber-1,g=c.endingLineNumber;return this.lines=[].concat(_toConsumableArray(this.lines.slice(0,f)),_toConsumableArray(this.lines.slice(g))),this.parseLines(),!0}return!1}/**
39
+ */delete(a){let b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];this.parseLinesIfNeeded();// Find the last occurrence of the key.
40
+ const c=[...this.collection].reverse().find(b=>b.key===a);if(c){const a=b?c.previousProperty?.endingLineNumber??0:c.startingLineNumber-1,d=c.endingLineNumber;return this.lines=[...this.lines.slice(0,a),...this.lines.slice(d)],this.needsLineParsing=!0,!0}return!1}/**
37
41
  * Restore the original newline characters of a key.
38
42
  *
39
43
  * @param property - A property object.
40
44
  *
41
45
  * @returns The key with its original newlines characters restored.
42
- */},{key:"getKeyWithNewlines",value:function getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce
43
- _toConsumableArray(a.key).reduce(function(b,c,d){return"".concat(b).concat(a.newlinePositions.includes(d)?"\n":"").concat(c)},"")}/**
46
+ */getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce
47
+ [...a.key].reduce((b,c,d)=>`${b}${a.newlinePositions.includes(d)?"\n":""}${c}`,"")}/**
44
48
  * Restore the original newline characters of a value.
45
49
  *
46
50
  * @param property - A property object.
47
51
  *
48
52
  * @returns The value with its original newlines characters restored.
49
- */},{key:"getValueWithNewlines",value:function getValueWithNewlines(a){return 0===a.newlinePositions.length||void 0===a.valuePosition?a.value:// eslint-disable-next-line unicorn/no-array-reduce
50
- _toConsumableArray(a.value).reduce(function(b,c,d){return"".concat(b).concat(a.newlinePositions.includes(d+a.valuePosition)?"\n":"").concat(c)},"")}/**
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)=>`${b}${a.newlinePositions.includes(d+a.valuePosition)?"\n":""}${c}`,"")}/**
51
55
  * Update the last occurrence of a given key from the existing object.
52
56
  *
53
57
  * @param key - The name of the key to update.
54
58
  * @param options - Additional options.
55
59
  *
56
60
  * @returns True if the key was updated, otherwise false.
57
- */},{key:"update",value:function update(a,b){var c,d,e,f,g=_toConsumableArray(this.collection).reverse().find(function(b){return b.key===a});// Find the last occurrence of the key to update.
58
- if(!g||!b)return!1;var 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(function(a){return(0,_escape.escapeKey)(a,h)}).join("\\\n"),k=(null!==(d=b.newValue)&&void 0!==d?d:this.getValueWithNewlines(g)).split(/\r?\n/).map(function(a){return(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.
61
+ */update(a,b){this.parseLinesIfNeeded();// Find the last occurrence of the key to update.
62
+ const c=[...this.collection].reverse().find(b=>b.key===a);if(!c||!b)return!1;const d=b.escapeUnicode||!1,e=b.separator?" "===b.separator?" ":` ${b.separator} `:c.separator||` ${DEFAULT_SEPARATOR} `.replace(" "," "),f=(b.newKey??this.getKeyWithNewlines(c)).split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,d)).join("\\\n"),g=(b.newValue??this.getValueWithNewlines(c)).split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,d)).join("\\\n"),h=`${b.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,i=void 0===b.newComment?"":`${`${h}${b.newComment}`.split(/\r?\n/).join(`\n${h}`)}\n`,j=`${i}${f}${e}${g}`.split(/\n/);// Allow multiline keys.
59
63
  // Allow multiline values.
60
64
  // Allow multiline comments.
61
65
  // Replace the existing property with the new one.
62
- return this.lines=[].concat(_toConsumableArray(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)),_toConsumableArray(n),_toConsumableArray(this.lines.slice(g.endingLineNumber))),this.parseLines(),!0}/**
66
+ return this.lines=[...this.lines.slice(0,void 0===b.newComment?c.startingLineNumber-1:c.previousProperty?.endingLineNumber??0),...j,...this.lines.slice(c.endingLineNumber)],this.needsLineParsing=!0,!0}/**
63
67
  * Update a key if it exist, otherwise add it at the end.
64
68
  *
65
69
  * @param key - A property key (unescaped).
@@ -67,6 +71,4 @@ return this.lines=[].concat(_toConsumableArray(this.lines.slice(0,void 0===b.new
67
71
  * @param options - Additional options.
68
72
  *
69
73
  * @returns True if the key was updated or inserted, otherwise false.
70
- */},{key:"upsert",value:function 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)}}]),b}(_properties.Properties);/** The default character used as 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. */ /**
71
- * A .properties file editor.
72
- */
74
+ */upsert(a,b,c){return this.parseLinesIfNeeded(),this.keyLineNumbers[a]?this.update(a,{newValue:b,newComment:c?.comment,commentDelimiter:c?.commentDelimiter,separator:c?.separator,escapeUnicode:c?.escapeUnicode}):this.insert(a,b,c)}}exports.PropertiesEditor=PropertiesEditor;
@@ -5,14 +5,14 @@
5
5
  * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
6
6
  *
7
7
  * @return The escaped key.
8
- */var escapeKey=exports.escapeKey=function(a){var b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!0,b)},escapeValue=exports.escapeValue=function(a){var b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!1,b)},escapeContent=function(a,b,c){return a.replace(new RegExp("[\\s!#:=\\\\".concat(c?"\\u0000-\\u001F\\u007F-\\uFFFF":"","]"),"g"),function(a,c){return" "===a?b||0===c?"\\ ":" ":"\\"===a?"\\\\":"\f"===a?"\\f":"\n"===a?"\\n":"\r"===a?"\\r":"\t"===a?"\\t":"="===a||":"===a||"#"===a||"!"===a?"\\".concat(a):"\\u".concat(a.codePointAt(0).toString(16).padStart(4,"0"))})};/**
8
+ */const escapeKey=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!0,b)};/**
9
9
  * Escape property value.
10
10
  *
11
11
  * @param unescapedValue - Property value to be escaped.
12
12
  * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
13
13
  *
14
14
  * @return The escaped value.
15
- */ /**
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
16
  * Escape the content from either key or value of a property.
17
17
  *
18
18
  * @param unescapedContent - The content to escape.
@@ -20,4 +20,4 @@
20
20
  * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
21
21
  *
22
22
  * @returns The escaped content.
23
- */
23
+ */exports.escapeValue=escapeValue;const escapeContent=(a,b,c)=>a.replace(new RegExp(`[\\s!#:=\\\\${c?"\\u0000-\\u001F\\u007F-\\uFFFF":""}]`,"g"),(a,c)=>" "===a?b||0===c?"\\ ":" ":"\\"===a?"\\\\":"\f"===a?"\\f":"\n"===a?"\\n":"\r"===a?"\\r":"\t"===a?"\\t":"="===a||":"===a||"#"===a||"!"===a?`\\${a}`:`\\u${a.codePointAt(0).toString(16).padStart(4,"0")}`);
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function get(){return _properties.Properties}}),exports.getProperties=void 0;var _properties=require("./properties"),getProperties=exports.getProperties=function(a){return new _properties.Properties(a).toObject()};/**
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
2
  * A key-value pair object.
3
3
  */ /**
4
4
  * Converts the content of a `.properties` file to a key-value pair object.
@@ -6,4 +6,4 @@
6
6
  * @param content - The content of a `.properties` file.
7
7
  *
8
8
  * @returns A key/value object representing the content of a `.properties` file.
9
- */
9
+ */const getProperties=a=>new _properties.Properties(a).toObject();exports.getProperties=getProperties;
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _=require(".."),webpackLoader=function(a){return"module.exports = ".concat(JSON.stringify((0,_.getProperties)(a)),";")},_default=exports.default=webpackLoader;/**
1
+ "use strict";var _=require("..");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/**
2
2
  * Webpack file loader for `.properties` files.
3
3
  *
4
4
  * @param content - the content of a `.properties` file.
5
5
  *
6
6
  * @returns A Webpack file loader string containing the content of a `.properties` file.
7
- */
7
+ */const webpackLoader=a=>`module.exports = ${JSON.stringify((0,_.getProperties)(a))};`;var _default=exports.default=webpackLoader;
package/lib/properties.js CHANGED
@@ -1,51 +1,52 @@
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;var _property=require("./property"),_propertyLine=require("./property-line");function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _slicedToArray(a,b){return _arrayWithHoles(a)||_iterableToArrayLimit(a,b)||_unsupportedIterableToArray(a,b)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d.return&&(k=d.return(),Object(k)!==k))return}finally{if(m)throw h}}return l}}function _arrayWithHoles(a){if(Array.isArray(a))return a}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}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)}/**
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;var _property=require("./property"),_propertyLine=require("./property-line");/**
2
2
  * Byte-order mark.
3
- */var BOM=exports.BOM="\uFEFF",BOM_CODE_POINT=exports.BOM_CODE_POINT=BOM.codePointAt(0),DEFAULT_END_OF_LINE_CHARACTER=exports.DEFAULT_END_OF_LINE_CHARACTER="\n",getFirstEolCharacter=exports.getFirstEolCharacter=function(a){var b=a.indexOf("\n");return 0>b?void 0:"".concat("\r"===a[b-1]?"\r":"","\n")},Properties=exports.Properties=/*#__PURE__*/function(){/**
3
+ */const BOM=exports.BOM="\uFEFF",BOM_CODE_POINT=exports.BOM_CODE_POINT=BOM.codePointAt(0),DEFAULT_END_OF_LINE_CHARACTER=exports.DEFAULT_END_OF_LINE_CHARACTER="\n",getFirstEolCharacter=a=>{const b=a.indexOf("\n");return 0>b?void 0:`${"\r"===a[b-1]?"\r":""}\n`};/** The default end of line character. */ /**
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
+ */ /**
10
+ * A class representing the content of a .properties file.
11
+ */exports.getFirstEolCharacter=getFirstEolCharacter;class Properties{/** Does the .properties content starts with a BOM character? */ /** The end of line character. */ /** `.properties` content split by line. */ /** The collection of property object. */collection=[];/** Object associating keys with their starting line numbers. */keyLineNumbers={};/**
4
12
  * Create `Properties` object.
5
13
  *
6
14
  * @param content - The content of a `.properties` file.
7
- */function a(b){var c;_classCallCheck(this,a),_defineProperty(this,"collection",[]),_defineProperty(this,"keyLineNumbers",{});var d="string"==typeof b?b:b.toString();this.hasBom=d.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=null!==(c=getFirstEolCharacter(d))&&void 0!==c?c:DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?d.slice(1):d).split(/\r?\n/),this.parseLines()}/**
15
+ */constructor(a){const b="string"==typeof a?a:a.toString();this.hasBom=b.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=getFirstEolCharacter(b)??DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?b.slice(1):b).split(/\r?\n/),this.parseLines()}/**
8
16
  * Parse the `.properties` content line by line.
9
- */return _createClass(a,[{key:"parseLines",value:function parseLines(){this.collection=[],this.keyLineNumbers={};/** Line number while parsing properties file content. */var a,b,c,d=0,e=_createForOfIteratorHelper(this.lines);/** The current property object being parsed. */ /** The previous property object that was parsed. */try{for(e.s();!(c=e.n()).done;){var f=c.value;d++;var g=new _propertyLine.PropertyLine(f,!!a);if(!a){// Check if the line is a new property.
10
- if(g.isComment||g.isBlank)continue;// Skip line if its a comment or blank.
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.
11
19
  // The line is a new property.
12
- if(a=new _property.Property(g,d,b),g.isContinuing)continue;// Continue parsing the next line.
13
- }else if(a.addLine(g),g.isContinuing)continue;// If the line does not continue, add the property to the collection.
14
- this.addToCollection(a),b=a,a=void 0}}catch(a){e.e(a)}finally{e.f()}}/**
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}}/**
15
23
  * Add a property object into a properties object collection.
16
24
  *
17
25
  * @param property - A property object, or undefined.
18
26
  *
19
27
  * @returns Undefined so that we conveniently overwrite the property object.
20
- */},{key:"addToCollection",value:function addToCollection(a){var b;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(function(b){return b.key!==a.key})):this.keyLineNumbers[a.key]=[a.startingLineNumber],this.collection.push(a)}/**
28
+ */addToCollection(a){// Add the property to the collection.
29
+ a.setKeyAndValue(),this.keyLineNumbers[a.key]?.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)}/**
21
30
  * Get keys that have collisions (more than one occurrence).
22
- */},{key:"getKeyCollisions",value:function getKeyCollisions(){for(var a=[],b=0,c=Object.entries(this.keyLineNumbers);b<c.length;b++){var d=_slicedToArray(c[b],2),e=d[0],f=d[1];1<f.length&&a.push(new KeyCollisions(e,f))}return a}/**
31
+ */getKeyCollisions(){const a=[];for(const[b,c]of Object.entries(this.keyLineNumbers))1<c.length&&a.push(new KeyCollisions(b,c));return a}/**
23
32
  * Get the key/value object representing the properties.
24
33
  *
25
34
  * @returns A key/value object representing the properties.
26
- */},{key:"toObject",value:function toObject(){var a={};return this.collection.forEach(function(b){a[b.key]=b.value}),a}/**
35
+ */toObject(){const a={};return this.collection.forEach(b=>{a[b.key]=b.value}),a}/**
27
36
  * Format the object in `.properties`.
28
37
  *
29
38
  * @param endOfLineCharacter - The character used for end of lines.
30
39
  *
31
40
  * @returns The object in `.properties` format.
32
- */},{key:"format",value:function format(a){return"".concat(this.hasBom?BOM:"").concat(this.lines.join(a||this.eolCharacter))}}]),a}(),KeyCollisions=exports.KeyCollisions=/*#__PURE__*/function(){/** The key with collisions. */ /** The starting line numbers where collisions are found. */ /**
41
+ */format(a){return`${this.hasBom?BOM:""}${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. */ /**
33
46
  * Create a new key collision object.
34
47
  *
35
48
  * @param key - The key with collisions.
36
49
  * @param startingLineNumbers - The starting line numbers where collisions are found.
37
- */function a(b,c){_classCallCheck(this,a),this.key=b,this.startingLineNumbers=c}/**
50
+ */constructor(a,b){this.key=a,this.startingLineNumbers=b}/**
38
51
  * Get the number of the line from which the value will be used.
39
- */return _createClass(a,[{key:"getApplicableLineNumber",value:function getApplicableLineNumber(){return this.startingLineNumbers.slice(-1)[0]}}]),a}();/** The default end of line character. */ /**
40
- * Get the first end of line (EOL) character from multiline content.
41
- *
42
- * @param content - The content of a `.properties` file.
43
- *
44
- * @returns The multiline content's first end of line (EOL) character.
45
- */ /**
46
- * A class representing the content of a .properties file.
47
- */ /**
48
- * Object associating keys with their line numbers.
49
- */ /**
50
- * A class representing key within a .properties file that had collisions (more than one occurrence).
51
- */
52
+ */getApplicableLineNumber(){return this.startingLineNumbers.slice(-1)[0]}}exports.KeyCollisions=KeyCollisions;
@@ -1,9 +1,9 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _wrapRegExp(){function a(b,c,e){var f=new RegExp(b,c);return d.set(f,e||d.get(b)),_setPrototypeOf(f,a.prototype)}function b(a,b){var c=d.get(b);return Object.keys(c).reduce(function(b,d){var e=c[d];if("number"==typeof e)b[d]=a[e];else{for(var f=0;void 0===a[e[f]]&&f+1<e.length;)f++;b[d]=a[e[f]]}return b},Object.create(null))}_wrapRegExp=function(b,c){return new a(b,void 0,c)};var c=RegExp.prototype,d=new WeakMap;return _inherits(a,RegExp),a.prototype.exec=function(a){var d=c.exec.call(this,a);if(d){d.groups=b(d,this);var e=d.indices;e&&(e.groups=b(e,this))}return d},a.prototype[Symbol.replace]=function(a,f){if("string"==typeof f){var g=d.get(this);return c[Symbol.replace].call(this,a,f.replace(/\$<([^>]+)>/g,function(a,b){var c=g[b];return"$"+(Array.isArray(c)?c.join("$"):c)}))}if("function"==typeof f){var h=this;return c[Symbol.replace].call(this,a,function(){var a=arguments;return"object"!=_typeof(a[a.length-1])&&(a=[].slice.call(a)).push(b(a,h)),f.apply(this,a)})}return c[Symbol.replace].call(this,a,f)},_wrapRegExp.apply(this,arguments)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}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)}/**
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;/**
2
2
  * Object representing a line from the content of .properties file.
3
- */var PropertyLine=exports.PropertyLine=/*#__PURE__*/_createClass(/** Is the line object a continuation from a previous line? */ /**
3
+ */class PropertyLine{/** The line content, minus the trailing \ that identifies that the line is continuing. */ /** True if the line is continuing to the next line, otherwise false. */isContinuing=!1;/** True if the line is blank, otherwise false. */isBlank=!1;/** True if the line is a comment, otherwise false. */isComment=!1;/** Is the line object a continuation from a previous line? */ /**
4
4
  * Create a new line object.
5
5
  *
6
6
  * @param line - The raw content of a line.
7
7
  * @param isMultiline - Is the line spreading on multiple lines?
8
- */function c(a,b){if(_classCallCheck(this,c),_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
- var d=this.content.match(/*#__PURE__*/_wrapRegExp(/(\\+)$/,{backslashes:1}));null!==d&&void 0!==d&&d.groups&&(this.isContinuing=!!(d.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}});
8
+ */constructor(a,b){if(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>\\+)$/);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,21 +1,21 @@
1
- "use strict";var _unescape=require("./unescape");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _wrapRegExp(){function a(b,c,e){var f=new RegExp(b,c);return d.set(f,e||d.get(b)),_setPrototypeOf(f,a.prototype)}function b(a,b){var c=d.get(b);return Object.keys(c).reduce(function(b,d){var e=c[d];if("number"==typeof e)b[d]=a[e];else{for(var f=0;void 0===a[e[f]]&&f+1<e.length;)f++;b[d]=a[e[f]]}return b},Object.create(null))}_wrapRegExp=function(b,c){return new a(b,void 0,c)};var c=RegExp.prototype,d=new WeakMap;return _inherits(a,RegExp),a.prototype.exec=function(a){var d=c.exec.call(this,a);if(d){d.groups=b(d,this);var e=d.indices;e&&(e.groups=b(e,this))}return d},a.prototype[Symbol.replace]=function(a,f){if("string"==typeof f){var g=d.get(this);return c[Symbol.replace].call(this,a,f.replace(/\$<([^>]+)>/g,function(a,b){var c=g[b];return"$"+(Array.isArray(c)?c.join("$"):c)}))}if("function"==typeof f){var h=this;return c[Symbol.replace].call(this,a,function(){var a=arguments;return"object"!=_typeof(a[a.length-1])&&(a=[].slice.call(a)).push(b(a,h)),f.apply(this,a)})}return c[Symbol.replace].call(this,a,f)},_wrapRegExp.apply(this,arguments)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _createForOfIteratorHelper(a,b){var c="undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(!c){if(Array.isArray(a)||(c=_unsupportedIterableToArray(a))||b&&a&&"number"==typeof a.length){c&&(a=c);var d=0,e=function(){};return{s:e,n:function n(){return d>=a.length?{done:!0}:{done:!1,value:a[d++]}},e:function e(a){throw a},f:e}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var f,g=!0,h=!1;return{s:function s(){c=c.call(a)},n:function n(){var a=c.next();return g=a.done,a},e:function e(a){h=!0,f=a},f:function f(){try{g||null==c.return||c.return()}finally{if(h)throw f}}}}function _unsupportedIterableToArray(a,b){if(a){if("string"==typeof a)return _arrayLikeToArray(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?_arrayLikeToArray(a,b):void 0}}function _arrayLikeToArray(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,_toPropertyKey(c.key),c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}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)}/**
1
+ "use strict";var _unescape=require("./unescape");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;/**
2
2
  * Object representing a property (key/value).
3
- */var Property=exports.Property=/*#__PURE__*/function(){/** 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. */ /**
3
+ */class Property{/** The content of one or multiple lines when applicable. */ /** The property key (unescaped). */key="";/** The property key, including its escaped characters. */escapedKey="";/** Is the key empty? */hasNoKey=!1;/** Does the key definition spread across multiple lines? */hasMultilineKey=!1;/** Starting line numbers of property objects with the same key. */keyCollisionLines=[];/** Was the property's key used more than once? */hasKeyCollisions=!1;/** The key/value pair separator */ /** The length of the key/value pair separator, including its whitespace characters. */ /** The starting position of the key/value pair separator. */ /** The property value (unescaped). */value="";/** The starting position of the value. */ /** The property value, including its escaped characters. */escapedValue="";/** Is the value empty? */hasNoValue=!1;/** Positions of the newline characters if any. */newlinePositions=[];/** 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
4
  * Create a new property object.
5
5
  *
6
6
  * @param propertyLine - A property line object.
7
7
  * @param startingLineNumber - The line number at which the property starts.
8
- */function a(b,c,d){_classCallCheck(this,a),_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=b.content,this.startingLineNumber=c,this.endingLineNumber=c,this.previousProperty=d,null===d||void 0===d||d.setNextProperty(this)}/**
8
+ */constructor(a,b,c){this.linesContent=a.content,this.startingLineNumber=b,this.endingLineNumber=b,this.previousProperty=c,c?.setNextProperty(this)}/**
9
9
  * Set the next property object.
10
10
  *
11
11
  * @param property - The next property object
12
- */return _createClass(a,[{key:"setNextProperty",value:function setNextProperty(a){this.nextProperty=a}/**
12
+ */setNextProperty(a){this.nextProperty=a}/**
13
13
  * Add the a line to a multiline property object.
14
14
  *
15
15
  * @param propertyLine - A property line object.
16
- */},{key:"addLine",value:function addLine(a){0<this.linesContent.length&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=a.content}/**
16
+ */addLine(a){0<this.linesContent.length&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=a.content}/**
17
17
  * Set the property's key and value.
18
- */},{key:"setKeyAndValue",value:function setKeyAndValue(){this.findSeparator(),void 0!==this.separatorPosition&&void 0!==this.separatorLength?(!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))}/**
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
19
  * Unescape the content from either key or value of a property.
20
20
  *
21
21
  * @param escapedContent - The content to unescape.
@@ -25,15 +25,15 @@
25
25
  *
26
26
  * @throws {@link Error}
27
27
  * This exception is thrown if malformed escaped unicode characters are present.
28
- */},{key:"unescapeLine",value:function unescapeLine(a,b){try{return(0,_unescape.unescapeContent)(a)}catch(a){throw new Error("".concat(a.message," in property starting at line ").concat(b))}}/**
28
+ */unescapeLine(a,b){try{return(0,_unescape.unescapeContent)(a)}catch(a){throw new Error(`${a.message} in property starting at line ${b}`)}}/**
29
29
  * Find the character separating the key from the value.
30
- */},{key:"findSeparator",value:function findSeparator(){// If the separator was already found, skip.
30
+ */findSeparator(){// If the separator was already found, skip.
31
31
  if(!(this.hasNoKey||this.hasNoValue||this.separatorPosition)){// Only match separators to avoid iterating all characters.
32
- var a,b=_createForOfIteratorHelper(this.linesContent.matchAll(/[\t\f :=]/g));try{for(b.s();!(a=b.n()).done;){var c,d=a.value,e=d.index,f=this.linesContent.slice(0,e),g=f.match(/*#__PURE__*/_wrapRegExp(/(\\+)$/,{backslashes:1}));// Check if the separator might be escaped.
33
- if(null!==g&&void 0!==g&&g.groups){var h=!!(g.groups.backslashes.length%2);if(h)// If the separator is escaped, check the next character.
34
- continue}var i="";this.separatorPosition=e;// Check if the separator starts with a whitespace.
35
- var j=this.linesContent.slice(e),k=j.match(/*#__PURE__*/_wrapRegExp(/^([\t\n\v\f\r ]+)/,{whitespace:1})),l=(null===k||void 0===k||null===(c=k.groups)||void 0===c?void 0:c.whitespace)||"";// All white-space characters, excluding non-breaking spaces.
36
- // If there is a whitespace, move to the next character.
32
+ for(const a of this.linesContent.matchAll(/[\t\f :=]/g)){const b=a.index,c=this.linesContent.slice(0,b),d=c.match(/(?<backslashes>\\+)$/);// Check if the separator might be escaped.
33
+ if(d?.groups){const a=!!(d.groups.backslashes.length%2);if(a)// If the separator is escaped, check the next character.
34
+ continue}let e="";this.separatorPosition=b;// Check if the separator starts with a whitespace.
35
+ let f=this.linesContent.slice(b);// All white-space characters, excluding non-breaking spaces.
36
+ const g=f.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),h=g?.groups?.whitespace||"";// If there is a whitespace, move to the next character.
37
37
  // Check if there is an equal or colon character.
38
- if(0<l.length&&(i+=l,j=j.slice(l.length)),/[:=]/.test(j[0])){var m;i+=j[0],j=j.slice(1);// If an equal or colon character was found, try to get trailing whitespace.
39
- var n=j.match(/*#__PURE__*/_wrapRegExp(/^([\t\n\v\f\r ]+)/,{whitespace:1})),o=(null===n||void 0===n||null===(m=n.groups)||void 0===m?void 0:m.whitespace)||"";i+=o}this.separatorLength=i.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),e||(this.hasNoKey=!0);break}}catch(a){b.e(a)}finally{b.f()}void 0===this.separatorPosition?this.hasNoValue=!0:0<this.newlinePositions.length&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}}}]),a}();
38
+ if(0<h.length&&(e+=h,f=f.slice(h.length)),/[:=]/.test(f[0])){e+=f[0],f=f.slice(1);// If an equal or colon character was found, try to get trailing whitespace.
39
+ const a=f.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),b=a?.groups?.whitespace||"";e+=b}this.separatorLength=e.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),b||(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;
@@ -7,11 +7,11 @@
7
7
  *
8
8
  * @throws {@link Error}
9
9
  * This exception is thrown if malformed escaped unicode characters are present.
10
- */var unescapeContent=exports.unescapeContent=function(a){return(// By using a regular expression we avoid iterating through all characters and improve performance.
11
- a.replace(/\\[^u]|\\u.{4}/g,function(a){var b=a.charAt(1);switch(b){case"f":// Formfeed.
10
+ */const unescapeContent=a=>// By using a regular expression we avoid iterating through all characters and improve performance.
11
+ a.replace(/\\[^u]|\\u.{4}/g,a=>{const b=a.charAt(1);switch(b){case"f":// Formfeed.
12
12
  return"\f";case"n":// Newline.
13
13
  return"\n";case"r":// Carriage return.
14
14
  return"\r";case"t":// Tab.
15
15
  return"\t";case"u":{// Unicode character.
16
- var c=a.slice(2,6);if(!/[\da-f]{4}/i.test(c))// Code point can only be within Unicode's Multilingual Plane (BMP).
17
- throw new Error("malformed escaped unicode characters '\\u".concat(c,"'"));return String.fromCodePoint(Number.parseInt(c,16))}default:return b}}))};
16
+ const b=a.slice(2,6);if(!/[\da-f]{4}/i.test(b))// Code point can only be within Unicode's Multilingual Plane (BMP).
17
+ throw new Error(`malformed escaped unicode characters '\\u${b}'`);return String.fromCodePoint(Number.parseInt(b,16))}default:return b}});exports.unescapeContent=unescapeContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "properties-file",
3
- "version": "3.3.2",
3
+ "version": "3.3.4",
4
4
  "description": ".properties file parser, editor, formatter and Webpack loader.",
5
5
  "keywords": [
6
6
  ".properties",
@@ -64,9 +64,9 @@
64
64
  },
65
65
  "devDependencies": {
66
66
  "@babel/cli": "^7.23.0",
67
- "@babel/core": "^7.23.0",
68
- "@babel/preset-env": "^7.22.20",
69
- "@babel/preset-typescript": "7.23.0",
67
+ "@babel/core": "^7.23.2",
68
+ "@babel/preset-env": "^7.23.2",
69
+ "@babel/preset-typescript": "7.23.2",
70
70
  "@release-it/conventional-changelog": "7.0.2",
71
71
  "@types/jest": "29.5.5",
72
72
  "@typescript-eslint/eslint-plugin": "6.7.5",