properties-file 3.6.5 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Package Size](https://deno.bundlejs.com/badge?q=properties-file@latest&treeshake=[*])](https://bundlejs.com/?q=properties-file@latest&treeshake=[*])
7
7
  ![Dependencies](https://img.shields.io/badge/dependencies-0-brightgreen)
8
8
 
9
- `.properties` file parser, editor, formatter and Webpack loader.
9
+ `.properties` file parser, editor, formatter and bundler integrations.
10
10
 
11
11
  ## Installation 💻
12
12
 
@@ -27,7 +27,7 @@ npm install properties-file
27
27
  - A `Properties` class provides insights into parsing data.
28
28
  - A `PropertiesEditor` class enables the addition, edition, and removal of entries.
29
29
  - `escapeKey` and `escapeValue` allow the conversion of any content to a `.properties` compatible format.
30
- - The library also includes a Webpack loader to import `.properties` files directly into your application.
30
+ - Bundler integrations for Webpack, Rollup/Vite, esbuild, and Bun to import `.properties` files directly. See [BUNDLER.md](./BUNDLER.md).
31
31
  - [Tiny](https://bundlejs.com/?q=properties-file%40latest&treeshake=%5B*%5D) with 0 dependencies.
32
32
  - 100% test coverage based on the output from a Java implementation.
33
33
  - Active maintenance (many popular `.properties` packages have been inactive for years).
@@ -189,40 +189,11 @@ console.log(properties.format())
189
189
 
190
190
  For convenience, we also added an `upsert` method that allows updating a key if it exists or adding it at the end, when it doesn't. Make sure to check in your IDE for all available methods and options in our TSDoc.
191
191
 
192
- ### Webpack File Loader
192
+ ### Bundler Integrations
193
193
 
194
- If you would like to import `.properties` directly using `import`, this package comes with its own Webpack file loader located under `properties-file/webpack-loader`. Here is an example of how to configure it:
194
+ If you would like to import `.properties` directly using `import`, this package provides integrations for all major bundlers: **Webpack/Rspack**, **Rollup/Vite/Rolldown**, **esbuild**, and **Bun**.
195
195
 
196
- ```js
197
- // webpack.config.js
198
- module.exports = {
199
- module: {
200
- rules: [
201
- {
202
- test: /\.properties$/i,
203
- use: [
204
- {
205
- loader: 'properties-file/webpack-loader',
206
- },
207
- ],
208
- },
209
- ],
210
- },
211
- }
212
- ```
213
-
214
- As soon as you configure Webpack, the `.properties` type should be available in your IDE when using `import`. If you ever need to add it manually, you can add a `*.properties` type declaration file at the root of your application, like this:
215
-
216
- ```ts
217
- declare module '*.properties' {
218
- /** A key/value object representing the content of a `.properties` file. */
219
- const properties: {
220
- /** The value of a `.properties` file key. */
221
- [key: string]: string
222
- }
223
- export { properties }
224
- }
225
- ```
196
+ See [BUNDLER.md](./BUNDLER.md) for setup instructions and examples.
226
197
 
227
198
  By adding these configurations you should now be able to import directly `.properties` files just like this:
228
199
 
@@ -0,0 +1,10 @@
1
+ import type { BunPlugin } from 'bun';
2
+ /**
3
+ * Bun plugin for `.properties` files. Works with both `Bun.plugin` (runtime) and `Bun.build`
4
+ * (build-time).
5
+ */
6
+ declare const bunPlugin: BunPlugin;
7
+ export default bunPlugin;
8
+
9
+ // Enables type recognition for direct `.properties` file imports.
10
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var node_fs_1=require("node:fs"),__1=require(".."),bunPlugin={name:"properties-file",setup:function(e){e.onLoad({filter:/\.properties$/},function(e){var r=e.path;return{exports:{properties:(0,__1.getProperties)((0,node_fs_1.readFileSync)(r,"utf8"))},loader:"object"}})}};exports.default=bunPlugin;
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'esbuild';
2
+ /**
3
+ * esbuild plugin for `.properties` files.
4
+ *
5
+ * @returns An esbuild plugin that transforms `.properties` imports into JavaScript modules.
6
+ */
7
+ declare const esbuildPlugin: () => Plugin;
8
+ export default esbuildPlugin;
9
+
10
+ // Enables type recognition for direct `.properties` file imports.
11
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var node_fs_1=require("node:fs"),__1=require(".."),esbuildPlugin=function(){return{name:"properties-file",setup:function(e){e.onLoad({filter:/\.properties$/},function(e){var r=e.path;return{contents:"export const properties = ".concat(JSON.stringify((0,__1.getProperties)((0,node_fs_1.readFileSync)(r,"utf8"))),";"),loader:"js"}})}}};exports.default=esbuildPlugin;
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'rollup';
2
+ /**
3
+ * Rollup plugin for `.properties` files. Also compatible with Vite and Rolldown.
4
+ *
5
+ * @returns A Rollup plugin that transforms `.properties` imports into JavaScript modules.
6
+ */
7
+ declare const rollupPlugin: () => Plugin;
8
+ export default rollupPlugin;
9
+
10
+ // Enables type recognition for direct `.properties` file imports.
11
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __1=require(".."),PROPERTIES_EXTENSION=".properties",rollupPlugin=function(){return{name:"properties-file",transform:function(e,r){return-1===r.indexOf(PROPERTIES_EXTENSION,r.length-PROPERTIES_EXTENSION.length)?null:{code:"export const properties = ".concat(JSON.stringify((0,__1.getProperties)(e)),";"),map:null}}}};exports.default=rollupPlugin;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Webpack file loader for `.properties` files. Also compatible with Rspack.
3
+ *
4
+ * @param content - The content of a `.properties` file.
5
+ *
6
+ * @returns A CommonJS module string exporting the parsed key-value pairs.
7
+ */
8
+ declare const webpackLoader: (content: string) => string;
9
+ export default webpackLoader;
10
+
11
+ // Enables type recognition for direct `.properties` file imports.
12
+ import '../properties-file.d.ts'
@@ -70,6 +70,14 @@ export declare class PropertiesEditor extends Properties {
70
70
  * @param content - The content of a `.properties` file.
71
71
  */
72
72
  constructor(content: string);
73
+ /**
74
+ * Find the last occurrence of a property by key (iterates backward for performance).
75
+ *
76
+ * @param key - The property key to search for.
77
+ *
78
+ * @returns The last matching property, or undefined if not found.
79
+ */
80
+ private findLastPropertyByKey;
73
81
  /**
74
82
  * Parse the `.properties` content line by line only when needed.
75
83
  */
@@ -1 +1 @@
1
- "use strict";var __extends=this&&this.__extends||function(){var e=function(r,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])},e(r,n)};return function(r,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function t(){this.constructor=r}e(r,n),r.prototype=null===n?Object.create(n):(t.prototype=n.prototype,new t)}}(),__read=this&&this.__read||function(e,r){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var t,i,o=n.call(e),s=[];try{for(;(void 0===r||r-- >0)&&!(t=o.next()).done;)s.push(t.value)}catch(e){i={error:e}}finally{try{t&&!t.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s},__spreadArray=this&&this.__spreadArray||function(e,r,n){if(n||2===arguments.length)for(var t,i=0,o=r.length;i<o;i++)!t&&i in r||(t||(t=Array.prototype.slice.call(r,0,i)),t[i]=r[i]);return e.concat(t||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");exports.DEFAULT_SEPARATOR="=",exports.DEFAULT_COMMENT_DELIMITER="#";var PropertiesEditor=function(e){function r(r){var n=e.call(this,r)||this;return n.needsLineParsing=!1,n}return __extends(r,e),r.prototype.parseLinesIfNeeded=function(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)},r.prototype.insert=function(e,r,n){var t,i,o,s=(null==n?void 0:n.escapeUnicode)||!1,a=(null==n?void 0:n.separator)?" "===n.separator?" ":" ".concat(n.separator," "):" ".concat(exports.DEFAULT_SEPARATOR," ").replace(" "," "),c=null==n?void 0:n.referenceKey,l=(null==n?void 0:n.position)||"after";c&&this.parseLinesIfNeeded();var p=e.split(/\r?\n/).map(function(e){return(0,escape_1.escapeKey)(e,s)}).join("\\\n"),d=r.split(/\r?\n/).map(function(e){return(0,escape_1.escapeValue)(e,s)}).join("\\\n"),u="".concat((null==n?void 0:n.commentDelimiter)||exports.DEFAULT_COMMENT_DELIMITER," "),_=void 0===(null==n?void 0:n.comment)?"":"".concat("".concat(u).concat(n.comment).split(/\r?\n/).join("\n".concat(u)),"\n"),v="".concat(_).concat(p).concat(a).concat(d).split(/\n/);if(void 0===c)return(t=this.lines).push.apply(t,__spreadArray([],__read(v),!1)),this.needsLineParsing=!0,!0;var y=__spreadArray([],__read(this.collection),!1).reverse().find(function(e){return e.key===c});if(y){var f="after"===l?y.endingLineNumber:null!==(o=null===(i=y.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,f)),!1),__read(v),!1),__read(this.lines.slice(f)),!1),this.needsLineParsing=!0,!0}return!1},r.prototype.insertComment=function(e,r){var n,t,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," "),c="".concat(a).concat(e).replace(/\r?\n/g,"\n".concat(a)).split(/\n/);if(void 0===o)return(n=this.lines).push.apply(n,__spreadArray([],__read(c),!1)),this.needsLineParsing=!0,!0;var l=__spreadArray([],__read(this.collection),!1).reverse().find(function(e){return e.key===o});if(l){var p="after"===s?l.endingLineNumber:null!==(i=null===(t=l.previousProperty)||void 0===t?void 0:t.endingLineNumber)&&void 0!==i?i:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,p)),!1),__read(c),!1),__read(this.lines.slice(p)),!1),this.needsLineParsing=!0,!0}return!1},r.prototype.delete=function(e,r){var n,t;void 0===r&&(r=!0),this.parseLinesIfNeeded();var i=__spreadArray([],__read(this.collection),!1).reverse().find(function(r){return r.key===e});if(i){var o=r?null!==(t=null===(n=i.previousProperty)||void 0===n?void 0:n.endingLineNumber)&&void 0!==t?t: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,n,t){return"".concat(r).concat(e.newlinePositions.includes(t)?"\n":"").concat(n)},"")},r.prototype.getValueWithNewlines=function(e){return 0===e.newlinePositions.length||void 0===e.valuePosition?e.value:__spreadArray([],__read(e.value),!1).reduce(function(r,n,t){return"".concat(r).concat(e.newlinePositions.includes(t+e.valuePosition)?"\n":"").concat(n)},"")},r.prototype.update=function(e,r){var n,t,i,o;this.parseLinesIfNeeded();var s=__spreadArray([],__read(this.collection),!1).reverse().find(function(r){return r.key===e});if(!s||!r)return!1;var a=r.escapeUnicode||!1,c=r.separator?" "===r.separator?" ":" ".concat(r.separator," "):s.separator||" ".concat(exports.DEFAULT_SEPARATOR," ").replace(" "," "),l=(null!==(n=r.newKey)&&void 0!==n?n:this.getKeyWithNewlines(s)).split(/\r?\n/).map(function(e){return(0,escape_1.escapeKey)(e,a)}).join("\\\n"),p=(null!==(t=r.newValue)&&void 0!==t?t:this.getValueWithNewlines(s)).split(/\r?\n/).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(/\r?\n/).join("\n".concat(d)),"\n"),_="".concat(u).concat(l).concat(c).concat(p).split(/\n/);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,n){return this.parseLinesIfNeeded(),this.keyLineNumbers[e]?this.update(e,{newValue:r,newComment:null==n?void 0:n.comment,commentDelimiter:null==n?void 0:n.commentDelimiter,separator:null==n?void 0:n.separator,escapeUnicode:null==n?void 0:n.escapeUnicode}):this.insert(e,r,n)},r.prototype.toObject=function(){return this.parseLinesIfNeeded(),e.prototype.toObject.call(this)},r}(properties_1.Properties);exports.PropertiesEditor=PropertiesEditor;
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 +1 @@
1
- "use strict";var __makeTemplateObject=this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e};Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeValue=exports.escapeKey=void 0;var escapeKey=function(e,t){return void 0===t&&(t=!1),escapeContent(e,!0,t)};exports.escapeKey=escapeKey;var escapeValue=function(e,t){return void 0===t&&(t=!1),escapeContent(e,!1,t)};exports.escapeValue=escapeValue;var templateObject_1,templateObject_2,templateObject_3,templateObject_4,templateObject_5,templateObject_6,templateObject_7,escapeContent=function(e,t,a){return e.replace(new RegExp("[\\s!#:=\\\\".concat(a?String.raw(templateObject_2||(templateObject_2=__makeTemplateObject(["\0--￿"],["\\u0000-\\u001F\\u007F-\\uFFFF"]))):"","]"),"g"),function(e,a){var c;switch(e){case" ":return t||0===a?String.raw(templateObject_3||(templateObject_3=__makeTemplateObject([" "],["\\ "]))):" ";case"\\":return"\\\\";case"\f":return String.raw(templateObject_4||(templateObject_4=__makeTemplateObject(["\f"],["\\f"])));case"\n":return String.raw(templateObject_5||(templateObject_5=__makeTemplateObject(["\n"],["\\n"])));case"\r":return String.raw(templateObject_6||(templateObject_6=__makeTemplateObject(["\r"],["\\r"])));case"\t":return String.raw(templateObject_7||(templateObject_7=__makeTemplateObject(["\t"],["\\t"])));case"=":case":":case"#":case"!":return"\\".concat(e);default:return String.raw(templateObject_1||(templateObject_1=__makeTemplateObject([void 0,""],["\\u",""])),(null!==(c=e.codePointAt(0))&&void 0!==c?c:0).toString(16).padStart(4,"0"))}})};
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)}})};
@@ -4,7 +4,9 @@ import { Property } from './property';
4
4
  * Byte-order mark.
