properties-file 5.0.4 → 5.0.5

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.
@@ -104,21 +104,21 @@ export type DeleteOptions = {
104
104
  */
105
105
  export declare class PropertiesEditor extends Properties {
106
106
  /**
107
- * Find the index of the first property node with the given key.
107
+ * Find the first property node with the given key.
108
108
  *
109
109
  * @param key - The unescaped key to search for.
110
110
  *
111
- * @returns The index in `this.nodes`, or `-1` if not found.
111
+ * @returns The matching node and its index in `this.nodes`, or `undefined`.
112
112
  */
113
- private findFirstPropertyIndex;
113
+ private findFirstProperty;
114
114
  /**
115
- * Find the index of the last property node with the given key.
115
+ * Find the last property node with the given key.
116
116
  *
117
117
  * @param key - The unescaped key to search for.
118
118
  *
119
- * @returns The index in `this.nodes`, or `-1` if not found.
119
+ * @returns The matching node and its index in `this.nodes`, or `undefined`.
120
120
  */
121
- private findLastPropertyIndex;
121
+ private findLastProperty;
122
122
  /**
123
123
  * Insert a new property.
124
124
  *
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"PropertiesEditor",{enumerable:!0,get:function(){return PropertiesEditor}});var _index=require("../escape/index.js"),_properties=require("../parser/properties.js");function _instanceof(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _assert_this_initialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _call_super(e,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!_instanceof(e,r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}function _get_prototype_of(e){return _get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},_get_prototype_of(e)}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){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 _possible_constructor_return(e,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}function _is_native_reflect_construct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_is_native_reflect_construct=function(){return!!e})()}var DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER="#",REGEX_NEWLINE=/\r\n|\r|\n/,buildPropertyNode=function(e,r,t,n){var o,i=!0===t.escapeUnicode,a=(0,_index.escapeKey)(e,i),s=(0,_index.escapeValue)(r,i),l=" "===t.separator?void 0:null!==(o=t.separator)&&void 0!==o?o:DEFAULT_SEPARATOR,c=l?" ":"",u=l?"".concat(" ").concat(l).concat(c):" ",p="".concat(a).concat(u).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:p,leadingWhitespace:"",key:e,escapedKey:a,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){var r=1,t=!0,n=!1,o=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var s=i.value;if("property"===s.type){var l=s.rawLines.length;s.startingLineNumber=r,s.endingLineNumber=r+l-1,r+=l}else s.lineNumber=r,r++}}catch(e){n=!0,o=e}finally{try{t||null==a.return||a.return()}finally{if(n)throw o}}},PropertiesEditor=function(){function e(){return _class_call_check(this,e),_call_super(this,e,arguments)}return _inherits(e,_properties.Properties),_create_class(e,[{key:"findFirstPropertyIndex",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"findLastPropertyIndex",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"insert",value:function(e,r,t){var n,o,i=[];if(void 0!==(null==t?void 0:t.comment)){var a,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(a=i).push.apply(a,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(i.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastPropertyIndex(t.referenceKey);if(-1!==l){var c,u="before"===t.position?l:l+1;return(c=this.nodes).splice.apply(c,[u,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(n=this.nodes).push.apply(n,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertComment",value:function(e,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,i=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var a=this.findLastPropertyIndex(r.referenceKey);if(-1!==a){var s,l="before"===r.position?a:a+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastPropertyIndex(e.referenceKey);if(-1!==t){var n="before"===e.position?t:t+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,i=this.findLastPropertyIndex(e);if(-1===i)return!1;var a=this.nodes[i],s=null!==(t=r.newKey)&&void 0!==t?t:a.key,l=null!==(n=r.newValue)&&void 0!==n?n:a.value,c=!0===r.escapeUnicode,u=c?(0,_index.escapeKey)(s,!0):void 0!==r.newKey?(0,_index.escapeKey)(s):a.escapedKey,p=c?(0,_index.escapeValue)(l,!0):void 0!==r.newValue?(0,_index.escapeValue)(l):a.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:a.separatorChar,d=r.separator?" ":a.separatorLeading,y=r.separator?_?" ":"":a.separatorTrailing,f=_?"".concat(d).concat(_).concat(y):d,m="".concat(u).concat(f).concat(p).split(REGEX_NEWLINE),h={type:"property",rawLines:m,leadingWhitespace:a.leadingWhitespace,key:s,escapedKey:u,separatorLeading:d,separatorChar:_,separatorTrailing:y,value:l,escapedValue:p,startingLineNumber:a.startingLineNumber,endingLineNumber:a.startingLineNumber+m.length-1};if(void 0!==r.newComment){for(var v,b=i,L=i-1;L>=0&&"property"!==this.nodes[L].type;L--)b=L;var E=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,g=buildCommentNodes(r.newComment,E,0);(v=this.nodes).splice.apply(v,[b,i-b+1].concat(_to_consumable_array(g),[h]))}else this.nodes[i]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){-1!==this.findLastPropertyIndex(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstPropertyIndex(e):this.findLastPropertyIndex(e);if(-1!==t){var n=this.nodes[t];if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var o=t,i=t-1;i>=0&&"property"!==this.nodes[i].type;i--)o=i;this.nodes.splice(o,t-o+1)}else this.nodes.splice(t,1);return recalculateLineNumbers(this.nodes),n}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),e}();
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"PropertiesEditor",{enumerable:!0,get:function(){return PropertiesEditor}});var _index=require("../escape/index.js"),_properties=require("../parser/properties.js");function _instanceof(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _assert_this_initialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _call_super(e,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!_instanceof(e,r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}function _get_prototype_of(e){return _get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},_get_prototype_of(e)}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){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 _possible_constructor_return(e,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}function _is_native_reflect_construct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_is_native_reflect_construct=function(){return!!e})()}var DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER="#",REGEX_NEWLINE=/\r\n|\r|\n/,buildPropertyNode=function(e,r,t,n){var o,i=!0===t.escapeUnicode,a=(0,_index.escapeKey)(e,i),s=(0,_index.escapeValue)(r,i),l=" "===t.separator?void 0:null!==(o=t.separator)&&void 0!==o?o:DEFAULT_SEPARATOR,c=l?" ":"",u=l?"".concat(" ").concat(l).concat(c):" ",p="".concat(a).concat(u).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:p,leadingWhitespace:"",key:e,escapedKey:a,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){for(var r=1,t=0;t<e.length;t++){var n=e[t];if("property"===n.type){var o=n.rawLines.length;e[t]={type:"property",rawLines:n.rawLines,leadingWhitespace:n.leadingWhitespace,key:n.key,escapedKey:n.escapedKey,separatorLeading:n.separatorLeading,separatorChar:n.separatorChar,separatorTrailing:n.separatorTrailing,value:n.value,escapedValue:n.escapedValue,startingLineNumber:r,endingLineNumber:r+o-1},r+=o}else"comment"===n.type?(e[t]={type:"comment",rawLine:n.rawLine,leadingWhitespace:n.leadingWhitespace,delimiter:n.delimiter,body:n.body,lineNumber:r},r++):(e[t]={type:"blank",rawLine:n.rawLine,lineNumber:r},r++)}},PropertiesEditor=function(){function e(){return _class_call_check(this,e),_call_super(this,e,arguments)}return _inherits(e,_properties.Properties),_create_class(e,[{key:"findFirstProperty",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return{index:r,node:t}}}},{key:"findLastProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return{index:r,node:t}}}},{key:"insert",value:function(e,r,t){var n,o,i=[];if(void 0!==(null==t?void 0:t.comment)){var a,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(a=i).push.apply(a,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(i.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastProperty(t.referenceKey);if(void 0!==l){var c,u="before"===t.position?l.index:l.index+1;return(c=this.nodes).splice.apply(c,[u,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(n=this.nodes).push.apply(n,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertComment",value:function(e,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,i=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var a=this.findLastProperty(r.referenceKey);if(void 0!==a){var s,l="before"===r.position?a.index:a.index+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastProperty(e.referenceKey);if(void 0!==t){var n="before"===e.position?t.index:t.index+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,i=this.findLastProperty(e);if(void 0===i)return!1;var a=i.index,s=i.node,l=null!==(t=r.newKey)&&void 0!==t?t:s.key,c=null!==(n=r.newValue)&&void 0!==n?n:s.value,u=!0===r.escapeUnicode,p=u?(0,_index.escapeKey)(l,!0):void 0!==r.newKey?(0,_index.escapeKey)(l):s.escapedKey,d=u?(0,_index.escapeValue)(c,!0):void 0!==r.newValue?(0,_index.escapeValue)(c):s.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:s.separatorChar,y=r.separator?" ":s.separatorLeading,f=r.separator?_?" ":"":s.separatorTrailing,m=_?"".concat(y).concat(_).concat(f):y,v="".concat(p).concat(m).concat(d).split(REGEX_NEWLINE),h={type:"property",rawLines:v,leadingWhitespace:s.leadingWhitespace,key:l,escapedKey:p,separatorLeading:y,separatorChar:_,separatorTrailing:f,value:c,escapedValue:d,startingLineNumber:s.startingLineNumber,endingLineNumber:s.startingLineNumber+v.length-1};if(void 0!==r.newComment){for(var b,L=a,g=a-1;g>=0&&"property"!==this.nodes[g].type;g--)L=g;var E=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,N=buildCommentNodes(r.newComment,E,0);(b=this.nodes).splice.apply(b,[L,a-L+1].concat(_to_consumable_array(N),[h]))}else this.nodes[a]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){void 0!==this.findLastProperty(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstProperty(e):this.findLastProperty(e);if(void 0!==t){var n=t.index,o=t.node;if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var i=n,a=n-1;a>=0&&"property"!==this.nodes[a].type;a--)i=a;this.nodes.splice(i,n-i+1)}else this.nodes.splice(n,1);return recalculateLineNumbers(this.nodes),o}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),e}();
@@ -1 +1 @@
1
- "use strict";function _export(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:Object.getOwnPropertyDescriptor(t,r).get})}Object.defineProperty(exports,"__esModule",{value:!0}),_export(exports,{get escapeKey(){return escapeKey},get escapeValue(){return escapeValue}});var escapeKey=function(e){return escapeContent(e,!0,arguments.length>1&&void 0!==arguments[1]&&arguments[1])},escapeValue=function(e){return escapeContent(e,!1,arguments.length>1&&void 0!==arguments[1]&&arguments[1])},REGEX_ESCAPE_NO_UNICODE=/[\s!#:=\\]/g,REGEX_ESCAPE_UNICODE=/[\s!#:=\\\u0000-\u001F\u007F-\uFFFF]/g,escapeContent=function(e,t,r){var n=r?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,r){var n;switch(e){case" ":return t||0===r?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+(null!==(n=e.charCodeAt(0))&&void 0!==n?n:0).toString(16)).slice(-4)}})};
1
+ "use strict";function _export(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:Object.getOwnPropertyDescriptor(t,r).get})}Object.defineProperty(exports,"__esModule",{value:!0}),_export(exports,{get escapeKey(){return escapeKey},get escapeValue(){return escapeValue}});var escapeKey=function(e){return escapeContent(e,!0,arguments.length>1&&void 0!==arguments[1]&&arguments[1])},escapeValue=function(e){return escapeContent(e,!1,arguments.length>1&&void 0!==arguments[1]&&arguments[1])},REGEX_ESCAPE_NO_UNICODE=/[\s!#:=\\]/g,REGEX_ESCAPE_UNICODE=/[\s!#:=\\\u0000-\u001F\u007F-\uFFFF]/g,escapeContent=function(e,t,r){var n=r?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,r){switch(e){case" ":return t||0===r?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}})};
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * A key-value pair object.
3
3
  */
4
- export type KeyValuePairObject = {
5
- [key: string]: string;
6
- };
4
+ export type KeyValuePairObject = Record<string, string>;
7
5
  /**
8
6
  * Converts the content of a `.properties` file to a key-value pair object.
9
7
  *
@@ -74,9 +74,7 @@ export type BlankLineNode = {
74
74
  /** Discriminated union of all node types in a `.properties` file. */
75
75
  export type PropertiesNode = PropertyNode | CommentNode | BlankLineNode;
76
76
  /** A plain key-value pair object where every value is a string. */
77
- export type KeyValuePairObject = {
78
- [key: string]: string;
79
- };
77
+ export type KeyValuePairObject = Record<string, string>;
80
78
  /** Information about a key that appears more than once. */
81
79
  export type KeyCollisions = {
82
80
  /** The duplicate key. */
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"formatNormalized",{enumerable:!0,get:function(){return formatNormalized}});var _index=require("../escape/index.js"),BOM="\ufeff",wrapAtWidth=function(e,a){if(e.length<=a)return e;for(var r=[],i=0,t=e.length;i<t;){var o=Math.min(i+a,t);if(o<t)for(var n=0;n<6&&o-n>i;n++){var p=o-n;if(p+5<=t&&"\\"===e[p]&&"u"===e[p+1]){o=p;break}}r.push(e.slice(i,o)),i=o}return r.join("\\\n ")},rebuildPropertyLine=function(e,a){var r,i,t,o,n=!0===a.escapeUnicode,p=a.removeLeadingWhitespace?"":e.leadingWhitespace,s=n?(0,_index.escapeKey)(e.key,!0):e.escapedKey;void 0!==a.separatorChar?(i=void 0!==a.separatorLeading?a.separatorLeading:e.separatorLeading,t=" "===a.separatorChar?"":a.separatorChar,o=void 0!==a.separatorTrailing?a.separatorTrailing:e.separatorTrailing," "===a.separatorChar&&(i=void 0!==a.separatorLeading?a.separatorLeading:" ")):(i=void 0!==a.separatorLeading?a.separatorLeading:e.separatorLeading,t=null!==(r=e.separatorChar)&&void 0!==r?r:"",o=void 0!==a.separatorTrailing?a.separatorTrailing:e.separatorTrailing);var d=n?(0,_index.escapeValue)(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(s=wrapAtWidth(s,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(d=wrapAtWidth(d,a.wrapValuesAt)),"".concat(p).concat(s).concat(i).concat(t).concat(o).concat(d)},formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},d=[],c=e.length-1;c>=0;c--){var l=e[c];"property"===l.type&&(s[l.key]?d.push(c):s[l.key]=!0)}o={};var u=!0,v=!1,f=void 0;try{for(var h,y=d[Symbol.iterator]();!(u=(h=y.next()).done);u=!0){var g=h.value;if(o[g]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var L=g-1;L>=0&&"property"!==e[L].type;L--)o[L]=!0}}catch(e){v=!0,f=e}finally{try{u||null==y.return||y.return()}finally{if(v)throw f}}}for(var m=[],w=0;w<e.length;w++)if(!o||!o[w]){var b=e[w];switch(b.type){case"comment":if(i.removeComments)continue;m.push(i.removeLeadingWhitespace?"".concat(b.delimiter).concat(b.body):b.rawLine);break;case"blank":if(i.removeBlankLines)continue;m.push(b.rawLine);break;case"property":p?m.push(rebuildPropertyLine(b,i)):m.push(b.rawLines.join(n))}}return(a?BOM:"")+m.join(n)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"formatNormalized",{enumerable:!0,get:function(){return formatNormalized}});var _index=require("../escape/index.js"),BOM="\ufeff",wrapAtWidth=function(e,a){if(e.length<=a)return e;for(var r=[],i=0,t=e.length;i<t;){var o=Math.min(i+a,t);if(o<t)for(var n=0;n<6&&o-n>i;n++){var p=o-n;if(p+5<=t&&"\\"===e[p]&&"u"===e[p+1]){o=p;break}}r.push(e.slice(i,o)),i=o}return r.join("\\\n ")},rebuildPropertyLine=function(e,a){var r,i,t,o,n,p,s,l,d,c=!0===a.escapeUnicode,u=a.removeLeadingWhitespace?"":e.leadingWhitespace,v=c?(0,_index.escapeKey)(e.key,!0):e.escapedKey;void 0!==a.separatorChar?(s=null!==(r=a.separatorLeading)&&void 0!==r?r:e.separatorLeading,l=" "===a.separatorChar?"":a.separatorChar,d=null!==(i=a.separatorTrailing)&&void 0!==i?i:e.separatorTrailing," "===a.separatorChar&&(s=null!==(t=a.separatorLeading)&&void 0!==t?t:" ")):(s=null!==(o=a.separatorLeading)&&void 0!==o?o:e.separatorLeading,l=null!==(n=e.separatorChar)&&void 0!==n?n:"",d=null!==(p=a.separatorTrailing)&&void 0!==p?p:e.separatorTrailing);var f=c?(0,_index.escapeValue)(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(v=wrapAtWidth(v,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(f=wrapAtWidth(f,a.wrapValuesAt)),"".concat(u).concat(v).concat(s).concat(l).concat(d).concat(f)},formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},l=[],d=e.length-1;d>=0;d--){var c=e[d];"property"===c.type&&(s[c.key]?l.push(d):s[c.key]=!0)}o={};var u=!0,v=!1,f=void 0;try{for(var h,y=l[Symbol.iterator]();!(u=(h=y.next()).done);u=!0){var g=h.value;if(o[g]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var m=g-1;m>=0&&"property"!==e[m].type;m--)o[m]=!0}}catch(e){v=!0,f=e}finally{try{u||null==y.return||y.return()}finally{if(v)throw f}}}for(var L=[],w=0;w<e.length;w++)if(!(null==o?void 0:o[w])){var b=e[w];switch(b.type){case"comment":if(i.removeComments)continue;L.push(i.removeLeadingWhitespace?"".concat(b.delimiter).concat(b.body):b.rawLine);break;case"blank":if(i.removeBlankLines)continue;L.push(b.rawLine);break;case"property":p?L.push(rebuildPropertyLine(b,i)):L.push(b.rawLines.join(n))}}return(a?BOM:"")+L.join(n)};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return Properties}});var _normalize=require("./normalize.js"),_parse=require("./parse.js");function _instanceof(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _class_call_check(e,r){if(!_instanceof(e,r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}var BOM="\ufeff",Properties=function(){function e(r){_class_call_check(this,e);var t=(0,_parse.parseDocument)(r);this.hasBom=t.hasBom,this.eolCharacter=t.eolCharacter,this.nodes=t.nodes}return _create_class(e,[{key:"getProperties",value:function(){return this.nodes.filter(function(e){return"property"===e.type})}},{key:"getComments",value:function(){return this.nodes.filter(function(e){return"comment"===e.type})}},{key:"getBlankLines",value:function(){return this.nodes.filter(function(e){return"blank"===e.type})}},{key:"toObject",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;"property"===i.type&&(e[i.key]=i.value)}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}return e}},{key:"getPropertyNodes",value:function(e){return this.nodes.filter(function(r){return"property"===r.type&&r.key===e})}},{key:"getEffectiveProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return t}}},{key:"getKeyCollisions",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;"property"===i.type&&(e[i.key]||(e[i.key]=[]),e[i.key].push(i))}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}var s=[],l=!0,u=!1,f=void 0;try{for(var y,c=Object.keys(e)[Symbol.iterator]();!(l=(y=c.next()).done);l=!0){var p=y.value;e[p].length>1&&s.push({key:p,nodes:e[p]})}}catch(e){u=!0,f=e}finally{try{l||null==c.return||c.return()}finally{if(u)throw f}}return s}},{key:"getLeadingNodes",value:function(e){for(var r=-1,t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];if("property"===n.type&&n.key===e){r=t;break}}if(r<=0)return[];for(var o=[],a=r-1;a>=0;a--){var i=this.nodes[a];if("property"===i.type)break;o.unshift(i)}return o}},{key:"format",value:function(e){if(!e){var r=this.eolCharacter,t=[],n=!0,o=!1,a=void 0;try{for(var i,s=this.nodes[Symbol.iterator]();!(n=(i=s.next()).done);n=!0){var l=i.value;"property"===l.type?t.push(l.rawLines.join(r)):t.push(l.rawLine)}}catch(e){o=!0,a=e}finally{try{n||null==s.return||s.return()}finally{if(o)throw a}}return(this.hasBom?BOM:"")+t.join(r)}return(0,_normalize.formatNormalized)(this.nodes,this.hasBom,this.eolCharacter,e)}}]),e}();
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return Properties}});var _normalize=require("./normalize.js"),_parse=require("./parse.js");function _instanceof(e,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _class_call_check(e,r){if(!_instanceof(e,r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}var BOM="\ufeff",Properties=function(){function e(r){_class_call_check(this,e);var t=(0,_parse.parseDocument)(r);this.hasBom=t.hasBom,this.eolCharacter=t.eolCharacter,this.nodes=t.nodes}return _create_class(e,[{key:"getProperties",value:function(){return this.nodes.filter(function(e){return"property"===e.type})}},{key:"getComments",value:function(){return this.nodes.filter(function(e){return"comment"===e.type})}},{key:"getBlankLines",value:function(){return this.nodes.filter(function(e){return"blank"===e.type})}},{key:"toObject",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,i=this.nodes[Symbol.iterator]();!(r=(o=i.next()).done);r=!0){var a=o.value;"property"===a.type&&(e[a.key]=a.value)}}catch(e){t=!0,n=e}finally{try{r||null==i.return||i.return()}finally{if(t)throw n}}return e}},{key:"getPropertyNodes",value:function(e){return this.nodes.filter(function(r){return"property"===r.type&&r.key===e})}},{key:"getEffectiveProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return t}}},{key:"getKeyCollisions",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,i=this.nodes[Symbol.iterator]();!(r=(o=i.next()).done);r=!0){var a=o.value;if("property"===a.type){var s=e[a.key];void 0===s?e[a.key]=[a]:s.push(a)}}}catch(e){t=!0,n=e}finally{try{r||null==i.return||i.return()}finally{if(t)throw n}}var l=[],u=!0,f=!1,y=void 0;try{for(var c,p=Object.keys(e)[Symbol.iterator]();!(u=(c=p.next()).done);u=!0){var h=c.value,v=e[h];void 0!==v&&v.length>1&&l.push({key:h,nodes:v})}}catch(e){f=!0,y=e}finally{try{u||null==p.return||p.return()}finally{if(f)throw y}}return l}},{key:"getLeadingNodes",value:function(e){for(var r=-1,t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];if("property"===n.type&&n.key===e){r=t;break}}if(r<=0)return[];for(var o=[],i=r-1;i>=0;i--){var a=this.nodes[i];if("property"===a.type)break;o.unshift(a)}return o}},{key:"format",value:function(e){if(!e){var r=this.eolCharacter,t=[],n=!0,o=!1,i=void 0;try{for(var a,s=this.nodes[Symbol.iterator]();!(n=(a=s.next()).done);n=!0){var l=a.value;"property"===l.type?t.push(l.rawLines.join(r)):t.push(l.rawLine)}}catch(e){o=!0,i=e}finally{try{n||null==s.return||s.return()}finally{if(o)throw i}}return(this.hasBom?BOM:"")+t.join(r)}return(0,_normalize.formatNormalized)(this.nodes,this.hasBom,this.eolCharacter,e)}}]),e}();
@@ -104,21 +104,21 @@ export type DeleteOptions = {
104
104
  */
105
105
  export declare class PropertiesEditor extends Properties {
106
106
  /**
107
- * Find the index of the first property node with the given key.
107
+ * Find the first property node with the given key.
108
108
  *
109
109
  * @param key - The unescaped key to search for.
110
110
  *
111
- * @returns The index in `this.nodes`, or `-1` if not found.
111
+ * @returns The matching node and its index in `this.nodes`, or `undefined`.
112
112
  */
113
- private findFirstPropertyIndex;
113
+ private findFirstProperty;
114
114
  /**
115
- * Find the index of the last property node with the given key.
115
+ * Find the last property node with the given key.
116
116
  *
117
117
  * @param key - The unescaped key to search for.
118
118
  *
119
- * @returns The index in `this.nodes`, or `-1` if not found.
119
+ * @returns The matching node and its index in `this.nodes`, or `undefined`.
120
120
  */
121
- private findLastPropertyIndex;
121
+ private findLastProperty;
122
122
  /**
123
123
  * Insert a new property.
124
124
  *
@@ -1 +1 @@
1
- function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _assert_this_initialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _call_super(e,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}function _get_prototype_of(e){return _get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},_get_prototype_of(e)}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){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 _possible_constructor_return(e,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}function _is_native_reflect_construct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_is_native_reflect_construct=function(){return!!e})()}import{escapeKey,escapeValue}from"../escape/index.js";import{Properties}from"../parser/properties.js";var DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER="#",REGEX_NEWLINE=/\r\n|\r|\n/,buildPropertyNode=function(e,r,t,n){var o,a=!0===t.escapeUnicode,i=escapeKey(e,a),s=escapeValue(r,a),l=" "===t.separator?void 0:null!==(o=t.separator)&&void 0!==o?o:DEFAULT_SEPARATOR,c=l?" ":"",u=l?"".concat(" ").concat(l).concat(c):" ",p="".concat(i).concat(u).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:p,leadingWhitespace:"",key:e,escapedKey:i,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){var r=1,t=!0,n=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(t=(a=i.next()).done);t=!0){var s=a.value;if("property"===s.type){var l=s.rawLines.length;s.startingLineNumber=r,s.endingLineNumber=r+l-1,r+=l}else s.lineNumber=r,r++}}catch(e){n=!0,o=e}finally{try{t||null==i.return||i.return()}finally{if(n)throw o}}};export var PropertiesEditor=function(e){"use strict";function r(){return _class_call_check(this,r),_call_super(this,r,arguments)}return _inherits(r,e),_create_class(r,[{key:"findFirstPropertyIndex",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"findLastPropertyIndex",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"insert",value:function(e,r,t){var n,o,a=[];if(void 0!==(null==t?void 0:t.comment)){var i,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(i=a).push.apply(i,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(a.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastPropertyIndex(t.referenceKey);if(-1!==l){var c,u="before"===t.position?l:l+1;return(c=this.nodes).splice.apply(c,[u,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(n=this.nodes).push.apply(n,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertComment",value:function(e,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,a=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var i=this.findLastPropertyIndex(r.referenceKey);if(-1!==i){var s,l="before"===r.position?i:i+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastPropertyIndex(e.referenceKey);if(-1!==t){var n="before"===e.position?t:t+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,a=this.findLastPropertyIndex(e);if(-1===a)return!1;var i=this.nodes[a],s=null!==(t=r.newKey)&&void 0!==t?t:i.key,l=null!==(n=r.newValue)&&void 0!==n?n:i.value,c=!0===r.escapeUnicode,u=c?escapeKey(s,!0):void 0!==r.newKey?escapeKey(s):i.escapedKey,p=c?escapeValue(l,!0):void 0!==r.newValue?escapeValue(l):i.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:i.separatorChar,d=r.separator?" ":i.separatorLeading,y=r.separator?_?" ":"":i.separatorTrailing,f=_?"".concat(d).concat(_).concat(y):d,m="".concat(u).concat(f).concat(p).split(REGEX_NEWLINE),v={type:"property",rawLines:m,leadingWhitespace:i.leadingWhitespace,key:s,escapedKey:u,separatorLeading:d,separatorChar:_,separatorTrailing:y,value:l,escapedValue:p,startingLineNumber:i.startingLineNumber,endingLineNumber:i.startingLineNumber+m.length-1};if(void 0!==r.newComment){for(var h,b=a,L=a-1;L>=0&&"property"!==this.nodes[L].type;L--)b=L;var g=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,E=buildCommentNodes(r.newComment,g,0);(h=this.nodes).splice.apply(h,[b,a-b+1].concat(_to_consumable_array(E),[v]))}else this.nodes[a]=v;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){-1!==this.findLastPropertyIndex(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstPropertyIndex(e):this.findLastPropertyIndex(e);if(-1!==t){var n=this.nodes[t];if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var o=t,a=t-1;a>=0&&"property"!==this.nodes[a].type;a--)o=a;this.nodes.splice(o,t-o+1)}else this.nodes.splice(t,1);return recalculateLineNumbers(this.nodes),n}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),r}(Properties);
1
+ function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function _array_without_holes(e){if(Array.isArray(e))return _array_like_to_array(e)}function _assert_this_initialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _call_super(e,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}function _get_prototype_of(e){return _get_prototype_of=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},_get_prototype_of(e)}function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}function _iterable_to_array(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _non_iterable_spread(){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 _possible_constructor_return(e,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}function _to_consumable_array(e){return _array_without_holes(e)||_iterable_to_array(e)||_unsupported_iterable_to_array(e)||_non_iterable_spread()}function _type_of(e){return e&&"undefined"!=typeof Symbol&&e.constructor===Symbol?"symbol":typeof e}function _unsupported_iterable_to_array(e,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):void 0}}function _is_native_reflect_construct(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(_is_native_reflect_construct=function(){return!!e})()}import{escapeKey,escapeValue}from"../escape/index.js";import{Properties}from"../parser/properties.js";var DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER="#",REGEX_NEWLINE=/\r\n|\r|\n/,buildPropertyNode=function(e,r,t,n){var o,a=!0===t.escapeUnicode,i=escapeKey(e,a),s=escapeValue(r,a),l=" "===t.separator?void 0:null!==(o=t.separator)&&void 0!==o?o:DEFAULT_SEPARATOR,c=l?" ":"",p=l?"".concat(" ").concat(l).concat(c):" ",u="".concat(i).concat(p).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:u,leadingWhitespace:"",key:e,escapedKey:i,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+u.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){for(var r=1,t=0;t<e.length;t++){var n=e[t];if("property"===n.type){var o=n.rawLines.length;e[t]={type:"property",rawLines:n.rawLines,leadingWhitespace:n.leadingWhitespace,key:n.key,escapedKey:n.escapedKey,separatorLeading:n.separatorLeading,separatorChar:n.separatorChar,separatorTrailing:n.separatorTrailing,value:n.value,escapedValue:n.escapedValue,startingLineNumber:r,endingLineNumber:r+o-1},r+=o}else"comment"===n.type?(e[t]={type:"comment",rawLine:n.rawLine,leadingWhitespace:n.leadingWhitespace,delimiter:n.delimiter,body:n.body,lineNumber:r},r++):(e[t]={type:"blank",rawLine:n.rawLine,lineNumber:r},r++)}};export var PropertiesEditor=function(e){"use strict";function r(){return _class_call_check(this,r),_call_super(this,r,arguments)}return _inherits(r,e),_create_class(r,[{key:"findFirstProperty",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return{index:r,node:t}}}},{key:"findLastProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return{index:r,node:t}}}},{key:"insert",value:function(e,r,t){var n,o,a=[];if(void 0!==(null==t?void 0:t.comment)){var i,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(i=a).push.apply(i,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(a.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastProperty(t.referenceKey);if(void 0!==l){var c,p="before"===t.position?l.index:l.index+1;return(c=this.nodes).splice.apply(c,[p,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(n=this.nodes).push.apply(n,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertComment",value:function(e,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,a=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var i=this.findLastProperty(r.referenceKey);if(void 0!==i){var s,l="before"===r.position?i.index:i.index+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastProperty(e.referenceKey);if(void 0!==t){var n="before"===e.position?t.index:t.index+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,a=this.findLastProperty(e);if(void 0===a)return!1;var i=a.index,s=a.node,l=null!==(t=r.newKey)&&void 0!==t?t:s.key,c=null!==(n=r.newValue)&&void 0!==n?n:s.value,p=!0===r.escapeUnicode,u=p?escapeKey(l,!0):void 0!==r.newKey?escapeKey(l):s.escapedKey,d=p?escapeValue(c,!0):void 0!==r.newValue?escapeValue(c):s.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:s.separatorChar,y=r.separator?" ":s.separatorLeading,f=r.separator?_?" ":"":s.separatorTrailing,m=_?"".concat(y).concat(_).concat(f):y,v="".concat(u).concat(m).concat(d).split(REGEX_NEWLINE),h={type:"property",rawLines:v,leadingWhitespace:s.leadingWhitespace,key:l,escapedKey:u,separatorLeading:y,separatorChar:_,separatorTrailing:f,value:c,escapedValue:d,startingLineNumber:s.startingLineNumber,endingLineNumber:s.startingLineNumber+v.length-1};if(void 0!==r.newComment){for(var b,L=i,g=i-1;g>=0&&"property"!==this.nodes[g].type;g--)L=g;var N=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,E=buildCommentNodes(r.newComment,N,0);(b=this.nodes).splice.apply(b,[L,i-L+1].concat(_to_consumable_array(E),[h]))}else this.nodes[i]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){void 0!==this.findLastProperty(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstProperty(e):this.findLastProperty(e);if(void 0!==t){var n=t.index,o=t.node;if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var a=n,i=n-1;i>=0&&"property"!==this.nodes[i].type;i--)a=i;this.nodes.splice(a,n-a+1)}else this.nodes.splice(n,1);return recalculateLineNumbers(this.nodes),o}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),r}(Properties);
@@ -1 +1 @@
1
- export var escapeKey=function(e){return escapeContent(e,!0,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};export var escapeValue=function(e){return escapeContent(e,!1,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};var REGEX_ESCAPE_NO_UNICODE=/[\s!#:=\\]/g,REGEX_ESCAPE_UNICODE=/[\s!#:=\\\u0000-\u001F\u007F-\uFFFF]/g,escapeContent=function(e,r,t){var n=t?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,t){var n;switch(e){case" ":return r||0===t?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+(null!==(n=e.charCodeAt(0))&&void 0!==n?n:0).toString(16)).slice(-4)}})};
1
+ export var escapeKey=function(e){return escapeContent(e,!0,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};export var escapeValue=function(e){return escapeContent(e,!1,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};var REGEX_ESCAPE_NO_UNICODE=/[\s!#:=\\]/g,REGEX_ESCAPE_UNICODE=/[\s!#:=\\\u0000-\u001F\u007F-\uFFFF]/g,escapeContent=function(e,t,r){var n=r?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,r){switch(e){case" ":return t||0===r?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}})};
@@ -1,9 +1,7 @@
1
1
  /**
2
2
  * A key-value pair object.
3
3
  */
4
- export type KeyValuePairObject = {
5
- [key: string]: string;
6
- };
4
+ export type KeyValuePairObject = Record<string, string>;
7
5
  /**
8
6
  * Converts the content of a `.properties` file to a key-value pair object.
9
7
  *
@@ -74,9 +74,7 @@ export type BlankLineNode = {
74
74
  /** Discriminated union of all node types in a `.properties` file. */
75
75
  export type PropertiesNode = PropertyNode | CommentNode | BlankLineNode;
76
76
  /** A plain key-value pair object where every value is a string. */
77
- export type KeyValuePairObject = {
78
- [key: string]: string;
79
- };
77
+ export type KeyValuePairObject = Record<string, string>;
80
78
  /** Information about a key that appears more than once. */
81
79
  export type KeyCollisions = {
82
80
  /** The duplicate key. */
@@ -1 +1 @@
1
- import{escapeKey,escapeValue}from"../escape/index.js";var BOM="\ufeff",wrapAtWidth=function(e,a){if(e.length<=a)return e;for(var r=[],i=0,t=e.length;i<t;){var o=Math.min(i+a,t);if(o<t)for(var n=0;n<6&&o-n>i;n++){var p=o-n;if(p+5<=t&&"\\"===e[p]&&"u"===e[p+1]){o=p;break}}r.push(e.slice(i,o)),i=o}return r.join("\\\n ")},rebuildPropertyLine=function(e,a){var r,i,t,o,n=!0===a.escapeUnicode,p=a.removeLeadingWhitespace?"":e.leadingWhitespace,s=n?escapeKey(e.key,!0):e.escapedKey;void 0!==a.separatorChar?(i=void 0!==a.separatorLeading?a.separatorLeading:e.separatorLeading,t=" "===a.separatorChar?"":a.separatorChar,o=void 0!==a.separatorTrailing?a.separatorTrailing:e.separatorTrailing," "===a.separatorChar&&(i=void 0!==a.separatorLeading?a.separatorLeading:" ")):(i=void 0!==a.separatorLeading?a.separatorLeading:e.separatorLeading,t=null!==(r=e.separatorChar)&&void 0!==r?r:"",o=void 0!==a.separatorTrailing?a.separatorTrailing:e.separatorTrailing);var d=n?escapeValue(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(s=wrapAtWidth(s,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(d=wrapAtWidth(d,a.wrapValuesAt)),"".concat(p).concat(s).concat(i).concat(t).concat(o).concat(d)};export var formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},d=[],c=e.length-1;c>=0;c--){var l=e[c];"property"===l.type&&(s[l.key]?d.push(c):s[l.key]=!0)}o={};var v=!0,u=!1,h=void 0;try{for(var f,y=d[Symbol.iterator]();!(v=(f=y.next()).done);v=!0){var g=f.value;if(o[g]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var L=g-1;L>=0&&"property"!==e[L].type;L--)o[L]=!0}}catch(e){u=!0,h=e}finally{try{v||null==y.return||y.return()}finally{if(u)throw h}}}for(var m=[],w=0;w<e.length;w++)if(!o||!o[w]){var A=e[w];switch(A.type){case"comment":if(i.removeComments)continue;m.push(i.removeLeadingWhitespace?"".concat(A.delimiter).concat(A.body):A.rawLine);break;case"blank":if(i.removeBlankLines)continue;m.push(A.rawLine);break;case"property":p?m.push(rebuildPropertyLine(A,i)):m.push(A.rawLines.join(n))}}return(a?BOM:"")+m.join(n)};
1
+ import{escapeKey,escapeValue}from"../escape/index.js";var BOM="\ufeff",wrapAtWidth=function(e,a){if(e.length<=a)return e;for(var r=[],i=0,t=e.length;i<t;){var o=Math.min(i+a,t);if(o<t)for(var n=0;n<6&&o-n>i;n++){var p=o-n;if(p+5<=t&&"\\"===e[p]&&"u"===e[p+1]){o=p;break}}r.push(e.slice(i,o)),i=o}return r.join("\\\n ")},rebuildPropertyLine=function(e,a){var r,i,t,o,n,p,s,l,c,d=!0===a.escapeUnicode,u=a.removeLeadingWhitespace?"":e.leadingWhitespace,v=d?escapeKey(e.key,!0):e.escapedKey;void 0!==a.separatorChar?(s=null!==(r=a.separatorLeading)&&void 0!==r?r:e.separatorLeading,l=" "===a.separatorChar?"":a.separatorChar,c=null!==(i=a.separatorTrailing)&&void 0!==i?i:e.separatorTrailing," "===a.separatorChar&&(s=null!==(t=a.separatorLeading)&&void 0!==t?t:" ")):(s=null!==(o=a.separatorLeading)&&void 0!==o?o:e.separatorLeading,l=null!==(n=e.separatorChar)&&void 0!==n?n:"",c=null!==(p=a.separatorTrailing)&&void 0!==p?p:e.separatorTrailing);var h=d?escapeValue(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(v=wrapAtWidth(v,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(h=wrapAtWidth(h,a.wrapValuesAt)),"".concat(u).concat(v).concat(s).concat(l).concat(c).concat(h)};export var formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},l=[],c=e.length-1;c>=0;c--){var d=e[c];"property"===d.type&&(s[d.key]?l.push(c):s[d.key]=!0)}o={};var u=!0,v=!1,h=void 0;try{for(var f,y=l[Symbol.iterator]();!(u=(f=y.next()).done);u=!0){var g=f.value;if(o[g]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var L=g-1;L>=0&&"property"!==e[L].type;L--)o[L]=!0}}catch(e){v=!0,h=e}finally{try{u||null==y.return||y.return()}finally{if(v)throw h}}}for(var m=[],w=0;w<e.length;w++)if(!(null==o?void 0:o[w])){var A=e[w];switch(A.type){case"comment":if(i.removeComments)continue;m.push(i.removeLeadingWhitespace?"".concat(A.delimiter).concat(A.body):A.rawLine);break;case"blank":if(i.removeBlankLines)continue;m.push(A.rawLine);break;case"property":p?m.push(rebuildPropertyLine(A,i)):m.push(A.rawLines.join(n))}}return(a?BOM:"")+m.join(n)};
@@ -1 +1 @@
1
- function _class_call_check(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}import{formatNormalized as formatNormalizedImpl}from"./normalize.js";import{parseDocument}from"./parse.js";var BOM="\ufeff";export var Properties=function(){"use strict";function e(r){_class_call_check(this,e);var t=parseDocument(r);this.hasBom=t.hasBom,this.eolCharacter=t.eolCharacter,this.nodes=t.nodes}return _create_class(e,[{key:"getProperties",value:function(){return this.nodes.filter(function(e){return"property"===e.type})}},{key:"getComments",value:function(){return this.nodes.filter(function(e){return"comment"===e.type})}},{key:"getBlankLines",value:function(){return this.nodes.filter(function(e){return"blank"===e.type})}},{key:"toObject",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;"property"===i.type&&(e[i.key]=i.value)}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}return e}},{key:"getPropertyNodes",value:function(e){return this.nodes.filter(function(r){return"property"===r.type&&r.key===e})}},{key:"getEffectiveProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return t}}},{key:"getKeyCollisions",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;"property"===i.type&&(e[i.key]||(e[i.key]=[]),e[i.key].push(i))}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}var l=[],s=!0,u=!1,f=void 0;try{for(var y,c=Object.keys(e)[Symbol.iterator]();!(s=(y=c.next()).done);s=!0){var h=y.value;e[h].length>1&&l.push({key:h,nodes:e[h]})}}catch(e){u=!0,f=e}finally{try{s||null==c.return||c.return()}finally{if(u)throw f}}return l}},{key:"getLeadingNodes",value:function(e){for(var r=-1,t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];if("property"===n.type&&n.key===e){r=t;break}}if(r<=0)return[];for(var o=[],a=r-1;a>=0;a--){var i=this.nodes[a];if("property"===i.type)break;o.unshift(i)}return o}},{key:"format",value:function(e){if(!e){var r=this.eolCharacter,t=[],n=!0,o=!1,a=void 0;try{for(var i,l=this.nodes[Symbol.iterator]();!(n=(i=l.next()).done);n=!0){var s=i.value;"property"===s.type?t.push(s.rawLines.join(r)):t.push(s.rawLine)}}catch(e){o=!0,a=e}finally{try{n||null==l.return||l.return()}finally{if(o)throw a}}return(this.hasBom?BOM:"")+t.join(r)}return formatNormalizedImpl(this.nodes,this.hasBom,this.eolCharacter,e)}}]),e}();
1
+ function _class_call_check(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),e}import{formatNormalized as formatNormalizedImpl}from"./normalize.js";import{parseDocument}from"./parse.js";var BOM="\ufeff";export var Properties=function(){"use strict";function e(r){_class_call_check(this,e);var t=parseDocument(r);this.hasBom=t.hasBom,this.eolCharacter=t.eolCharacter,this.nodes=t.nodes}return _create_class(e,[{key:"getProperties",value:function(){return this.nodes.filter(function(e){return"property"===e.type})}},{key:"getComments",value:function(){return this.nodes.filter(function(e){return"comment"===e.type})}},{key:"getBlankLines",value:function(){return this.nodes.filter(function(e){return"blank"===e.type})}},{key:"toObject",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;"property"===i.type&&(e[i.key]=i.value)}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}return e}},{key:"getPropertyNodes",value:function(e){return this.nodes.filter(function(r){return"property"===r.type&&r.key===e})}},{key:"getEffectiveProperty",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return t}}},{key:"getKeyCollisions",value:function(){var e={},r=!0,t=!1,n=void 0;try{for(var o,a=this.nodes[Symbol.iterator]();!(r=(o=a.next()).done);r=!0){var i=o.value;if("property"===i.type){var l=e[i.key];void 0===l?e[i.key]=[i]:l.push(i)}}}catch(e){t=!0,n=e}finally{try{r||null==a.return||a.return()}finally{if(t)throw n}}var s=[],u=!0,f=!1,y=void 0;try{for(var c,h=Object.keys(e)[Symbol.iterator]();!(u=(c=h.next()).done);u=!0){var p=c.value,v=e[p];void 0!==v&&v.length>1&&s.push({key:p,nodes:v})}}catch(e){f=!0,y=e}finally{try{u||null==h.return||h.return()}finally{if(f)throw y}}return s}},{key:"getLeadingNodes",value:function(e){for(var r=-1,t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];if("property"===n.type&&n.key===e){r=t;break}}if(r<=0)return[];for(var o=[],a=r-1;a>=0;a--){var i=this.nodes[a];if("property"===i.type)break;o.unshift(i)}return o}},{key:"format",value:function(e){if(!e){var r=this.eolCharacter,t=[],n=!0,o=!1,a=void 0;try{for(var i,l=this.nodes[Symbol.iterator]();!(n=(i=l.next()).done);n=!0){var s=i.value;"property"===s.type?t.push(s.rawLines.join(r)):t.push(s.rawLine)}}catch(e){o=!0,a=e}finally{try{n||null==l.return||l.return()}finally{if(o)throw a}}return(this.hasBom?BOM:"")+t.join(r)}return formatNormalizedImpl(this.nodes,this.hasBom,this.eolCharacter,e)}}]),e}();
package/package.json CHANGED
@@ -1,184 +1,185 @@
1
- {
2
- "name": "properties-file",
3
- "version": "5.0.4",
4
- "description": ".properties file parser, editor, formatter and bundler integrations.",
5
- "keywords": [
6
- ".properties",
7
- "properties",
8
- ".properties file",
9
- "properties file",
10
- "parser",
11
- "editor",
12
- "formatter",
13
- "Java",
14
- "intl",
15
- "i18n",
16
- "Webpack loader",
17
- "Rollup plugin",
18
- "Vite plugin",
19
- "esbuild plugin",
20
- "Bun plugin",
21
- "internationalization"
22
- ],
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/properties-file/properties-file.git"
26
- },
27
- "license": "MIT",
28
- "author": "properties-file",
29
- "sideEffects": false,
30
- "type": "module",
31
- "exports": {
32
- ".": {
33
- "import": {
34
- "types": "./dist/esm/index.d.ts",
35
- "default": "./dist/esm/index.js"
36
- },
37
- "require": {
38
- "types": "./dist/cjs/index.d.ts",
39
- "default": "./dist/cjs/index.js"
40
- }
41
- },
42
- "./bundler/bun": {
43
- "import": {
44
- "types": "./dist/esm/bundler/bun.d.ts",
45
- "default": "./dist/esm/bundler/bun.js"
46
- },
47
- "require": {
48
- "types": "./dist/cjs/bundler/bun.d.ts",
49
- "default": "./dist/cjs/bundler/bun.js"
50
- }
51
- },
52
- "./bundler/esbuild": {
53
- "import": {
54
- "types": "./dist/esm/bundler/esbuild.d.ts",
55
- "default": "./dist/esm/bundler/esbuild.js"
56
- },
57
- "require": {
58
- "types": "./dist/cjs/bundler/esbuild.d.ts",
59
- "default": "./dist/cjs/bundler/esbuild.js"
60
- }
61
- },
62
- "./bundler/rollup": {
63
- "import": {
64
- "types": "./dist/esm/bundler/rollup.d.ts",
65
- "default": "./dist/esm/bundler/rollup.js"
66
- },
67
- "require": {
68
- "types": "./dist/cjs/bundler/rollup.d.ts",
69
- "default": "./dist/cjs/bundler/rollup.js"
70
- }
71
- },
72
- "./bundler/webpack": {
73
- "import": {
74
- "types": "./dist/esm/bundler/webpack.d.ts",
75
- "default": "./dist/esm/bundler/webpack.js"
76
- },
77
- "require": {
78
- "types": "./dist/cjs/bundler/webpack.d.ts",
79
- "default": "./dist/cjs/bundler/webpack.js"
80
- }
81
- },
82
- "./editor": {
83
- "import": {
84
- "types": "./dist/esm/editor/index.d.ts",
85
- "default": "./dist/esm/editor/index.js"
86
- },
87
- "require": {
88
- "types": "./dist/cjs/editor/index.d.ts",
89
- "default": "./dist/cjs/editor/index.js"
90
- }
91
- },
92
- "./escape": {
93
- "import": {
94
- "types": "./dist/esm/escape/index.d.ts",
95
- "default": "./dist/esm/escape/index.js"
96
- },
97
- "require": {
98
- "types": "./dist/cjs/escape/index.d.ts",
99
- "default": "./dist/cjs/escape/index.js"
100
- }
101
- },
102
- "./parser": {
103
- "import": {
104
- "types": "./dist/esm/parser/index.d.ts",
105
- "default": "./dist/esm/parser/index.js"
106
- },
107
- "require": {
108
- "types": "./dist/cjs/parser/index.d.ts",
109
- "default": "./dist/cjs/parser/index.js"
110
- }
111
- },
112
- "./unescape": {
113
- "import": {
114
- "types": "./dist/esm/unescape/index.d.ts",
115
- "default": "./dist/esm/unescape/index.js"
116
- },
117
- "require": {
118
- "types": "./dist/cjs/unescape/index.d.ts",
119
- "default": "./dist/cjs/unescape/index.js"
120
- }
121
- }
122
- },
123
- "main": "dist/cjs/index.js",
124
- "module": "dist/esm/index.js",
125
- "types": "dist/esm/index.d.ts",
126
- "files": [
127
- "dist"
128
- ],
129
- "scripts": {
130
- "benchmark": "npx tsx performance/benchmarks/compare.ts",
131
- "build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && rm -Rf ./dist && tsc && npx tsx src/build-scripts/build.ts && npm run test && npm run size",
132
- "check-nvm-node-version": "check-node-version --node $(node -p \"'>='+require('fs').readFileSync('.nvmrc','utf-8').trim()\")",
133
- "depcheck": "depcheck",
134
- "eslint-fix": "eslint --fix",
135
- "ncu": "npm-check-updates",
136
- "ncu-update": "npm-check-updates -u",
137
- "performance-clean": "rm -rf performance/published-packages/.cache performance/benchmarks/.results performance/size/.results",
138
- "prepare": "husky",
139
- "prettier-write": "prettier --write .",
140
- "release": "dotenv -- release-it --only-version",
141
- "size": "npx tsx performance/size/compare.ts",
142
- "snapshot": "npx tsx performance/snapshots/manage.ts",
143
- "test": "jest --coverage",
144
- "test-node-compat": "docker build --platform linux/amd64 -f tests/node-compat/Dockerfile.node-0.4 ."
145
- },
146
- "devDependencies": {
147
- "@release-it/conventional-changelog": "10.0.6",
148
- "@swc/core": "1.15.24",
149
- "@types/bun": "1.3.12",
150
- "@types/jest": "30.0.0",
151
- "@types/node": "25.6.0",
152
- "check-node-version": "4.2.1",
153
- "depcheck": "1.4.7",
154
- "dotenv-cli": "11.0.0",
155
- "esbuild": "0.28.0",
156
- "eslint": "10.2.0",
157
- "eslint-config-prettier": "10.1.8",
158
- "eslint-import-resolver-typescript": "4.4.4",
159
- "eslint-plugin-es-x": "9.6.0",
160
- "eslint-plugin-import-x": "4.16.2",
161
- "eslint-plugin-jest": "29.15.2",
162
- "eslint-plugin-package-json": "0.91.1",
163
- "eslint-plugin-prefer-arrow-functions": "3.9.1",
164
- "eslint-plugin-prettier": "5.5.5",
165
- "eslint-plugin-tsdoc": "0.5.2",
166
- "eslint-plugin-unicorn": "64.0.0",
167
- "husky": "9.1.7",
168
- "jest": "30.3.0",
169
- "jiti": "2.6.1",
170
- "jsonc-eslint-parser": "3.1.0",
171
- "npm-check-updates": "20.0.1",
172
- "prettier": "3.8.2",
173
- "release-it": "20.0.0-1",
174
- "rollup": "4.60.1",
175
- "terser": "5.46.1",
176
- "tinybench": "6.0.0",
177
- "ts-jest": "29.4.9",
178
- "typescript": "6.0.2",
179
- "typescript-eslint": "8.58.1"
180
- },
181
- "engines": {
182
- "node": ">=0.4.0"
183
- }
184
- }
1
+ {
2
+ "name": "properties-file",
3
+ "version": "5.0.5",
4
+ "description": ".properties file parser, editor, formatter and bundler integrations.",
5
+ "keywords": [
6
+ ".properties",
7
+ "properties",
8
+ ".properties file",
9
+ "properties file",
10
+ "parser",
11
+ "editor",
12
+ "formatter",
13
+ "Java",
14
+ "intl",
15
+ "i18n",
16
+ "Webpack loader",
17
+ "Rollup plugin",
18
+ "Vite plugin",
19
+ "esbuild plugin",
20
+ "Bun plugin",
21
+ "internationalization"
22
+ ],
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/properties-file/properties-file.git"
26
+ },
27
+ "license": "MIT",
28
+ "author": "properties-file",
29
+ "sideEffects": false,
30
+ "type": "module",
31
+ "exports": {
32
+ ".": {
33
+ "import": {
34
+ "types": "./dist/esm/index.d.ts",
35
+ "default": "./dist/esm/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/cjs/index.d.ts",
39
+ "default": "./dist/cjs/index.js"
40
+ }
41
+ },
42
+ "./bundler/bun": {
43
+ "import": {
44
+ "types": "./dist/esm/bundler/bun.d.ts",
45
+ "default": "./dist/esm/bundler/bun.js"
46
+ },
47
+ "require": {
48
+ "types": "./dist/cjs/bundler/bun.d.ts",
49
+ "default": "./dist/cjs/bundler/bun.js"
50
+ }
51
+ },
52
+ "./bundler/esbuild": {
53
+ "import": {
54
+ "types": "./dist/esm/bundler/esbuild.d.ts",
55
+ "default": "./dist/esm/bundler/esbuild.js"
56
+ },
57
+ "require": {
58
+ "types": "./dist/cjs/bundler/esbuild.d.ts",
59
+ "default": "./dist/cjs/bundler/esbuild.js"
60
+ }
61
+ },
62
+ "./bundler/rollup": {
63
+ "import": {
64
+ "types": "./dist/esm/bundler/rollup.d.ts",
65
+ "default": "./dist/esm/bundler/rollup.js"
66
+ },
67
+ "require": {
68
+ "types": "./dist/cjs/bundler/rollup.d.ts",
69
+ "default": "./dist/cjs/bundler/rollup.js"
70
+ }
71
+ },
72
+ "./bundler/webpack": {
73
+ "import": {
74
+ "types": "./dist/esm/bundler/webpack.d.ts",
75
+ "default": "./dist/esm/bundler/webpack.js"
76
+ },
77
+ "require": {
78
+ "types": "./dist/cjs/bundler/webpack.d.ts",
79
+ "default": "./dist/cjs/bundler/webpack.js"
80
+ }
81
+ },
82
+ "./editor": {
83
+ "import": {
84
+ "types": "./dist/esm/editor/index.d.ts",
85
+ "default": "./dist/esm/editor/index.js"
86
+ },
87
+ "require": {
88
+ "types": "./dist/cjs/editor/index.d.ts",
89
+ "default": "./dist/cjs/editor/index.js"
90
+ }
91
+ },
92
+ "./escape": {
93
+ "import": {
94
+ "types": "./dist/esm/escape/index.d.ts",
95
+ "default": "./dist/esm/escape/index.js"
96
+ },
97
+ "require": {
98
+ "types": "./dist/cjs/escape/index.d.ts",
99
+ "default": "./dist/cjs/escape/index.js"
100
+ }
101
+ },
102
+ "./parser": {
103
+ "import": {
104
+ "types": "./dist/esm/parser/index.d.ts",
105
+ "default": "./dist/esm/parser/index.js"
106
+ },
107
+ "require": {
108
+ "types": "./dist/cjs/parser/index.d.ts",
109
+ "default": "./dist/cjs/parser/index.js"
110
+ }
111
+ },
112
+ "./unescape": {
113
+ "import": {
114
+ "types": "./dist/esm/unescape/index.d.ts",
115
+ "default": "./dist/esm/unescape/index.js"
116
+ },
117
+ "require": {
118
+ "types": "./dist/cjs/unescape/index.d.ts",
119
+ "default": "./dist/cjs/unescape/index.js"
120
+ }
121
+ }
122
+ },
123
+ "main": "dist/cjs/index.js",
124
+ "module": "dist/esm/index.js",
125
+ "types": "dist/esm/index.d.ts",
126
+ "files": [
127
+ "dist"
128
+ ],
129
+ "scripts": {
130
+ "benchmark": "npx tsx performance/benchmarks/compare.ts",
131
+ "build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && npm run typecheck && rm -Rf ./dist && tsc && npx tsx src/build-scripts/build.ts && npm run test && npm run size",
132
+ "check-nvm-node-version": "check-node-version --node $(node -p \"'>='+require('fs').readFileSync('.nvmrc','utf-8').trim()\")",
133
+ "depcheck": "depcheck",
134
+ "eslint-fix": "eslint --fix",
135
+ "ncu": "npm-check-updates",
136
+ "ncu-update": "npm-check-updates -u",
137
+ "performance-clean": "rm -rf performance/published-packages/.cache performance/benchmarks/.results performance/size/.results",
138
+ "prepare": "husky",
139
+ "prettier-write": "prettier --write .",
140
+ "release": "dotenv -- release-it --only-version",
141
+ "size": "npx tsx performance/size/compare.ts",
142
+ "snapshot": "npx tsx performance/snapshots/manage.ts",
143
+ "test": "jest --coverage",
144
+ "test-node-compat": "docker build --platform linux/amd64 -f tests/node-compat/Dockerfile.node-0.4 .",
145
+ "typecheck": "find . -name tsconfig.json -not -path '*/node_modules/*' -not -path '*/dist/*' -not -path '*/.*/*' -print0 | xargs -0 -n1 -I{} npx tsc --noEmit -p {}"
146
+ },
147
+ "devDependencies": {
148
+ "@release-it/conventional-changelog": "11.0.0",
149
+ "@swc/core": "1.15.33",
150
+ "@types/bun": "1.3.14",
151
+ "@types/jest": "30.0.0",
152
+ "@types/node": "25.9.0",
153
+ "check-node-version": "4.2.1",
154
+ "depcheck": "1.4.7",
155
+ "dotenv-cli": "11.0.0",
156
+ "esbuild": "0.28.0",
157
+ "eslint": "10.4.0",
158
+ "eslint-config-prettier": "10.1.8",
159
+ "eslint-import-resolver-typescript": "4.4.4",
160
+ "eslint-plugin-es-x": "9.6.0",
161
+ "eslint-plugin-import-x": "4.16.2",
162
+ "eslint-plugin-jest": "29.15.2",
163
+ "eslint-plugin-package-json": "1.0.0",
164
+ "eslint-plugin-prefer-arrow-functions": "3.9.1",
165
+ "eslint-plugin-prettier": "5.5.5",
166
+ "eslint-plugin-tsdoc": "0.5.2",
167
+ "eslint-plugin-unicorn": "64.0.0",
168
+ "husky": "9.1.7",
169
+ "jest": "30.4.2",
170
+ "jiti": "2.7.0",
171
+ "jsonc-eslint-parser": "3.1.0",
172
+ "npm-check-updates": "22.2.0",
173
+ "prettier": "3.8.3",
174
+ "release-it": "20.0.1",
175
+ "rollup": "4.60.4",
176
+ "terser": "5.47.1",
177
+ "tinybench": "6.0.2",
178
+ "ts-jest": "29.4.9",
179
+ "typescript": "6.0.3",
180
+ "typescript-eslint": "8.59.4"
181
+ },
182
+ "engines": {
183
+ "node": ">=0.4.0"
184
+ }
185
+ }