properties-file 4.0.0 → 5.0.1

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.
Files changed (57) hide show
  1. package/README.md +94 -97
  2. package/dist/cjs/bundler/bun.js +1 -1
  3. package/dist/cjs/bundler/esbuild.js +1 -1
  4. package/dist/cjs/bundler/rollup.js +1 -1
  5. package/dist/cjs/bundler/webpack.js +1 -1
  6. package/dist/cjs/editor/index.d.ts +100 -93
  7. package/dist/cjs/editor/index.js +1 -1
  8. package/dist/cjs/escape/index.js +1 -1
  9. package/dist/cjs/index.d.ts +0 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/package.json +1 -1
  12. package/dist/cjs/parse-properties.d.ts +22 -0
  13. package/dist/cjs/parse-properties.js +1 -0
  14. package/dist/cjs/parser/index.d.ts +3 -0
  15. package/dist/cjs/parser/index.js +1 -0
  16. package/dist/cjs/parser/nodes.d.ts +156 -0
  17. package/dist/cjs/parser/nodes.js +1 -0
  18. package/dist/cjs/parser/normalize.d.ts +12 -0
  19. package/dist/cjs/parser/normalize.js +1 -0
  20. package/dist/cjs/parser/parse.d.ts +23 -0
  21. package/dist/cjs/parser/parse.js +1 -0
  22. package/dist/cjs/parser/properties.d.ts +93 -0
  23. package/dist/cjs/parser/properties.js +1 -0
  24. package/dist/cjs/unescape/index.d.ts +4 -0
  25. package/dist/cjs/unescape/index.js +1 -1
  26. package/dist/esm/editor/index.d.ts +100 -93
  27. package/dist/esm/editor/index.js +1 -1
  28. package/dist/esm/escape/index.js +1 -1
  29. package/dist/esm/index.d.ts +0 -1
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/parse-properties.d.ts +22 -0
  32. package/dist/esm/parse-properties.js +1 -0
  33. package/dist/esm/parser/index.d.ts +3 -0
  34. package/dist/esm/parser/index.js +1 -0
  35. package/dist/esm/parser/nodes.d.ts +156 -0
  36. package/dist/esm/parser/nodes.js +1 -0
  37. package/dist/esm/parser/normalize.d.ts +12 -0
  38. package/dist/esm/parser/normalize.js +1 -0
  39. package/dist/esm/parser/parse.d.ts +23 -0
  40. package/dist/esm/parser/parse.js +1 -0
  41. package/dist/esm/parser/properties.d.ts +93 -0
  42. package/dist/esm/parser/properties.js +1 -0
  43. package/dist/esm/unescape/index.d.ts +4 -0
  44. package/dist/esm/unescape/index.js +1 -1
  45. package/package.json +33 -21
  46. package/dist/cjs/properties.d.ts +0 -96
  47. package/dist/cjs/properties.js +0 -1
  48. package/dist/cjs/property-line.d.ts +0 -22
  49. package/dist/cjs/property-line.js +0 -1
  50. package/dist/cjs/property.d.ts +0 -81
  51. package/dist/cjs/property.js +0 -1
  52. package/dist/esm/properties.d.ts +0 -96
  53. package/dist/esm/properties.js +0 -1
  54. package/dist/esm/property-line.d.ts +0 -22
  55. package/dist/esm/property-line.js +0 -1
  56. package/dist/esm/property.d.ts +0 -81
  57. package/dist/esm/property.js +0 -1