5
5
  */
6
6
  export declare const BOM = "\uFEFF";
7
- export declare const BOM_CODE_POINT: number | undefined;
7
+ export declare const BOM_CODE_POINT: number;
8
+ /** Matches a newline, optionally preceded by a carriage return. */
9
+ export declare const REGEX_NEWLINE: RegExp;
8
10
  /** The default end of line character. */
9
11
  export declare const DEFAULT_END_OF_LINE_CHARACTER = "\n";
10
12
  /**
@@ -1 +1 @@
1
- "use strict";var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=this&&this.__read||function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,i,n=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(o=n.next()).done;)s.push(o.value)}catch(e){i={error:e}}finally{try{o&&!o.done&&(r=n.return)&&r.call(n)}finally{if(i)throw i.error}}return s};Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyCollisions=exports.Properties=exports.getFirstEolCharacter=exports.DEFAULT_END_OF_LINE_CHARACTER=exports.BOM_CODE_POINT=exports.BOM=void 0;var property_1=require("./property"),property_line_1=require("./property-line");exports.BOM="\ufeff",exports.BOM_CODE_POINT=exports.BOM.codePointAt(0),exports.DEFAULT_END_OF_LINE_CHARACTER="\n";var getFirstEolCharacter=function(e){var t=e.indexOf("\n");return-1===t?void 0:"".concat("\r"===e[t-1]?"\r":"","\n")};exports.getFirstEolCharacter=getFirstEolCharacter;var Properties=function(){function e(e){var t;this.collection=[],this.keyLineNumbers={};var r="string"==typeof e?e:e.toString();this.hasBom=r.codePointAt(0)===exports.BOM_CODE_POINT,this.eolCharacter=null!==(t=(0,exports.getFirstEolCharacter)(r))&&void 0!==t?t:exports.DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?r.slice(1):r).split(/\r?\n/),this.parseLines()}return e.prototype.parseLines=function(){var e,t;this.collection=[],this.keyLineNumbers={};var r,o,i=0;try{for(var n=__values(this.lines),s=n.next();!s.done;s=n.next()){var l=s.value;i++;var a=new property_line_1.PropertyLine(l,!!r);if(r){if(r.addLine(a),a.isContinuing)continue}else{if(a.isComment||a.isBlank)continue;if(r=new property_1.Property(a,i,o),a.isContinuing)continue}this.addToCollection(r),o=r,r=void 0}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e.prototype.addToCollection=function(e){var t;e.setKeyAndValue(),(null===(t=this.keyLineNumbers[e.key])||void 0===t?void 0:t.length)?(this.keyLineNumbers[e.key].push(e.startingLineNumber),e.hasKeyCollisions=!0,e.keyCollisionLines=this.keyLineNumbers[e.key],this.collection=this.collection.filter(function(t){return t.key!==e.key})):this.keyLineNumbers[e.key]=[e.startingLineNumber],this.collection.push(e)},e.prototype.getKeyCollisions=function(){var e,t,r=[];try{for(var o=__values(Object.entries(this.keyLineNumbers)),i=o.next();!i.done;i=o.next()){var n=__read(i.value,2),s=n[0],l=n[1];l.length>1&&r.push(new KeyCollisions(s,l))}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return r},e.prototype.toObject=function(){var e={};return this.collection.forEach(function(t){e[t.key]=t.value}),e},e.prototype.format=function(e){return"".concat(this.hasBom?exports.BOM:"").concat(this.lines.join(e||this.eolCharacter))},e}();exports.Properties=Properties;var KeyCollisions=function(){function e(e,t){this.key=e,this.startingLineNumbers=t}return e.prototype.getApplicableLineNumber=function(){return this.startingLineNumbers.slice(-1)[0]},e}();exports.KeyCollisions=KeyCollisions;
1
+ "use strict";var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.KeyCollisions=exports.Properties=exports.getFirstEolCharacter=exports.DEFAULT_END_OF_LINE_CHARACTER=exports.REGEX_NEWLINE=exports.BOM_CODE_POINT=exports.BOM=void 0;var property_1=require("./property"),property_line_1=require("./property-line");exports.BOM="\ufeff",exports.BOM_CODE_POINT=exports.BOM.charCodeAt(0),exports.REGEX_NEWLINE=/\r?\n/,exports.DEFAULT_END_OF_LINE_CHARACTER="\n";var getFirstEolCharacter=function(e){var t=e.indexOf("\n");return-1===t?void 0:"".concat("\r"===e[t-1]?"\r":"","\n")};exports.getFirstEolCharacter=getFirstEolCharacter;var Properties=function(){function e(e){var t;this.collection=[],this.keyLineNumbers={};var r="string"==typeof e?e:e.toString();this.hasBom=r.charCodeAt(0)===exports.BOM_CODE_POINT,this.eolCharacter=null!==(t=(0,exports.getFirstEolCharacter)(r))&&void 0!==t?t:exports.DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?r.slice(1):r).split(exports.REGEX_NEWLINE),this.parseLines()}return e.prototype.parseLines=function(){var e,t;this.collection=[],this.keyLineNumbers={};var r,i,o=0;try{for(var n=__values(this.lines),s=n.next();!s.done;s=n.next()){var l=s.value;o++;var a=new property_line_1.PropertyLine(l,!!r);if(r){if(r.addLine(a),a.isContinuing)continue}else{if(a.isComment||a.isBlank)continue;if(r=new property_1.Property(a,o,i),a.isContinuing)continue}this.addToCollection(r),i=r,r=void 0}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e.prototype.addToCollection=function(e){var t;e.setKeyAndValue(),(null===(t=this.keyLineNumbers[e.key])||void 0===t?void 0:t.length)?(this.keyLineNumbers[e.key].push(e.startingLineNumber),e.hasKeyCollisions=!0,e.keyCollisionLines=this.keyLineNumbers[e.key],this.collection=this.collection.filter(function(t){return t.key!==e.key})):this.keyLineNumbers[e.key]=[e.startingLineNumber],this.collection.push(e)},e.prototype.getKeyCollisions=function(){var e,t,r=[],i=Object.keys(this.keyLineNumbers);try{for(var o=__values(i),n=o.next();!n.done;n=o.next()){var s=n.value,l=this.keyLineNumbers[s];l.length>1&&r.push(new KeyCollisions(s,l))}}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}return r},e.prototype.toObject=function(){var e={};return this.collection.forEach(function(t){e[t.key]=t.value}),e},e.prototype.format=function(e){return"".concat(this.hasBom?exports.BOM:"").concat(this.lines.join(e||this.eolCharacter))},e}();exports.Properties=Properties;var KeyCollisions=function(){function e(e,t){this.key=e,this.startingLineNumbers=t}return e.prototype.getApplicableLineNumber=function(){return this.startingLineNumbers.slice(-1)[0]},e}();exports.KeyCollisions=KeyCollisions;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;var PropertyLine=function(t,i){if(this.isContinuing=!1,this.isBlank=!1,this.isComment=!1,this.content=t.trimStart(),this.isMultiline=i,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=/^[!#]/.test(this.content)),!this.isComment){var n=this.content.match(/(\\+)$/);n&&(this.isContinuing=n[1].length%2==1,this.isContinuing&&(this.content=this.content.slice(0,-1)))}};exports.PropertyLine=PropertyLine;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;var REGEX_LEADING_WHITESPACE=/^\s+/,REGEX_COMMENT=/^[!#]/,REGEX_TRAILING_BACKSLASHES=/(\\+)$/,PropertyLine=function(t,i){if(this.isContinuing=!1,this.isBlank=!1,this.isComment=!1,this.content=t.replace(REGEX_LEADING_WHITESPACE,""),this.isMultiline=i,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=REGEX_COMMENT.test(this.content)),!this.isComment){var e=this.content.match(REGEX_TRAILING_BACKSLASHES);e&&(this.isContinuing=e[1].length%2==1,this.isContinuing&&(this.content=this.content.slice(0,-1)))}};exports.PropertyLine=PropertyLine;
@@ -1 +1 @@
1
- "use strict";var __values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],s=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;var unescape_1=require("./unescape"),Property=function(){function t(t,e,i){this.key="",this.escapedKey="",this.hasNoKey=!1,this.hasMultilineKey=!1,this.keyCollisionLines=[],this.hasKeyCollisions=!1,this.value="",this.escapedValue="",this.newlinePositions=[],this.linesContent=t.content,this.startingLineNumber=e,this.endingLineNumber=e,this.previousProperty=i,null==i||i.setNextProperty(this)}return t.prototype.setNextProperty=function(t){this.nextProperty=t},t.prototype.addLine=function(t){this.linesContent.length>0&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=t.content},t.prototype.setKeyAndValue=function(){this.findSeparator(),void 0!==this.separatorPosition&&void 0!==this.separatorLength?(this.hasNoKey||(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber)):(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},t.prototype.unescapeLine=function(t,e){try{return(0,unescape_1.unescapeContent)(t)}catch(t){throw new Error("".concat(t.message," in property starting at line ").concat(e))}},t.prototype.findSeparator=function(){var t,e,i,s,n,o;if(!this.hasNoKey&&!this.separator){try{for(var r=__values(this.linesContent.matchAll(/[\t\f :=]/g)),a=r.next();!a.done;a=r.next()){var h=a.value.index,l=this.linesContent.slice(0,h).match(/(\\+)$/);if(l)if(l[1].length%2==1)continue;var p="";this.separatorPosition=h;var u=this.linesContent.slice(h),c=null!==(s=null===(i=u.match(/^([\t\n\v\f\r ]+)/))||void 0===i?void 0:i[0])&&void 0!==s?s:"";c.length>0&&(p+=c,u=u.slice(c.length)),/[:=]/.test(u[0])&&(p+=u[0],p+=null!==(o=null===(n=(u=u.slice(1)).match(/^([\t\n\v\f\r ]+)/))||void 0===n?void 0:n[0])&&void 0!==o?o:""),this.separatorLength=p.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),h||(this.hasNoKey=!0);break}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}void 0!==this.separatorPosition&&this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();exports.Property=Property;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;var unescape_1=require("./unescape"),REGEX_TRAILING_BACKSLASHES=/(\\+)$/,REGEX_LEADING_WHITESPACE=/^([\t\n\v\f\r ]+)/,REGEX_SEPARATOR=/[\t\f :=]/g,REGEX_COLON_OR_EQUALS=/[:=]/,Property=function(){function t(t,e,i){this.key="",this.escapedKey="",this.hasNoKey=!1,this.hasMultilineKey=!1,this.keyCollisionLines=[],this.hasKeyCollisions=!1,this.value="",this.escapedValue="",this.newlinePositions=[],this.linesContent=t.content,this.startingLineNumber=e,this.endingLineNumber=e,this.previousProperty=i,null==i||i.setNextProperty(this)}return t.prototype.setNextProperty=function(t){this.nextProperty=t},t.prototype.addLine=function(t){this.linesContent.length>0&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=t.content},t.prototype.setKeyAndValue=function(){this.findSeparator(),void 0!==this.separatorPosition&&void 0!==this.separatorLength?(this.hasNoKey||(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber)):(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},t.prototype.unescapeLine=function(t,e){try{return(0,unescape_1.unescapeContent)(t)}catch(t){throw new Error("".concat(t.message," in property starting at line ").concat(e))}},t.prototype.findSeparator=function(){var t,e,i,s;if(!this.hasNoKey&&!this.separator){var n;for(REGEX_SEPARATOR.lastIndex=0;null!==(n=REGEX_SEPARATOR.exec(this.linesContent));){var o=n.index,r=this.linesContent.slice(0,o).match(REGEX_TRAILING_BACKSLASHES);if(r)if(r[1].length%2==1)continue;var h="";this.separatorPosition=o;var a=this.linesContent.slice(o),l=null!==(e=null===(t=a.match(REGEX_LEADING_WHITESPACE))||void 0===t?void 0:t[0])&&void 0!==e?e:"";l.length>0&&(h+=l,a=a.slice(l.length)),REGEX_COLON_OR_EQUALS.test(a[0])&&(h+=a[0],h+=null!==(s=null===(i=(a=a.slice(1)).match(REGEX_LEADING_WHITESPACE))||void 0===i?void 0:i[0])&&void 0!==s?s:""),this.separatorLength=h.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),o||(this.hasNoKey=!0);break}void 0!==this.separatorPosition&&this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();exports.Property=Property;
@@ -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(!e.includes("\\"))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.fromCodePoint(Number.parseInt(r,16)):null!=t?t:""})};exports.unescapeContent=unescapeContent;
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;
@@ -0,0 +1,10 @@
1
+ import type { BunPlugin } from 'bun';
2
+ /**
3
+ * Bun plugin for `.properties` files. Works with both `Bun.plugin` (runtime) and `Bun.build`
4
+ * (build-time).
5
+ */
6
+ declare const bunPlugin: BunPlugin;
7
+ export default bunPlugin;
8
+
9
+ // Enables type recognition for direct `.properties` file imports.
10
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ import{readFileSync}from"node:fs";import{getProperties}from"../index.js";var bunPlugin={name:"properties-file",setup:function(e){e.onLoad({filter:/\.properties$/},function(e){var r=e.path;return{exports:{properties:getProperties(readFileSync(r,"utf8"))},loader:"object"}})}};export default bunPlugin;
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'esbuild';
2
+ /**
3
+ * esbuild plugin for `.properties` files.
4
+ *
5
+ * @returns An esbuild plugin that transforms `.properties` imports into JavaScript modules.
6
+ */
7
+ declare const esbuildPlugin: () => Plugin;
8
+ export default esbuildPlugin;
9
+
10
+ // Enables type recognition for direct `.properties` file imports.
11
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ import{readFileSync}from"node:fs";import{getProperties}from"../index.js";var esbuildPlugin=function(){return{name:"properties-file",setup:function(e){e.onLoad({filter:/\.properties$/},function(e){var r=e.path;return{contents:"export const properties = ".concat(JSON.stringify(getProperties(readFileSync(r,"utf8"))),";"),loader:"js"}})}}};export default esbuildPlugin;
@@ -0,0 +1,11 @@
1
+ import type { Plugin } from 'rollup';
2
+ /**
3
+ * Rollup plugin for `.properties` files. Also compatible with Vite and Rolldown.
4
+ *
5
+ * @returns A Rollup plugin that transforms `.properties` imports into JavaScript modules.
6
+ */
7
+ declare const rollupPlugin: () => Plugin;
8
+ export default rollupPlugin;
9
+
10
+ // Enables type recognition for direct `.properties` file imports.
11
+ import '../properties-file.d.ts'
@@ -0,0 +1 @@
1
+ import{getProperties}from"../index.js";var PROPERTIES_EXTENSION=".properties",rollupPlugin=function(){return{name:"properties-file",transform:function(e,r){return-1===r.indexOf(PROPERTIES_EXTENSION,r.length-PROPERTIES_EXTENSION.length)?null:{code:"export const properties = ".concat(JSON.stringify(getProperties(e)),";"),map:null}}}};export default rollupPlugin;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Webpack file loader for `.properties` files. Also compatible with Rspack.
3
+ *
4
+ * @param content - The content of a `.properties` file.
5
+ *
6
+ * @returns A CommonJS module string exporting the parsed key-value pairs.
7
+ */
8
+ declare const webpackLoader: (content: string) => string;
9
+ export default webpackLoader;
10
+
11
+ // Enables type recognition for direct `.properties` file imports.
12
+ import '../properties-file.d.ts'
@@ -70,6 +70,14 @@ export declare class PropertiesEditor extends Properties {
70
70
  * @param content - The content of a `.properties` file.
71
71
  */
72
72
  constructor(content: string);
73
+ /**
74
+ * Find the last occurrence of a property by key (iterates backward for performance).
75
+ *
76
+ * @param key - The property key to search for.
77
+ *
78
+ * @returns The last matching property, or undefined if not found.
79
+ */
80
+ private findLastPropertyByKey;
73
81
  /**
74
82
  * Parse the `.properties` content line by line only when needed.
75
83
  */
@@ -1 +1 @@
1
- var __extends=this&&this.__extends||function(){var e=function(n,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])},e(n,r)};return function(n,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function t(){this.constructor=n}e(n,r),n.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}}(),__read=this&&this.__read||function(e,n){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var t,i,o=r.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(t=o.next()).done;)a.push(t.value)}catch(e){i={error:e}}finally{try{t&&!t.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a},__spreadArray=this&&this.__spreadArray||function(e,n,r){if(r||2===arguments.length)for(var t,i=0,o=n.length;i<o;i++)!t&&i in n||(t||(t=Array.prototype.slice.call(n,0,i)),t[i]=n[i]);return e.concat(t||Array.prototype.slice.call(n))};import{escapeKey,escapeValue}from"../escape/index.js";import{Properties}from"../properties.js";export var DEFAULT_SEPARATOR="=";export var DEFAULT_COMMENT_DELIMITER="#";var PropertiesEditor=function(e){function n(n){var r=e.call(this,n)||this;return r.needsLineParsing=!1,r}return __extends(n,e),n.prototype.parseLinesIfNeeded=function(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)},n.prototype.insert=function(e,n,r){var t,i,o,a=(null==r?void 0:r.escapeUnicode)||!1,s=(null==r?void 0:r.separator)?" "===r.separator?" ":" ".concat(r.separator," "):" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),c=null==r?void 0:r.referenceKey,l=(null==r?void 0:r.position)||"after";c&&this.parseLinesIfNeeded();var p=e.split(/\r?\n/).map(function(e){return escapeKey(e,a)}).join("\\\n"),d=n.split(/\r?\n/).map(function(e){return escapeValue(e,a)}).join("\\\n"),u="".concat((null==r?void 0:r.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),_=void 0===(null==r?void 0:r.comment)?"":"".concat("".concat(u).concat(r.comment).split(/\r?\n/).join("\n".concat(u)),"\n"),v="".concat(_).concat(p).concat(s).concat(d).split(/\n/);if(void 0===c)return(t=this.lines).push.apply(t,__spreadArray([],__read(v),!1)),this.needsLineParsing=!0,!0;var y=__spreadArray([],__read(this.collection),!1).reverse().find(function(e){return e.key===c});if(y){var f="after"===l?y.endingLineNumber:null!==(o=null===(i=y.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,f)),!1),__read(v),!1),__read(this.lines.slice(f)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.insertComment=function(e,n){var r,t,i,o=null==n?void 0:n.referenceKey,a=(null==n?void 0:n.position)||"after";o&&this.parseLinesIfNeeded();var s="".concat((null==n?void 0:n.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),c="".concat(s).concat(e).replace(/\r?\n/g,"\n".concat(s)).split(/\n/);if(void 0===o)return(r=this.lines).push.apply(r,__spreadArray([],__read(c),!1)),this.needsLineParsing=!0,!0;var l=__spreadArray([],__read(this.collection),!1).reverse().find(function(e){return e.key===o});if(l){var p="after"===a?l.endingLineNumber:null!==(i=null===(t=l.previousProperty)||void 0===t?void 0:t.endingLineNumber)&&void 0!==i?i:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,p)),!1),__read(c),!1),__read(this.lines.slice(p)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.delete=function(e,n){var r,t;void 0===n&&(n=!0),this.parseLinesIfNeeded();var i=__spreadArray([],__read(this.collection),!1).reverse().find(function(n){return n.key===e});if(i){var o=n?null!==(t=null===(r=i.previousProperty)||void 0===r?void 0:r.endingLineNumber)&&void 0!==t?t:0:i.startingLineNumber-1,a=i.endingLineNumber;return this.lines=__spreadArray(__spreadArray([],__read(this.lines.slice(0,o)),!1),__read(this.lines.slice(a)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.getKeyWithNewlines=function(e){return 0===e.newlinePositions.length?e.key:__spreadArray([],__read(e.key),!1).reduce(function(n,r,t){return"".concat(n).concat(e.newlinePositions.includes(t)?"\n":"").concat(r)},"")},n.prototype.getValueWithNewlines=function(e){return 0===e.newlinePositions.length||void 0===e.valuePosition?e.value:__spreadArray([],__read(e.value),!1).reduce(function(n,r,t){return"".concat(n).concat(e.newlinePositions.includes(t+e.valuePosition)?"\n":"").concat(r)},"")},n.prototype.update=function(e,n){var r,t,i,o;this.parseLinesIfNeeded();var a=__spreadArray([],__read(this.collection),!1).reverse().find(function(n){return n.key===e});if(!a||!n)return!1;var s=n.escapeUnicode||!1,c=n.separator?" "===n.separator?" ":" ".concat(n.separator," "):a.separator||" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),l=(null!==(r=n.newKey)&&void 0!==r?r:this.getKeyWithNewlines(a)).split(/\r?\n/).map(function(e){return escapeKey(e,s)}).join("\\\n"),p=(null!==(t=n.newValue)&&void 0!==t?t:this.getValueWithNewlines(a)).split(/\r?\n/).map(function(e){return escapeValue(e,s)}).join("\\\n"),d="".concat(n.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),u=void 0===n.newComment?"":"".concat("".concat(d).concat(n.newComment).split(/\r?\n/).join("\n".concat(d)),"\n"),_="".concat(u).concat(l).concat(c).concat(p).split(/\n/);return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,void 0===n.newComment?a.startingLineNumber-1:null!==(o=null===(i=a.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0)),!1),__read(_),!1),__read(this.lines.slice(a.endingLineNumber)),!1),this.needsLineParsing=!0,!0},n.prototype.upsert=function(e,n,r){return this.parseLinesIfNeeded(),this.keyLineNumbers[e]?this.update(e,{newValue:n,newComment:null==r?void 0:r.comment,commentDelimiter:null==r?void 0:r.commentDelimiter,separator:null==r?void 0:r.separator,escapeUnicode:null==r?void 0:r.escapeUnicode}):this.insert(e,n,r)},n.prototype.toObject=function(){return this.parseLinesIfNeeded(),e.prototype.toObject.call(this)},n}(Properties);export{PropertiesEditor};
1
+ var __extends=this&&this.__extends||function(){var e=function(n,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])},e(n,r)};return function(n,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function t(){this.constructor=n}e(n,r),n.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}}(),__read=this&&this.__read||function(e,n){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var t,i,o=r.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(t=o.next()).done;)a.push(t.value)}catch(e){i={error:e}}finally{try{t&&!t.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a},__spreadArray=this&&this.__spreadArray||function(e,n,r){if(r||2===arguments.length)for(var t,i=0,o=n.length;i<o;i++)!t&&i in n||(t||(t=Array.prototype.slice.call(n,0,i)),t[i]=n[i]);return e.concat(t||Array.prototype.slice.call(n))};import{escapeKey,escapeValue}from"../escape/index.js";import{Properties,REGEX_NEWLINE}from"../properties.js";var REGEX_NEWLINE_GLOBAL=/\r?\n/g,REGEX_LF=/\n/;export var DEFAULT_SEPARATOR="=";export var DEFAULT_COMMENT_DELIMITER="#";var PropertiesEditor=function(e){function n(n){var r=e.call(this,n)||this;return r.needsLineParsing=!1,r}return __extends(n,e),n.prototype.findLastPropertyByKey=function(e){for(var n=this.collection.length-1;n>=0;n--){var r=this.collection[n];if(r.key===e)return r}},n.prototype.parseLinesIfNeeded=function(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)},n.prototype.insert=function(e,n,r){var t,i,o,a=(null==r?void 0:r.escapeUnicode)||!1,s=(null==r?void 0:r.separator)?" "===r.separator?" ":" ".concat(r.separator," "):" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),c=null==r?void 0:r.referenceKey,l=(null==r?void 0:r.position)||"after";c&&this.parseLinesIfNeeded();var p=e.split(REGEX_NEWLINE).map(function(e){return escapeKey(e,a)}).join("\\\n"),d=n.split(REGEX_NEWLINE).map(function(e){return escapeValue(e,a)}).join("\\\n"),u="".concat((null==r?void 0:r.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),_=void 0===(null==r?void 0:r.comment)?"":"".concat("".concat(u).concat(r.comment).split(REGEX_NEWLINE).join("\n".concat(u)),"\n"),y="".concat(_).concat(p).concat(s).concat(d).split(REGEX_LF);if(void 0===c)return(t=this.lines).push.apply(t,__spreadArray([],__read(y),!1)),this.needsLineParsing=!0,!0;var v=this.findLastPropertyByKey(c);if(v){var f="after"===l?v.endingLineNumber:null!==(o=null===(i=v.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,f)),!1),__read(y),!1),__read(this.lines.slice(f)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.insertComment=function(e,n){var r,t,i,o=null==n?void 0:n.referenceKey,a=(null==n?void 0:n.position)||"after";o&&this.parseLinesIfNeeded();var s="".concat((null==n?void 0:n.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),c="".concat(s).concat(e).replace(REGEX_NEWLINE_GLOBAL,"\n".concat(s)).split(REGEX_LF);if(void 0===o)return(r=this.lines).push.apply(r,__spreadArray([],__read(c),!1)),this.needsLineParsing=!0,!0;var l=this.findLastPropertyByKey(o);if(l){var p="after"===a?l.endingLineNumber:null!==(i=null===(t=l.previousProperty)||void 0===t?void 0:t.endingLineNumber)&&void 0!==i?i:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,p)),!1),__read(c),!1),__read(this.lines.slice(p)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.delete=function(e,n){var r,t;void 0===n&&(n=!0),this.parseLinesIfNeeded();var i=this.findLastPropertyByKey(e);if(i){var o=n?null!==(t=null===(r=i.previousProperty)||void 0===r?void 0:r.endingLineNumber)&&void 0!==t?t:0:i.startingLineNumber-1,a=i.endingLineNumber;return this.lines=__spreadArray(__spreadArray([],__read(this.lines.slice(0,o)),!1),__read(this.lines.slice(a)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.getKeyWithNewlines=function(e){return 0===e.newlinePositions.length?e.key:__spreadArray([],__read(e.key),!1).reduce(function(n,r,t){return"".concat(n).concat(-1!==e.newlinePositions.indexOf(t)?"\n":"").concat(r)},"")},n.prototype.getValueWithNewlines=function(e){return 0===e.newlinePositions.length||void 0===e.valuePosition?e.value:__spreadArray([],__read(e.value),!1).reduce(function(n,r,t){return"".concat(n).concat(-1!==e.newlinePositions.indexOf(t+e.valuePosition)?"\n":"").concat(r)},"")},n.prototype.update=function(e,n){var r,t,i,o;this.parseLinesIfNeeded();var a=this.findLastPropertyByKey(e);if(!a||!n)return!1;var s=n.escapeUnicode||!1,c=n.separator?" "===n.separator?" ":" ".concat(n.separator," "):a.separator||" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),l=(null!==(r=n.newKey)&&void 0!==r?r:this.getKeyWithNewlines(a)).split(REGEX_NEWLINE).map(function(e){return escapeKey(e,s)}).join("\\\n"),p=(null!==(t=n.newValue)&&void 0!==t?t:this.getValueWithNewlines(a)).split(REGEX_NEWLINE).map(function(e){return escapeValue(e,s)}).join("\\\n"),d="".concat(n.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),u=void 0===n.newComment?"":"".concat("".concat(d).concat(n.newComment).split(REGEX_NEWLINE).join("\n".concat(d)),"\n"),_="".concat(u).concat(l).concat(c).concat(p).split(REGEX_LF);return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,void 0===n.newComment?a.startingLineNumber-1:null!==(o=null===(i=a.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0)),!1),__read(_),!1),__read(this.lines.slice(a.endingLineNumber)),!1),this.needsLineParsing=!0,!0},n.prototype.upsert=function(e,n,r){return this.parseLinesIfNeeded(),this.keyLineNumbers[e]?this.update(e,{newValue:n,newComment:null==r?void 0:r.comment,commentDelimiter:null==r?void 0:r.commentDelimiter,separator:null==r?void 0:r.separator,escapeUnicode:null==r?void 0:r.escapeUnicode}):this.insert(e,n,r)},n.prototype.toObject=function(){return this.parseLinesIfNeeded(),e.prototype.toObject.call(this)},n}(Properties);export{PropertiesEditor};
@@ -1 +1 @@
1
- var __makeTemplateObject=this&&this.__makeTemplateObject||function(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e};export var escapeKey=function(e,t){return void 0===t&&(t=!1),escapeContent(e,!0,t)};export var escapeValue=function(e,t){return void 0===t&&(t=!1),escapeContent(e,!1,t)};var templateObject_1,templateObject_2,templateObject_3,templateObject_4,templateObject_5,templateObject_6,templateObject_7,escapeContent=function(e,t,a){return e.replace(new RegExp("[\\s!#:=\\\\".concat(a?String.raw(templateObject_2||(templateObject_2=__makeTemplateObject(["\0--￿"],["\\u0000-\\u001F\\u007F-\\uFFFF"]))):"","]"),"g"),function(e,a){var c;switch(e){case" ":return t||0===a?String.raw(templateObject_3||(templateObject_3=__makeTemplateObject([" "],["\\ "]))):" ";case"\\":return"\\\\";case"\f":return String.raw(templateObject_4||(templateObject_4=__makeTemplateObject(["\f"],["\\f"])));case"\n":return String.raw(templateObject_5||(templateObject_5=__makeTemplateObject(["\n"],["\\n"])));case"\r":return String.raw(templateObject_6||(templateObject_6=__makeTemplateObject(["\r"],["\\r"])));case"\t":return String.raw(templateObject_7||(templateObject_7=__makeTemplateObject(["\t"],["\\t"])));case"=":case":":case"#":case"!":return"\\".concat(e);default:return String.raw(templateObject_1||(templateObject_1=__makeTemplateObject([void 0,""],["\\u",""])),(null!==(c=e.codePointAt(0))&&void 0!==c?c:0).toString(16).padStart(4,"0"))}})};
1
+ export var escapeKey=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!0,r)};export var escapeValue=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!1,r)};var escapeContent=function(e,r,n){return e.replace(new RegExp("[\\s!#:=\\\\".concat(n?"\0--￿":"","]"),"g"),function(e,n){var t;switch(e){case" ":return r||0===n?"\\ ":" ";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!==(t=e.charCodeAt(0))&&void 0!==t?t:0).toString(16)).slice(-4)}})};
@@ -4,7 +4,9 @@ import { Property } from './property.js';
4
4
  * Byte-order mark.
