properties-file 3.3.1 → 3.3.3

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/README.md CHANGED
@@ -270,7 +270,7 @@ Just like Java, if a Unicode-escaped character (`\u`) is malformed, an error wil
270
270
 
271
271
  ## Additional references
272
272
 
273
- - Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-uSOlNK)
273
+ - Java [Test Sandbox](https://codehs.com/sandbox/id/java-main-FObePj)
274
274
  - Java's `Properties` class [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/Properties.html)
275
275
  - Java's `PropertyResourceBundle` [documentation](https://docs.oracle.com/javase/9/docs/api/java/util/PropertyResourceBundle.html)
276
276
  - Java's Internationalization [Guide](https://docs.oracle.com/en/java/javase/18/intl/internationalization-overview.html)
@@ -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,10 @@
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");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 _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 _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)}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)}/** 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){/**
2
2
  * Create `PropertiesEditor` object.
3
3
  *
4
4
  * @param content - The content of a `.properties` file.
5
- */function b(a){return _classCallCheck(this,b),c.call(this,a)}/**
5
+ */function b(a){var d;return _classCallCheck(this,b),d=c.call(this,a),_defineProperty(_assertThisInitialized(d),"needsLineParsing",!1),d}/**
6
+ * Parse the `.properties` content line by line only when needed.
7
+ */_inherits(b,a);var c=_createSuper(b);return _createClass(b,[{key:"parseLinesIfNeeded",value:function parseLinesIfNeeded(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)}/**
6
8
  * Insert a new property in the existing object (by default it will be at the end).
7
9
  *
8
10
  * @param key - A property key (unescaped).
@@ -10,30 +12,30 @@
10
12
  * @param options - Additional options.
11
13
  *
12
14
  * @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.
15
+ */},{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";f&&this.parseLinesIfNeeded();// Allow multiline keys.
16
+ var 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 values.
15
17
  // 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.
18
+ if(void 0===f){var m;return(m=this.lines).push.apply(m,_toConsumableArray(l)),this.needsLineParsing=!0,!0}// Find the last occurrence of the reference key.
17
19
  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(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.needsLineParsing=!0,!0}return!1}/**
19
21
  * Insert a new comment in the existing object (by default it will be at the end).
20
22
  *
21
23
  * @param comment - The comment to add.
22
24
  * @param options - Additional options.
23
25
  *
24
26
  * @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
+ */},{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";c&&this.parseLinesIfNeeded();// Allow multiline comments.
28
+ var 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/);if(void 0===c){var g;return(g=this.lines).push.apply(g,_toConsumableArray(f)),this.needsLineParsing=!0,!0}// Find the last occurrence of the reference key.
27
29
  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}/**
30
+ 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.needsLineParsing=!0,!0}return!1}/**
29
31
  * Delete the last occurrence of a given key from the existing object.
30
32
  *
31
33
  * @param key - The name of the key to delete.
32
34
  * @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
33
35
  *
34
36
  * @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}/**
37
+ */},{key:"delete",value:function _delete(a){var b=!(1<arguments.length&&void 0!==arguments[1])||arguments[1];this.parseLinesIfNeeded();// Find the last occurrence of the key.
38
+ var c=_toConsumableArray(this.collection).reverse().find(function(b){return b.key===a});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.needsLineParsing=!0,!0}return!1}/**
37
39
  * Restore the original newline characters of a key.
38
40
  *
39
41
  * @param property - A property object.
@@ -54,12 +56,12 @@ _toConsumableArray(a.value).reduce(function(b,c,d){return"".concat(b).concat(a.n
54
56
  * @param options - Additional options.
55
57
  *
56
58
  * @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.
59
+ */},{key:"update",value:function update(a,b){var c,d,e,f;this.parseLinesIfNeeded();// Find the last occurrence of the key to update.
60
+ var g=_toConsumableArray(this.collection).reverse().find(function(b){return b.key===a});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.
59
61
  // Allow multiline values.
60
62
  // Allow multiline comments.
61
63
  // 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}/**
64
+ 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.needsLineParsing=!0,!0}/**
63
65
  * Update a key if it exist, otherwise add it at the end.
64
66
  *
65
67
  * @param key - A property key (unescaped).
@@ -67,6 +69,6 @@ return this.lines=[].concat(_toConsumableArray(this.lines.slice(0,void 0===b.new
67
69
  * @param options - Additional options.
68
70
  *
69
71
  * @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. */ /**
72
+ */},{key:"upsert",value:function upsert(a,b,c){return this.parseLinesIfNeeded(),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
73
  * A .properties file editor.
72
74
  */
package/lib/property.js CHANGED
@@ -1,4 +1,4 @@
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 _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;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)}/**
2
2
  * Object representing a property (key/value).
3
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. */ /**
4
4
  * Create a new property object.
@@ -28,12 +28,12 @@
28
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))}}/**
29
29
  * Find the character separating the key from the value.
30
30
  */},{key:"findSeparator",value:function findSeparator(){// If the separator was already found, skip.
31
- if(!(this.hasNoKey||this.hasNoValue||this.separatorPosition)){for(var a=this.linesContent[0],b=0;b<this.linesContent.length;b++,a=this.linesContent[b]){var c;// If the character is not a separator, check the next one.
32
- if(/[\t\f :=]/.test(a)){// Check if the separator might be escaped.
33
- var d=b?this.linesContent.slice(0,b):"";if(0<d.length){var e=d.match(/*#__PURE__*/_wrapRegExp(/(\\+)$/,{backslashes:1}));if(null!==e&&void 0!==e&&e.groups){var f=!!(e.groups.backslashes.length%2);if(f)// If the separator is escaped, check the next character.
34
- continue}}var g="";this.separatorPosition=b;// Check if the separator starts with a whitespace.
35
- var h=this.linesContent.slice(b),i=h.match(/*#__PURE__*/_wrapRegExp(/^([\t\n\v\f\r ]+)/,{whitespace:1})),j=(null===i||void 0===i||null===(c=i.groups)||void 0===c?void 0:c.whitespace)||"";// All white-space characters, excluding non-breaking spaces.
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
36
  // If there is a whitespace, move to the next character.
37
37
  // Check if there is an equal or colon character.
38
- if(0<j.length&&(g+=j,h=h.slice(j.length)),/[:=]/.test(h[0])){var k;g+=h[0],h=h.slice(1);// If an equal or colon character was found, try to get trailing whitespace.
39
- var l=h.match(/*#__PURE__*/_wrapRegExp(/^([\t\n\v\f\r ]+)/,{whitespace:1})),m=(null===l||void 0===l||null===(k=l.groups)||void 0===k?void 0:k.whitespace)||"";g+=m}this.separatorLength=g.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)}}}]),a}();
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}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "properties-file",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": ".properties file parser, editor, formatter and Webpack loader.",
5
5
  "keywords": [
6
6
  ".properties",
@@ -82,7 +82,7 @@
82
82
  "eslint-plugin-jest": "27.4.2",
83
83
  "eslint-plugin-json-files": "3.0.0",
84
84
  "eslint-plugin-prefer-arrow-functions": "3.1.4",
85
- "eslint-plugin-prettier": "5.0.0",
85
+ "eslint-plugin-prettier": "5.0.1",
86
86
  "eslint-plugin-tsdoc": "0.2.17",
87
87
  "eslint-plugin-unicorn": "48.0.1",
88
88
  "jest": "29.7.0",