@@ -1 +1 @@
1
- "use strict";var __extends=this&&this.__extends||function(){var e=function(r,t){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},e(r,t)};return function(r,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=r}e(r,t),r.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}}(),__read=this&&this.__read||function(e,r){var t="function"==typeof Symbol&&e[Symbol.iterator];if(!t)return e;var n,i,o=t.call(e),s=[];try{for(;(void 0===r||r-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(i)throw i.error}}return s},__spreadArray=this&&this.__spreadArray||function(e,r,t){if(t||2===arguments.length)for(var n,i=0,o=r.length;i<o;i++)!n&&i in r||(n||(n=Array.prototype.slice.call(r,0,i)),n[i]=r[i]);return e.concat(n||Array.prototype.slice.call(r))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertiesEditor=exports.DEFAULT_COMMENT_DELIMITER=exports.DEFAULT_SEPARATOR=void 0;var escape_1=require("../escape"),properties_1=require("../properties"),REGEX_NEWLINE_GLOBAL=/\r?\n/g,REGEX_LF=/\n/;exports.DEFAULT_SEPARATOR="=",exports.DEFAULT_COMMENT_DELIMITER="#";var PropertiesEditor=function(e){function r(r){var t=e.call(this,r)||this;return t.needsLineParsing=!1,t}return __extends(r,e),r.prototype.findLastPropertyByKey=function(e){for(var r=this.collection.length-1;r>=0;r--){var t=this.collection[r];if(t.key===e)return t}},r.prototype.parseLinesIfNeeded=function(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)},r.prototype.insert=function(e,r,t){var n,i,o,s=(null==t?void 0:t.escapeUnicode)||!1,a=(null==t?void 0:t.separator)?" "===t.separator?" ":" ".concat(t.separator," "):" ".concat(exports.DEFAULT_SEPARATOR," ").replace(" "," "),p=null==t?void 0:t.referenceKey,c=(null==t?void 0:t.position)||"after";p&&this.parseLinesIfNeeded();var l=e.split(properties_1.REGEX_NEWLINE).map(function(e){return(0,escape_1.escapeKey)(e,s)}).join("\\\n"),d=r.split(properties_1.REGEX_NEWLINE).map(function(e){return(0,escape_1.escapeValue)(e,s)}).join("\\\n"),u="".concat((null==t?void 0:t.commentDelimiter)||exports.DEFAULT_COMMENT_DELIMITER," "),_=void 0===(null==t?void 0:t.comment)?"":"".concat("".concat(u).concat(t.comment).split(properties_1.REGEX_NEWLINE).join("\n".concat(u)),"\n"),y="".concat(_).concat(l).concat(a).concat(d).split(REGEX_LF);if(void 0===p)return(n=this.lines).push.apply(n,__spreadArray([],__read(y),!1)),this.needsLineParsing=!0,!0;var E=this.findLastPropertyByKey(p);if(E){var v="after"===c?E.endingLineNumber:null!==(o=null===(i=E.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,v)),!1),__read(y),!1),__read(this.lines.slice(v)),!1),this.needsLineParsing=!0,!0}return!1},r.prototype.insertComment=function(e,r){var t,n,i,o=null==r?void 0:r.referenceKey,s=(null==r?void 0:r.position)||"after";o&&this.parseLinesIfNeeded();var a="".concat((null==r?void 0:r.commentDelimiter)||exports.DEFAULT_COMMENT_DELIMITER," "),p="".concat(a).concat(e).replace(REGEX_NEWLINE_GLOBAL,"\n".concat(a)).split(REGEX_LF);if(void 0===o)return(t=this.lines).push.apply(t,__spreadArray([],__read(p),!1)),this.needsLineParsing=!0,!0;var c=this.findLastPropertyByKey(o);if(c){var l="after"===s?c.endingLineNumber:null!==(i=null===(n=c.previousProperty)||void 0===n?void 0:n.endingLineNumber)&&void 0!==i?i:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,l)),!1),__read(p),!1),__read(this.lines.slice(l)),!1),this.needsLineParsing=!0,!0}return!1},r.prototype.delete=function(e,r){var t,n;void 0===r&&(r=!0),this.parseLinesIfNeeded();var i=this.findLastPropertyByKey(e);if(i){var o=r?null!==(n=null===(t=i.previousProperty)||void 0===t?void 0:t.endingLineNumber)&&void 0!==n?n:0:i.startingLineNumber-1,s=i.endingLineNumber;return this.lines=__spreadArray(__spreadArray([],__read(this.lines.slice(0,o)),!1),__read(this.lines.slice(s)),!1),this.needsLineParsing=!0,!0}return!1},r.prototype.getKeyWithNewlines=function(e){return 0===e.newlinePositions.length?e.key:__spreadArray([],__read(e.key),!1).reduce(function(r,t,n){return"".concat(r).concat(-1!==e.newlinePositions.indexOf(n)?"\n":"").concat(t)},"")},r.prototype.getValueWithNewlines=function(e){return 0===e.newlinePositions.length||void 0===e.valuePosition?e.value:__spreadArray([],__read(e.value),!1).reduce(function(r,t,n){return"".concat(r).concat(-1!==e.newlinePositions.indexOf(n+e.valuePosition)?"\n":"").concat(t)},"")},r.prototype.update=function(e,r){var t,n,i,o;this.parseLinesIfNeeded();var s=this.findLastPropertyByKey(e);if(!s||!r)return!1;var a=r.escapeUnicode||!1,p=r.separator?" "===r.separator?" ":" ".concat(r.separator," "):s.separator||" ".concat(exports.DEFAULT_SEPARATOR," ").replace(" "," "),c=(null!==(t=r.newKey)&&void 0!==t?t:this.getKeyWithNewlines(s)).split(properties_1.REGEX_NEWLINE).map(function(e){return(0,escape_1.escapeKey)(e,a)}).join("\\\n"),l=(null!==(n=r.newValue)&&void 0!==n?n:this.getValueWithNewlines(s)).split(properties_1.REGEX_NEWLINE).map(function(e){return(0,escape_1.escapeValue)(e,a)}).join("\\\n"),d="".concat(r.commentDelimiter||exports.DEFAULT_COMMENT_DELIMITER," "),u=void 0===r.newComment?"":"".concat("".concat(d).concat(r.newComment).split(properties_1.REGEX_NEWLINE).join("\n".concat(d)),"\n"),_="".concat(u).concat(c).concat(p).concat(l).split(REGEX_LF);return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,void 0===r.newComment?s.startingLineNumber-1:null!==(o=null===(i=s.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0)),!1),__read(_),!1),__read(this.lines.slice(s.endingLineNumber)),!1),this.needsLineParsing=!0,!0},r.prototype.upsert=function(e,r,t){return this.parseLinesIfNeeded(),this.keyLineNumbers[e]?this.update(e,{newValue:r,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter,separator:null==t?void 0:t.separator,escapeUnicode:null==t?void 0:t.escapeUnicode}):this.insert(e,r,t)},r.prototype.toObject=function(){return this.parseLinesIfNeeded(),e.prototype.toObject.call(this)},r}(properties_1.Properties);exports.PropertiesEditor=PropertiesEditor;
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,t){return null!=t&&"undefined"!=typeof Symbol&&t[Symbol.hasInstance]?!!t[Symbol.hasInstance](e):e instanceof t}function _array_like_to_array(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];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,t,r){return t=_get_prototype_of(t),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(t,r||[],_get_prototype_of(e).constructor):t.apply(e,r))}function _class_call_check(e,t){if(!_instanceof(e,t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),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,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_set_prototype_of(e,t)}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,t){return!t||"object"!==_type_of(t)&&"function"!=typeof t?_assert_this_initialized(e):t}function _set_prototype_of(e,t){return _set_prototype_of=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},_set_prototype_of(e,t)}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,t){if(e){if("string"==typeof e)return _array_like_to_array(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(r):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_array_like_to_array(e,t):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,t,r,n){var o,a=!0===r.escapeUnicode,i=(0,_index.escapeKey)(e,a),s=(0,_index.escapeValue)(t,a),l=" "===r.separator?void 0:null!==(o=r.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:t,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,t,r){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:r+n}:{type:"comment",rawLine:"".concat(t," ").concat(e),leadingWhitespace:"",delimiter:t,body:" ".concat(e),lineNumber:r+n}})},recalculateLineNumbers=function(e){var t=1,r=!0,n=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(r=(a=i.next()).done);r=!0){var s=a.value;if("property"===s.type){var l=s.rawLines.length;s.startingLineNumber=t,s.endingLineNumber=t+l-1,t+=l}else s.lineNumber=t,t++}}catch(e){n=!0,o=e}finally{try{r||null==i.return||i.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:"findLastPropertyIndex",value:function(e){for(var t=this.nodes.length-1;t>=0;t--){var r=this.nodes[t];if("property"===r.type&&r.key===e)return t}return-1}},{key:"insert",value:function(e,t,r){var n,o,a=[];if(void 0!==(null==r?void 0:r.comment)){var i,s=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(i=a).push.apply(i,_to_consumable_array(buildCommentNodes(r.comment,s,0)))}if(a.push(buildPropertyNode(e,t,{escapeUnicode:null==r?void 0:r.escapeUnicode,separator:null==r?void 0:r.separator},0)),null==r?void 0:r.referenceKey){var l=this.findLastPropertyIndex(r.referenceKey);if(-1!==l){var c,u="before"===r.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,t){var r,n,o=null!==(n=null==t?void 0:t.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,a=buildCommentNodes(e,o,0);if(null==t?void 0:t.referenceKey){var i=this.findLastPropertyIndex(t.referenceKey);if(-1!==i){var s,l="before"===t.position?i:i+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(r=this.nodes).push.apply(r,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var t={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var r=this.findLastPropertyIndex(e.referenceKey);if(-1!==r){var n="before"===e.position?r:r+1;return this.nodes.splice(n,0,t),void recalculateLineNumbers(this.nodes)}}this.nodes.push(t),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,t){var r,n,o,a=this.findLastPropertyIndex(e);if(-1===a)return!1;var i=this.nodes[a],s=null!==(r=t.newKey)&&void 0!==r?r:i.key,l=null!==(n=t.newValue)&&void 0!==n?n:i.value,c=!0===t.escapeUnicode,u=c?(0,_index.escapeKey)(s,!0):void 0!==t.newKey?(0,_index.escapeKey)(s):i.escapedKey,p=c?(0,_index.escapeValue)(l,!0):void 0!==t.newValue?(0,_index.escapeValue)(l):i.escapedValue,_=t.separator?" "===t.separator?void 0:t.separator:i.separatorChar,d=t.separator?" ":i.separatorLeading,y=t.separator?_?" ":"":i.separatorTrailing,f=_?"".concat(d).concat(_).concat(y):d,m="".concat(u).concat(f).concat(p).split(REGEX_NEWLINE),h={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!==t.newComment){for(var v,b=a,L=a-1;L>=0&&"property"!==this.nodes[L].type;L--)b=L;var E=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,g=buildCommentNodes(t.newComment,E,0);(v=this.nodes).splice.apply(v,[b,a-b+1].concat(_to_consumable_array(g),[h]))}else this.nodes[a]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,t,r){-1!==this.findLastPropertyIndex(e)?this.update(e,{newValue:t,escapeUnicode:null==r?void 0:r.escapeUnicode,separator:null==r?void 0:r.separator,newComment:null==r?void 0:r.comment,commentDelimiter:null==r?void 0:r.commentDelimiter}):this.insert(e,t,r)}},{key:"delete",value:function(e,t){var r=this.findLastPropertyIndex(e);if(-1!==r){var n=this.nodes[r];if(!1!==(null==t?void 0:t.deleteLeadingNodes)){for(var o=r,a=r-1;a>=0&&"property"!==this.nodes[a].type;a--)o=a;this.nodes.splice(o,r-o+1)}else this.nodes.splice(r,1);return recalculateLineNumbers(this.nodes),n}}},{key:"deleteAll",value:function(e){for(var t=[],r=this.nodes.length-1;r>=0;r--){var n=this.nodes[r];"property"===n.type&&n.key===e&&(this.nodes.splice(r,1),t.push(n))}return t.length>0&&recalculateLineNumbers(this.nodes),t.reverse()}}]),e}();
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeValue=exports.escapeKey=void 0;var escapeKey=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!0,r)};exports.escapeKey=escapeKey;var escapeValue=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!1,r)};exports.escapeValue=escapeValue;var escapeContent=function(e,r,t){return e.replace(new RegExp("[\\s!#:=\\\\".concat(t?"\0--￿":"","]"),"g"),function(e,t){var a;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!==(a=e.charCodeAt(0))&&void 0!==a?a: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){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,4 +1,3 @@
1
- export { Properties } from './properties';
2
1
  /**
3
2
  * A key-value pair object.
4
3
  */
package/dist/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getProperties=exports.Properties=void 0;var properties_1=require("./properties"),properties_2=require("./properties");Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return properties_2.Properties}});var getProperties=function(e){return new properties_1.Properties(e).toObject()};exports.getProperties=getProperties;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"getProperties",{enumerable:!0,get:function(){return getProperties}});var _parseproperties=require("./parse-properties.js"),getProperties=function(e){return(0,_parseproperties.parseProperties)(e)};
@@ -1 +1 @@
1
- { "type": "commonjs" }
1
+ { "type": "commonjs" }
@@ -0,0 +1,22 @@
1
+ import type { KeyValuePairObject } from './index.js';
2
+ /**
3
+ * Parse a `.properties` file content string into a key-value pair object.
4
+ *
5
+ * This is a functional, single-pass parser that implements the Java
6
+ * `java.util.Properties` specification:
7
+ *
8
+ * - BOM detection and skipping
9
+ * - Comment lines (`#` or `!`)
10
+ * - Line continuations (trailing odd backslash)
11
+ * - Key-value separator detection (`=`, `:`, or whitespace)
12
+ * - Escape sequence processing (`\\n`, `\\t`, `\\r`, `\\f`, `\\\\`, `\\uXXXX`)
13
+ * - Last-value-wins semantics for duplicate keys
14
+ *
15
+ * All character inspection uses `charCodeAt()` (ES5). No regex, no
16
+ * intermediate object allocations.
17
+ *
18
+ * @param content - The content of a `.properties` file (string or Buffer).
19
+ *
20
+ * @returns A key-value pair object where every value is a string.
21
+ */
22
+ export declare const parseProperties: (content: string | Buffer) => KeyValuePairObject;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"parseProperties",{enumerable:!0,get:function(){return parseProperties}});var CH_TAB=9,CH_LF=10,CH_FF=12,CH_CR=13,CH_SPACE=32,CH_BANG=33,CH_HASH=35,CH_COLON=58,CH_EQUALS=61,CH_BACKSLASH=92,CH_LOWER_F=102,CH_LOWER_N=110,CH_LOWER_R=114,CH_LOWER_T=116,CH_LOWER_U=117,CH_BOM=65279,skipWhitespace=function(e,C,r){for(;C<r;){var a=e.charCodeAt(C);if(a!==CH_SPACE&&a!==CH_TAB&&a!==CH_FF)break;C++}return C},isHexDigit=function(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102},hexValue=function(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e-87},unescapeContent=function(e,C,r,a,t){if(!a)return e.slice(C,r);for(var H="",_=C,c=C;c<r;)if(e.charCodeAt(c)===CH_BACKSLASH){switch(c>_&&(H+=e.slice(_,c)),c++,e.charCodeAt(c)){case CH_LOWER_N:H+="\n",c++;break;case CH_LOWER_T:H+="\t",c++;break;case CH_LOWER_R:H+="\r",c++;break;case CH_LOWER_F:H+="\f",c++;break;case CH_LOWER_U:if(c+4>=r||!isHexDigit(e.charCodeAt(c+1))||!isHexDigit(e.charCodeAt(c+2))||!isHexDigit(e.charCodeAt(c+3))||!isHexDigit(e.charCodeAt(c+4))){var i=e.slice(c-1,c+5);throw new Error("malformed escaped unicode characters '".concat(i,"' in property starting at line ").concat(t))}var o=hexValue(e.charCodeAt(c+1))<<12|hexValue(e.charCodeAt(c+2))<<8|hexValue(e.charCodeAt(c+3))<<4|hexValue(e.charCodeAt(c+4));H+=String.fromCharCode(o),c+=5;break;default:H+=e.charAt(c),c++}_=c}else c++;return _<r&&(H+=e.slice(_,r)),H},parseProperties=function(e){var C="string"==typeof e?e:e.toString(),r=C.length,a={},t=0,H=1;for(r>0&&C.charCodeAt(0)===CH_BOM&&(t=1);t<r&&!((t=skipWhitespace(C,t,r))>=r);){var _=C.charCodeAt(t);if(_!==CH_LF)if(_!==CH_CR)if(_!==CH_HASH&&_!==CH_BANG){for(var c=H,i=t,o=0,A=!1;t<r&&(_=C.charCodeAt(t))!==CH_LF&&_!==CH_CR;)_===CH_BACKSLASH?(o++,A=!0):o=0,t++;if(o%2==1){var s=[C.slice(i,t-1)],h=A;for(t<r&&(C.charCodeAt(t)===CH_CR?++t<r&&C.charCodeAt(t)===CH_LF&&t++:t++,H++),t=skipWhitespace(C,t,r);;){var n=t;o=0;for(var d=!1;t<r&&(_=C.charCodeAt(t))!==CH_LF&&_!==CH_CR;)_===CH_BACKSLASH?(o++,d=!0):o=0,t++;var f=o%2==1,p=f?t-1:t;if(s.push(C.slice(n,p)),d&&(h=!0),t<r&&(C.charCodeAt(t)===CH_CR?++t<r&&C.charCodeAt(t)===CH_LF&&t++:t++,H++),!f)break;t=skipWhitespace(C,t,r)}for(var L=s.join(""),u=L.length,S=0,l=!1;S<u;)if((_=L.charCodeAt(S))!==CH_BACKSLASH){if(!l&&(_===CH_EQUALS||_===CH_COLON||_===CH_SPACE||_===CH_TAB||_===CH_FF))break;l=!1,S++}else l=!l,S++;var F=S;F<u&&((_=L.charCodeAt(F))!==CH_SPACE&&_!==CH_TAB&&_!==CH_FF||(F=skipWhitespace(L,F,u))<u&&(_=L.charCodeAt(F)),F<u&&(_===CH_EQUALS||_===CH_COLON)&&(F++,F=skipWhitespace(L,F,u))),a[unescapeContent(L,0,S,h,c)]=unescapeContent(L,F,u,h,c)}else{var O=t;t<r&&(C.charCodeAt(t)===CH_CR?++t<r&&C.charCodeAt(t)===CH_LF&&t++:t++,H++);for(var E=i,R=!1;E<O;)if((_=C.charCodeAt(E))!==CH_BACKSLASH){if(!R&&(_===CH_EQUALS||_===CH_COLON||_===CH_SPACE||_===CH_TAB||_===CH_FF))break;R=!1,E++}else R=!R,E++;var k=E;k<O&&((_=C.charCodeAt(k))!==CH_SPACE&&_!==CH_TAB&&_!==CH_FF||(k=skipWhitespace(C,k,O))<O&&(_=C.charCodeAt(k)),k<O&&(_===CH_EQUALS||_===CH_COLON)&&(k++,k=skipWhitespace(C,k,O))),a[unescapeContent(C,i,E,A,c)]=unescapeContent(C,k,O,A,c)}}else for(;t<r;){if((_=C.charCodeAt(t))===CH_LF){t++,H++;break}if(_===CH_CR){++t<r&&C.charCodeAt(t)===CH_LF&&t++,H++;break}t++}else++t<r&&C.charCodeAt(t)===CH_LF&&t++,H++;else t++,H++}return a};
@@ -0,0 +1,3 @@
1
+ export { Properties } from './properties.js';
2
+ export { PropertiesNodeType } from './nodes.js';
3
+ export type { BlankLineNode, CommentNode, KeyCollisions, KeyValuePairObject, NormalizeOptions, PropertiesNode, PropertyNode, } from './nodes.js';
@@ -0,0 +1 @@
1
+ "use strict";function _export(e,r){for(var t in r)Object.defineProperty(e,t,{enumerable:!0,get:Object.getOwnPropertyDescriptor(r,t).get})}Object.defineProperty(exports,"__esModule",{value:!0}),_export(exports,{get Properties(){return _properties.Properties},get PropertiesNodeType(){return _nodes.PropertiesNodeType}});var _properties=require("./properties.js"),_nodes=require("./nodes.js");
@@ -0,0 +1,156 @@
1
+ /** Constants for the `type` discriminator on each node. */
2
+ export declare const PropertiesNodeType: {
3
+ /** A property (key-value pair). */
4
+ readonly PROPERTY: "property";
5
+ /** A comment line (`#` or `!`). */
6
+ readonly COMMENT: "comment";
7
+ /** A blank line. */
8
+ readonly BLANK: "blank";
9
+ };
10
+ /**
11
+ * A property (key-value pair), potentially spanning multiple physical lines
12
+ * via backslash continuation.
13
+ */
14
+ export type PropertyNode = {
15
+ /** Discriminator. */
16
+ readonly type: 'property';
17
+ /** Physical lines as-is (without EOL characters), for lossless reconstruction. */
18
+ readonly rawLines: string[];
19
+ /** Leading whitespace before the key on the first physical line. */
20
+ readonly leadingWhitespace: string;
21
+ /** The unescaped key. */
22
+ readonly key: string;
23
+ /** The key as written in the source (after continuation joining, before unescaping). */
24
+ readonly escapedKey: string;
25
+ /** Whitespace between the key and the separator character. */
26
+ readonly separatorLeading: string;
27
+ /**
28
+ * The core separator character.
29
+ *
30
+ * - `'='` or `':'` when an explicit delimiter is used.
31
+ * - `undefined` when whitespace alone separates key from value, or when
32
+ * the property is key-only with no separator.
33
+ */
34
+ readonly separatorChar: '=' | ':' | undefined;
35
+ /** Whitespace between the separator character and the value. */
36
+ readonly separatorTrailing: string;
37
+ /** The unescaped value. */
38
+ readonly value: string;
39
+ /** The value as written in the source (after continuation joining, before unescaping). */
40
+ readonly escapedValue: string;
41
+ /** 1-based line number where this property starts. */
42
+ readonly startingLineNumber: number;
43
+ /** 1-based line number where this property ends. */
44
+ readonly endingLineNumber: number;
45
+ };
46
+ /**
47
+ * A comment line starting with `#` or `!`.
48
+ */
49
+ export type CommentNode = {
50
+ /** Discriminator. */
51
+ readonly type: 'comment';
52
+ /** The full line as-is (without the EOL character). */
53
+ readonly rawLine: string;
54
+ /** Leading whitespace before the delimiter. */
55
+ readonly leadingWhitespace: string;
56
+ /** The comment delimiter character. */
57
+ readonly delimiter: '#' | '!';
58
+ /** The text after the delimiter (including any space immediately after it). */
59
+ readonly body: string;
60
+ /** 1-based line number. */
61
+ readonly lineNumber: number;
62
+ };
63
+ /**
64
+ * A blank line (may contain only whitespace characters).
65
+ */
66
+ export type BlankLineNode = {
67
+ /** Discriminator. */
68
+ readonly type: 'blank';
69
+ /** The raw whitespace content of the line (without the EOL character). */
70
+ readonly rawLine: string;
71
+ /** 1-based line number. */
72
+ readonly lineNumber: number;
73
+ };
74
+ /** Discriminated union of all node types in a `.properties` file. */
75
+ export type PropertiesNode = PropertyNode | CommentNode | BlankLineNode;
76
+ /** A plain key-value pair object where every value is a string. */
77
+ export type KeyValuePairObject = {
78
+ [key: string]: string;
79
+ };
80
+ /** Information about a key that appears more than once. */
81
+ export type KeyCollisions = {
82
+ /** The duplicate key. */
83
+ key: string;
84
+ /** All property nodes with this key, in file order. */
85
+ nodes: PropertyNode[];
86
+ };
87
+ /**
88
+ * Options for {@link Properties.format} when producing normalized output.
89
+ *
90
+ * When no options are passed to `format()`, the output is a lossless reconstruction
91
+ * of the original content. Passing any option triggers normalization, rebuilding
92
+ * property lines from their parsed fields.
93
+ */
94
+ export type NormalizeOptions = {
95
+ /** Override the end-of-line character. Defaults to the EOL detected from the source. */
96
+ endOfLineCharacter?: '\n' | '\r\n';
97
+ /** If `true`, remove all comment lines from the output. Default: `false`. */
98
+ removeComments?: boolean;
99
+ /** If `true`, remove all blank lines from the output. Default: `false`. */
100
+ removeBlankLines?: boolean;
101
+ /** If `true`, strip leading whitespace from all property and comment lines. Default: `false`. */
102
+ removeLeadingWhitespace?: boolean;
103
+ /**
104
+ * If `true`, keep only the last occurrence of each duplicate key (Java's last-wins
105
+ * semantics). Earlier occurrences and their leading comment/blank line nodes are
106
+ * removed from the output. Set `deduplicateKeysKeepLeadingNodes` to `true` to
107
+ * preserve the leading nodes. Default: `false`.
108
+ */
109
+ deduplicateKeys?: boolean;
110
+ /**
111
+ * When `deduplicateKeys` is `true`, controls whether comment and blank line nodes
112
+ * preceding removed duplicates are preserved (`true`) or also removed (`false`).
113
+ * Default: `false` (leading nodes are removed along with the duplicate).
114
+ */
115
+ deduplicateKeysKeepLeadingNodes?: boolean;
116
+ /**
117
+ * Standardize the separator character across all properties. When set, every
118
+ * property is rewritten to use this separator. Original separators are preserved
119
+ * if not set. Use `' '` for whitespace-only separators (no `=` or `:`).
120
+ */
121
+ separatorChar?: '=' | ':' | ' ';
122
+ /**
123
+ * Whitespace to place before the separator character (e.g. `' '` for `key = value`,
124
+ * `''` for `key=value`). When not set, each property's original leading whitespace
125
+ * is preserved.
126
+ */
127
+ separatorLeading?: string;
128
+ /**
129
+ * Whitespace to place after the separator character (e.g. `' '` for `key = value`,
130
+ * `''` for `key=value`). When not set, each property's original trailing whitespace
131
+ * is preserved.
132
+ */
133
+ separatorTrailing?: string;
134
+ /**
135
+ * If `true`, re-escape all non-ASCII characters as `\\uXXXX` sequences. Useful for
136
+ * producing ISO-8859-1 compatible output. Default: `false` (preserves original encoding).
137
+ */
138
+ escapeUnicode?: boolean;
139
+ /**
140
+ * If `true`, collapse multiline keys and values (joined via `\\` line continuations)
141
+ * into single lines. Default: `false` (preserves original line structure).
142
+ */
143
+ collapseMultiline?: boolean;
144
+ /**
145
+ * Wrap keys at this character width using `\\` line continuations. Only applies to
146
+ * keys longer than the specified width. `\\uXXXX` sequences are never split across
147
+ * lines. `undefined` = no wrapping.
148
+ */
149
+ wrapKeysAt?: number;
150
+ /**
151
+ * Wrap values at this character width using `\\` line continuations. Only applies to
152
+ * values longer than the specified width. `\\uXXXX` sequences are never split across
153
+ * lines. `undefined` = no wrapping.
154
+ */
155
+ wrapValuesAt?: number;
156
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"PropertiesNodeType",{enumerable:!0,get:function(){return PropertiesNodeType}});var PropertiesNodeType={PROPERTY:"property",COMMENT:"comment",BLANK:"blank"};
@@ -0,0 +1,12 @@
1
+ import type { NormalizeOptions, PropertiesNode } from './nodes.js';
2
+ /**
3
+ * Format a set of property nodes into normalized output.
4
+ *
5
+ * @param nodes - All nodes from the parsed document.
6
+ * @param hasBom - Whether the original content had a BOM.
7
+ * @param eolCharacter - The detected EOL character.
8
+ * @param options - Normalization options.
9
+ *
10
+ * @returns The normalized `.properties` file content.
11
+ */
12
+ export declare const formatNormalized: (nodes: PropertiesNode[], hasBom: boolean, eolCharacter: string, options: NormalizeOptions) => string;
@@ -0,0 +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)};
@@ -0,0 +1,23 @@
1
+ import type { PropertiesNode } from './nodes.js';
2
+ /** Result of parsing a `.properties` file. */
3
+ export type ParseResult = {
4
+ /** Whether the content starts with a BOM character. */
5
+ hasBom: boolean;
6
+ /** The detected end-of-line character sequence. */
7
+ eolCharacter: string;
8
+ /** All parsed nodes in file order. */
9
+ nodes: PropertiesNode[];
10
+ };
11
+ /**
12
+ * Parse a `.properties` file into a lossless sequence of nodes.
13
+ *
14
+ * Every element in the file — properties, comments, and blank lines — is
15
+ * preserved in order. Duplicate keys are all retained. The original content
16
+ * can be reconstructed exactly by joining node raw lines with the EOL
17
+ * character.
18
+ *
19
+ * @param content - The content of a `.properties` file.
20
+ *
21
+ * @returns The parse result with BOM info, detected EOL, and ordered nodes.
22
+ */
23
+ export declare const parseDocument: (content: string | Buffer) => ParseResult;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"parseDocument",{enumerable:!0,get:function(){return parseDocument}});var _index=require("../unescape/index.js"),CH_TAB=9,CH_LF=10,CH_FF=12,CH_CR=13,CH_SPACE=32,CH_BANG=33,CH_HASH=35,CH_COLON=58,CH_EQUALS=61,CH_BACKSLASH=92,CH_BOM=65279,isWhitespace=function(e){return e===CH_SPACE||e===CH_TAB||e===CH_FF},countTrailingBackslashes=function(e,r){for(var a=0,i=r-1;i>=0&&e.charCodeAt(i)===CH_BACKSLASH;)a++,i--;return a},parseDocument=function(e){var r="string"==typeof e?e:e.toString(),a=r.length,i=0,t=a>0&&r.charCodeAt(0)===CH_BOM;t&&(i=1);for(var n="\n",s=i;s<a;s++){var c=r.charCodeAt(s);if(c===CH_CR){n=s+1<a&&r.charCodeAt(s+1)===CH_LF?"\r\n":"\r";break}if(c===CH_LF){n="\n";break}}for(var o=(i>0?r.slice(i):r).split(/\r\n|\r|\n/),C=[],l=0,h=o.length;l<h;){for(var H=o[l],p=l+1,d=0,u=H.length;d<u&&isWhitespace(H.charCodeAt(d));)d++;if(d>=u){var _={type:"blank",rawLine:H,lineNumber:p};C.push(_),l++}else{var v=H.charCodeAt(d);if(v!==CH_HASH&&v!==CH_BANG){for(var f=[H],A=p,g=d>0?H.slice(0,d):"",L=countTrailingBackslashes(H,u),S=L%2==1;S&&l+1<h;){var B=o[++l];f.push(B);var b=B.length;S=(L=countTrailingBackslashes(B,b))%2==1}var m=l+1,O=S,y=void 0;if(1===f.length){var N=d>0?H.slice(d):H;y=O?N.slice(0,-1):N}else{for(var k=[],x=0;x<f.length;x++){var W=f[x],F=void 0,E=void 0;if(0===x)F=d,E=W.length-1;else{F=0;for(var T=W.length;F<T&&isWhitespace(W.charCodeAt(F));)F++;E=x===f.length-1&&!O?T:T-1}k.push(W.slice(F,E))}y=k.join("")}for(var j=y.length,K=0,P=!1;K<j;){var Q=y.charCodeAt(K);if(Q!==CH_BACKSLASH){if(!P&&(Q===CH_EQUALS||Q===CH_COLON||isWhitespace(Q)))break;P=!1,K++}else P=!P,K++}var U=y.slice(0,K),w="",D=void 0,M="",G=K;if(G<j){for(var R=G;G<j&&isWhitespace(y.charCodeAt(G));)G++;if(G<j){var q=y.charCodeAt(G);if(q===CH_EQUALS||q===CH_COLON){w=y.slice(R,G),D=q===CH_EQUALS?"=":":";for(var V=++G;G<j&&isWhitespace(y.charCodeAt(G));)G++;M=y.slice(V,G)}else w=y.slice(R,G)}else w=y.slice(R,G)}var z=y.slice(G),I={type:"property",rawLines:f,leadingWhitespace:g,key:-1!==U.indexOf("\\")?(0,_index.unescapeContent)(U):U,escapedKey:U,separatorLeading:w,separatorChar:D,separatorTrailing:M,value:-1!==z.indexOf("\\")?(0,_index.unescapeContent)(z):z,escapedValue:z,startingLineNumber:A,endingLineNumber:m};C.push(I),l++}else{var J={type:"comment",rawLine:H,leadingWhitespace:d>0?H.slice(0,d):"",delimiter:v===CH_HASH?"#":"!",body:H.slice(d+1),lineNumber:p};C.push(J),l++}}}return{hasBom:t,eolCharacter:n,nodes:C}};
@@ -0,0 +1,93 @@
1
+ import type { BlankLineNode, CommentNode, KeyCollisions, KeyValuePairObject, NormalizeOptions, PropertiesNode, PropertyNode } from './nodes.js';
2
+ /**
3
+ * A lossless, ordered representation of a `.properties` file.
4
+ *
5
+ * Every element in the file — properties, comments, and blank lines — is
6
+ * preserved in order. Duplicate keys are all retained. The original content
7
+ * can be reconstructed exactly via {@link format}.
8
+ */
9
+ export declare class Properties {
10
+ /** Whether the content started with a BOM character. */
11
+ readonly hasBom: boolean;
12
+ /** The end-of-line character detected from the content. */
13
+ readonly eolCharacter: string;
14
+ /** All nodes in file order. */
15
+ readonly nodes: PropertiesNode[];
16
+ /**
17
+ * Parse a `.properties` file into a lossless node structure.
18
+ *
19
+ * @param content - The content of a `.properties` file (string or Buffer).
20
+ */
21
+ constructor(content: string | Buffer);
22
+ /**
23
+ * Get all property nodes in file order (including duplicates).
24
+ *
25
+ * @returns An array of all {@link PropertyNode} instances.
26
+ */
27
+ getProperties(): PropertyNode[];
28
+ /**
29
+ * Get all comment nodes in file order.
30
+ *
31
+ * @returns An array of all {@link CommentNode} instances.
32
+ */
33
+ getComments(): CommentNode[];
34
+ /**
35
+ * Get all blank line nodes in file order.
36
+ *
37
+ * @returns An array of all {@link BlankLineNode} instances.
38
+ */
39
+ getBlankLines(): BlankLineNode[];
40
+ /**
41
+ * Get the effective key-value map (last-wins semantics for duplicate keys).
42
+ *
43
+ * @returns A plain object where each key maps to its last-occurring value.
44
+ */
45
+ toObject(): KeyValuePairObject;
46
+ /**
47
+ * Get all property nodes for a given key (all occurrences, in file order).
48
+ *
49
+ * @param key - The unescaped key to search for.
50
+ *
51
+ * @returns An array of matching {@link PropertyNode} instances (empty if not found).
52
+ */
53
+ getPropertyNodes(key: string): PropertyNode[];
54
+ /**
55
+ * Get the effective property node for a given key (last occurrence).
56
+ *
57
+ * @param key - The unescaped key to search for.
58
+ *
59
+ * @returns The last {@link PropertyNode} with this key, or `undefined`.
60
+ */
61
+ getEffectiveProperty(key: string): PropertyNode | undefined;
62
+ /**
63
+ * Get keys that appear more than once, with all their property nodes.
64
+ *
65
+ * @returns An array of {@link KeyCollisions} for duplicate keys.
66
+ */
67
+ getKeyCollisions(): KeyCollisions[];
68
+ /**
69
+ * Get comment and blank line nodes immediately preceding a property.
70
+ *
71
+ * Walks backward from the last occurrence of the given key, collecting
72
+ * comment and blank line nodes until reaching another property or the
73
+ * start of the file.
74
+ *
75
+ * @param key - The unescaped key to find leading nodes for.
76
+ *
77
+ * @returns An array of preceding {@link CommentNode} and {@link BlankLineNode} instances.
78
+ */
79
+ getLeadingNodes(key: string): (CommentNode | BlankLineNode)[];
80
+ /**
81
+ * Format the `.properties` content as a string.
82
+ *
83
+ * Without options, produces an exact lossless reconstruction of the original
84
+ * content. With options, produces normalized output — standardize separators,
85
+ * remove comments, deduplicate keys, and more.
86
+ *
87
+ * @param options - Optional normalization options. When omitted, the output
88
+ * is a lossless round-trip of the original content.
89
+ *
90
+ * @returns The formatted `.properties` file content.
91
+ */
92
+ format(options?: NormalizeOptions): string;
93
+ }
@@ -0,0 +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,6 +1,10 @@
1
1
  /**
2
2
  * Tries to unescape the content from either key or value of a property.
3
3
  *
4
+ * Uses a single-pass, segment-based approach with `charCodeAt()` instead of
5
+ * regex. Scans for backslashes, flushes literal text in bulk via `slice()`,
6
+ * and only builds new characters for actual escape sequences.
7
+ *
4
8
  * @param content - The content to unescape.
5
9
  *
6
10
  * @returns The unescaped content.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unescapeContent=void 0;var REGEX_INVALID_UNICODE_ESCAPE=/\\u(?![0-9a-fA-F]{4})/,REGEX_ESCAPE=/\\(?:([fnrt])|u([0-9a-fA-F]{4})|(.))/g,ESCAPE_MAP={f:"\f",n:"\n",r:"\r",t:"\t"},unescapeContent=function(e){var n;if(-1===e.indexOf("\\"))return e;var r=e.match(REGEX_INVALID_UNICODE_ESCAPE);if(r){var t=null!==(n=r.index)&&void 0!==n?n:0,E=e.slice(t,t+6);throw new Error("malformed escaped unicode characters '".concat(E,"'"))}return e.replace(REGEX_ESCAPE,function(e,n,r,t){return n?ESCAPE_MAP[n]:r?String.fromCharCode(parseInt(r,16)):null!=t?t:""})};exports.unescapeContent=unescapeContent;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"unescapeContent",{enumerable:!0,get:function(){return unescapeContent}});var CH_BACKSLASH=92,CH_LOWER_F=102,CH_LOWER_N=110,CH_LOWER_R=114,CH_LOWER_T=116,CH_LOWER_U=117,isHexDigit=function(e){return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102},hexValue=function(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e-87},unescapeContent=function(e){if(-1===e.indexOf("\\"))return e;for(var r=e.length,t="",a=0,c=0;c<r;)if(e.charCodeAt(c)===CH_BACKSLASH){if(c>a&&(t+=e.slice(a,c)),++c>=r){t+="\\",a=c;break}switch(e.charCodeAt(c)){case CH_LOWER_N:t+="\n",c++;break;case CH_LOWER_T:t+="\t",c++;break;case CH_LOWER_R:t+="\r",c++;break;case CH_LOWER_F:t+="\f",c++;break;case CH_LOWER_U:if(c+4>=r||!isHexDigit(e.charCodeAt(c+1))||!isHexDigit(e.charCodeAt(c+2))||!isHexDigit(e.charCodeAt(c+3))||!isHexDigit(e.charCodeAt(c+4))){var i=e.slice(c-1,c+5);throw new Error("malformed escaped unicode characters '".concat(i,"'"))}var n=hexValue(e.charCodeAt(c+1))<<12|hexValue(e.charCodeAt(c+2))<<8|hexValue(e.charCodeAt(c+3))<<4|hexValue(e.charCodeAt(c+4));t+=String.fromCharCode(n),c+=5;break;default:t+=e.charAt(c),c++}a=c}else c++;return a<r&&(t+=e.slice(a,r)),t};