5
5
  */
6
6
  export declare const BOM = "\uFEFF";
7
- export declare const BOM_CODE_POINT: number | undefined;
7
+ export declare const BOM_CODE_POINT: number;
8
+ /** Matches a newline, optionally preceded by a carriage return. */
9
+ export declare const REGEX_NEWLINE: RegExp;
8
10
  /** The default end of line character. */
9
11
  export declare const DEFAULT_END_OF_LINE_CHARACTER = "\n";
10
12
  /**
@@ -1 +1 @@
1
- var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")},__read=this&&this.__read||function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s};import{Property}from"./property.js";import{PropertyLine}from"./property-line.js";export var BOM="\ufeff";export var BOM_CODE_POINT=BOM.codePointAt(0);export var DEFAULT_END_OF_LINE_CHARACTER="\n";export var getFirstEolCharacter=function(e){var t=e.indexOf("\n");return-1===t?void 0:"".concat("\r"===e[t-1]?"\r":"","\n")};var Properties=function(){function e(e){var t;this.collection=[],this.keyLineNumbers={};var r="string"==typeof e?e:e.toString();this.hasBom=r.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=null!==(t=getFirstEolCharacter(r))&&void 0!==t?t:DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?r.slice(1):r).split(/\r?\n/),this.parseLines()}return e.prototype.parseLines=function(){var e,t;this.collection=[],this.keyLineNumbers={};var r,n,i=0;try{for(var o=__values(this.lines),s=o.next();!s.done;s=o.next()){var l=s.value;i++;var a=new PropertyLine(l,!!r);if(r){if(r.addLine(a),a.isContinuing)continue}else{if(a.isComment||a.isBlank)continue;if(r=new Property(a,i,n),a.isContinuing)continue}this.addToCollection(r),n=r,r=void 0}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}},e.prototype.addToCollection=function(e){var t;e.setKeyAndValue(),(null===(t=this.keyLineNumbers[e.key])||void 0===t?void 0:t.length)?(this.keyLineNumbers[e.key].push(e.startingLineNumber),e.hasKeyCollisions=!0,e.keyCollisionLines=this.keyLineNumbers[e.key],this.collection=this.collection.filter(function(t){return t.key!==e.key})):this.keyLineNumbers[e.key]=[e.startingLineNumber],this.collection.push(e)},e.prototype.getKeyCollisions=function(){var e,t,r=[];try{for(var n=__values(Object.entries(this.keyLineNumbers)),i=n.next();!i.done;i=n.next()){var o=__read(i.value,2),s=o[0],l=o[1];l.length>1&&r.push(new KeyCollisions(s,l))}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}return r},e.prototype.toObject=function(){var e={};return this.collection.forEach(function(t){e[t.key]=t.value}),e},e.prototype.format=function(e){return"".concat(this.hasBom?BOM:"").concat(this.lines.join(e||this.eolCharacter))},e}();export{Properties};var KeyCollisions=function(){function e(e,t){this.key=e,this.startingLineNumbers=t}return e.prototype.getApplicableLineNumber=function(){return this.startingLineNumbers.slice(-1)[0]},e}();export{KeyCollisions};
1
+ var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],i=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&i>=e.length&&(e=void 0),{value:e&&e[i++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")};import{Property}from"./property.js";import{PropertyLine}from"./property-line.js";export var BOM="\ufeff";export var BOM_CODE_POINT=BOM.charCodeAt(0);export var REGEX_NEWLINE=/\r?\n/;export var DEFAULT_END_OF_LINE_CHARACTER="\n";export var getFirstEolCharacter=function(e){var t=e.indexOf("\n");return-1===t?void 0:"".concat("\r"===e[t-1]?"\r":"","\n")};var Properties=function(){function e(e){var t;this.collection=[],this.keyLineNumbers={};var r="string"==typeof e?e:e.toString();this.hasBom=r.charCodeAt(0)===BOM_CODE_POINT,this.eolCharacter=null!==(t=getFirstEolCharacter(r))&&void 0!==t?t:DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?r.slice(1):r).split(REGEX_NEWLINE),this.parseLines()}return e.prototype.parseLines=function(){var e,t;this.collection=[],this.keyLineNumbers={};var r,i,n=0;try{for(var o=__values(this.lines),s=o.next();!s.done;s=o.next()){var l=s.value;n++;var a=new PropertyLine(l,!!r);if(r){if(r.addLine(a),a.isContinuing)continue}else{if(a.isComment||a.isBlank)continue;if(r=new Property(a,n,i),a.isContinuing)continue}this.addToCollection(r),i=r,r=void 0}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=o.return)&&t.call(o)}finally{if(e)throw e.error}}},e.prototype.addToCollection=function(e){var t;e.setKeyAndValue(),(null===(t=this.keyLineNumbers[e.key])||void 0===t?void 0:t.length)?(this.keyLineNumbers[e.key].push(e.startingLineNumber),e.hasKeyCollisions=!0,e.keyCollisionLines=this.keyLineNumbers[e.key],this.collection=this.collection.filter(function(t){return t.key!==e.key})):this.keyLineNumbers[e.key]=[e.startingLineNumber],this.collection.push(e)},e.prototype.getKeyCollisions=function(){var e,t,r=[],i=Object.keys(this.keyLineNumbers);try{for(var n=__values(i),o=n.next();!o.done;o=n.next()){var s=o.value,l=this.keyLineNumbers[s];l.length>1&&r.push(new KeyCollisions(s,l))}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}return r},e.prototype.toObject=function(){var e={};return this.collection.forEach(function(t){e[t.key]=t.value}),e},e.prototype.format=function(e){return"".concat(this.hasBom?BOM:"").concat(this.lines.join(e||this.eolCharacter))},e}();export{Properties};var KeyCollisions=function(){function e(e,t){this.key=e,this.startingLineNumbers=t}return e.prototype.getApplicableLineNumber=function(){return this.startingLineNumbers.slice(-1)[0]},e}();export{KeyCollisions};
@@ -1 +1 @@
1
- var PropertyLine=function(t,i){if(this.isContinuing=!1,this.isBlank=!1,this.isComment=!1,this.content=t.trimStart(),this.isMultiline=i,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=/^[!#]/.test(this.content)),!this.isComment){var n=this.content.match(/(\\+)$/);n&&(this.isContinuing=n[1].length%2==1,this.isContinuing&&(this.content=this.content.slice(0,-1)))}};export{PropertyLine};
1
+ var REGEX_LEADING_WHITESPACE=/^\s+/,REGEX_COMMENT=/^[!#]/,REGEX_TRAILING_BACKSLASHES=/(\\+)$/,PropertyLine=function(t,i){if(this.isContinuing=!1,this.isBlank=!1,this.isComment=!1,this.content=t.replace(REGEX_LEADING_WHITESPACE,""),this.isMultiline=i,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=REGEX_COMMENT.test(this.content)),!this.isComment){var n=this.content.match(REGEX_TRAILING_BACKSLASHES);n&&(this.isContinuing=n[1].length%2==1,this.isContinuing&&(this.content=this.content.slice(0,-1)))}};export{PropertyLine};
@@ -1 +1 @@
1
- var __values=this&&this.__values||function(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")};import{unescapeContent}from"./unescape/index.js";var Property=function(){function t(t,e,i){this.key="",this.escapedKey="",this.hasNoKey=!1,this.hasMultilineKey=!1,this.keyCollisionLines=[],this.hasKeyCollisions=!1,this.value="",this.escapedValue="",this.newlinePositions=[],this.linesContent=t.content,this.startingLineNumber=e,this.endingLineNumber=e,this.previousProperty=i,null==i||i.setNextProperty(this)}return t.prototype.setNextProperty=function(t){this.nextProperty=t},t.prototype.addLine=function(t){this.linesContent.length>0&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=t.content},t.prototype.setKeyAndValue=function(){this.findSeparator(),void 0!==this.separatorPosition&&void 0!==this.separatorLength?(this.hasNoKey||(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber)):(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},t.prototype.unescapeLine=function(t,e){try{return unescapeContent(t)}catch(t){throw new Error("".concat(t.message," in property starting at line ").concat(e))}},t.prototype.findSeparator=function(){var t,e,i,n,s,o;if(!this.hasNoKey&&!this.separator){try{for(var r=__values(this.linesContent.matchAll(/[\t\f :=]/g)),a=r.next();!a.done;a=r.next()){var h=a.value.index,l=this.linesContent.slice(0,h).match(/(\\+)$/);if(l)if(l[1].length%2==1)continue;var p="";this.separatorPosition=h;var u=this.linesContent.slice(h),c=null!==(n=null===(i=u.match(/^([\t\n\v\f\r ]+)/))||void 0===i?void 0:i[0])&&void 0!==n?n:"";c.length>0&&(p+=c,u=u.slice(c.length)),/[:=]/.test(u[0])&&(p+=u[0],p+=null!==(o=null===(s=(u=u.slice(1)).match(/^([\t\n\v\f\r ]+)/))||void 0===s?void 0:s[0])&&void 0!==o?o:""),this.separatorLength=p.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),h||(this.hasNoKey=!0);break}}catch(e){t={error:e}}finally{try{a&&!a.done&&(e=r.return)&&e.call(r)}finally{if(t)throw t.error}}void 0!==this.separatorPosition&&this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();export{Property};
1
+ import{unescapeContent}from"./unescape/index.js";var REGEX_TRAILING_BACKSLASHES=/(\\+)$/,REGEX_LEADING_WHITESPACE=/^([\t\n\v\f\r ]+)/,REGEX_SEPARATOR=/[\t\f :=]/g,REGEX_COLON_OR_EQUALS=/[:=]/,Property=function(){function t(t,e,i){this.key="",this.escapedKey="",this.hasNoKey=!1,this.hasMultilineKey=!1,this.keyCollisionLines=[],this.hasKeyCollisions=!1,this.value="",this.escapedValue="",this.newlinePositions=[],this.linesContent=t.content,this.startingLineNumber=e,this.endingLineNumber=e,this.previousProperty=i,null==i||i.setNextProperty(this)}return t.prototype.setNextProperty=function(t){this.nextProperty=t},t.prototype.addLine=function(t){this.linesContent.length>0&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=t.content},t.prototype.setKeyAndValue=function(){this.findSeparator(),void 0!==this.separatorPosition&&void 0!==this.separatorLength?(this.hasNoKey||(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber)):(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},t.prototype.unescapeLine=function(t,e){try{return unescapeContent(t)}catch(t){throw new Error("".concat(t.message," in property starting at line ").concat(e))}},t.prototype.findSeparator=function(){var t,e,i,s;if(!this.hasNoKey&&!this.separator){var n;for(REGEX_SEPARATOR.lastIndex=0;null!==(n=REGEX_SEPARATOR.exec(this.linesContent));){var o=n.index,h=this.linesContent.slice(0,o).match(REGEX_TRAILING_BACKSLASHES);if(h)if(h[1].length%2==1)continue;var r="";this.separatorPosition=o;var a=this.linesContent.slice(o),l=null!==(e=null===(t=a.match(REGEX_LEADING_WHITESPACE))||void 0===t?void 0:t[0])&&void 0!==e?e:"";l.length>0&&(r+=l,a=a.slice(l.length)),REGEX_COLON_OR_EQUALS.test(a[0])&&(r+=a[0],r+=null!==(s=null===(i=(a=a.slice(1)).match(REGEX_LEADING_WHITESPACE))||void 0===i?void 0:i[0])&&void 0!==s?s:""),this.separatorLength=r.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),o||(this.hasNoKey=!0);break}void 0!==this.separatorPosition&&this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();export{Property};
@@ -1 +1 @@
1
- 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"};export var unescapeContent=function(r){var n;if(!r.includes("\\"))return r;var E=r.match(REGEX_INVALID_UNICODE_ESCAPE);if(E){var e=null!==(n=E.index)&&void 0!==n?n:0,t=r.slice(e,e+6);throw new Error("malformed escaped unicode characters '".concat(t,"'"))}return r.replace(REGEX_ESCAPE,function(r,n,E,e){return n?ESCAPE_MAP[n]:E?String.fromCodePoint(Number.parseInt(E,16)):null!=e?e:""})};
1
+ 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"};export var unescapeContent=function(r){var E;if(-1===r.indexOf("\\"))return r;var n=r.match(REGEX_INVALID_UNICODE_ESCAPE);if(n){var e=null!==(E=n.index)&&void 0!==E?E:0,a=r.slice(e,e+6);throw new Error("malformed escaped unicode characters '".concat(a,"'"))}return r.replace(REGEX_ESCAPE,function(r,E,n,e){return E?ESCAPE_MAP[E]:n?String.fromCharCode(parseInt(n,16)):null!=e?e:""})};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "properties-file",
3
- "version": "3.6.5",
4
- "description": ".properties file parser, editor, formatter and Webpack loader.",
3
+ "version": "4.0.0",
4
+ "description": ".properties file parser, editor, formatter and bundler integrations.",
5
5
  "keywords": [
6
6
  ".properties",
7
7
  "properties",
@@ -13,8 +13,11 @@
13
13
  "Java",
14
14
  "intl",
15
15
  "i18n",
16
- "properties Webpack loader",
17
16
  "Webpack loader",
17
+ "Rollup plugin",
18
+ "Vite plugin",
19
+ "esbuild plugin",
20
+ "Bun plugin",
18
21
  "internationalization"
19
22
  ],
20
23
  "repository": {
@@ -36,6 +39,46 @@
36
39
  "default": "./dist/cjs/index.js"
37
40
  }
38
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
+ },
39
82
  "./editor": {
40
83
  "import": {
41
84
  "types": "./dist/esm/editor/index.d.ts",
@@ -65,16 +108,6 @@
65
108
  "types": "./dist/cjs/unescape/index.d.ts",
66
109
  "default": "./dist/cjs/unescape/index.js"
67
110
  }
68
- },
69
- "./webpack-loader": {
70
- "import": {
71
- "types": "./dist/esm/loader/webpack.d.ts",
72
- "default": "./dist/esm/loader/webpack.js"
73
- },
74
- "require": {
75
- "types": "./dist/cjs/loader/webpack.d.ts",
76
- "default": "./dist/cjs/loader/webpack.js"
77
- }
78
111
  }
79
112
  },
80
113
  "main": "dist/cjs/index.js",
@@ -85,6 +118,8 @@
85
118
  ],
86
119
  "scripts": {
87
120
  "add-file-type-declaration": "node ./dist/esm/add-import-type.js && find ./dist -name 'add-import-type.*' -type f -delete",
121
+ "benchmark": "npx tsx benchmarks/run.ts",
122
+ "benchmark-compare": "npx tsx benchmarks/compare.ts",
88
123
  "build": "npm run check-nvm-node-version && npm run prettier-write && npm run eslint-fix && rm -Rf ./dist && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{ \"type\": \"commonjs\" }' > dist/cjs/package.json && tsc -p src/build-scripts/tsconfig.json && node dist/build-scripts/build.js && npm run test",
89
124
  "check-nvm-node-version": "check-node-version --node $(node -p \"'>='+require('fs').readFileSync('.nvmrc','utf-8').trim()\")",
90
125
  "depcheck": "depcheck",
@@ -98,16 +133,17 @@
98
133
  },
99
134
  "devDependencies": {
100
135
  "@release-it/conventional-changelog": "10.0.6",
136
+ "@types/bun": "1.3.11",
101
137
  "@types/jest": "30.0.0",
102
138
  "@types/node": "25.5.0",
103
- "baseline-browser-mapping": "2.10.8",
104
139
  "check-node-version": "4.2.1",
105
140
  "depcheck": "1.4.7",
106
141
  "dotenv-cli": "11.0.0",
107
- "eslint": "10.0.3",
142
+ "esbuild": "0.27.4",
143
+ "eslint": "10.1.0",
108
144
  "eslint-config-prettier": "10.1.8",
109
145
  "eslint-import-resolver-typescript": "4.4.4",
110
- "eslint-plugin-compat": "7.0.1",
146
+ "eslint-plugin-es-x": "9.6.0",
111
147
  "eslint-plugin-import-x": "4.16.2",
112
148
  "eslint-plugin-jest": "29.15.0",
113
149
  "eslint-plugin-package-json": "0.91.0",
@@ -119,14 +155,16 @@
119
155
  "jest": "30.3.0",
120
156
  "jiti": "2.6.1",
121
157
  "jsonc-eslint-parser": "3.1.0",
122
- "npm-check-updates": "19.6.3",
158
+ "npm-check-updates": "19.6.5",
123
159
  "prettier": "3.8.1",
124
160
  "prettier-plugin-organize-imports": "4.3.0",
125
161
  "release-it": "19.2.4",
126
- "terser": "5.46.0",
162
+ "rollup": "4.60.0",
163
+ "terser": "5.46.1",
164
+ "tinybench": "6.0.0",
127
165
  "ts-jest": "29.4.6",
128
166
  "typescript": "5.9.3",
129
- "typescript-eslint": "8.57.0"
167
+ "typescript-eslint": "8.57.1"
130
168
  },
131
169
  "engines": {
132
170
  "node": "*"
@@ -1,12 +0,0 @@
1
- /**
2
- * Webpack file loader for `.properties` files.
3
- *
4
- * @param content - the content of a `.properties` file.
5
- *
6
- * @returns A Webpack file loader string containing the content of a `.properties` file.
7
- */
8
- declare const webpackLoader: (content: string) => string;
9
- export default webpackLoader;
10
-
11
- // Enables type recognition for direct `.properties` file imports.
12
- import '../properties-file.d.ts'
@@ -1,12 +0,0 @@
1
- /**
2
- * Webpack file loader for `.properties` files.
3
- *
4
- * @param content - the content of a `.properties` file.
5
- *
6
- * @returns A Webpack file loader string containing the content of a `.properties` file.
7
- */
8
- declare const webpackLoader: (content: string) => string;
9
- export default webpackLoader;
10
-
11
- // Enables type recognition for direct `.properties` file imports.
12
- import '../properties-file.d.ts'
File without changes
File without changes