properties-file 3.4.0 → 3.5.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
@@ -212,18 +212,21 @@ module.exports = {
212
212
 
213
213
  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:
214
214
 
215
- ```js
216
- // properties-file.d.ts
215
+ ```ts
217
216
  declare module '*.properties' {
218
- const properties: { readonly [key: string]: string };
219
- export default properties;
217
+ /** A key/value object representing the content of a `.properties` file. */
218
+ const properties: {
219
+ /** The value of a `.properties` file key. */
220
+ [key: string]: string
221
+ }
222
+ export { properties }
220
223
  }
221
224
  ```
222
225
 
223
226
  By adding these configurations you should now be able to import directly `.properties` files just like this:
224
227
 
225
228
  ```ts
226
- import helloWorld from './hello-world.properties'
229
+ import { properties as helloWorld } from './hello-world.properties'
227
230
 
228
231
  console.dir(helloWorld)
229
232
  ```
@@ -1,4 +1,3 @@
1
- /// <reference types="./properties-file" />
2
1
  /// <reference types="node" />
3
2
  export { Properties } from './properties';
4
3
  /**
@@ -15,3 +14,6 @@ export type KeyValuePairObject = {
15
14
  * @returns A key/value object representing the content of a `.properties` file.
16
15
  */
17
16
  export declare const getProperties: (content: string | Buffer) => KeyValuePairObject;
17
+
18
+ // Enables type recognition for direct `.properties` file imports.
19
+ import './properties-file.d.ts'
@@ -1,4 +1,3 @@
1
- /// <reference types="../properties-file" />
2
1
  /**
3
2
  * Webpack file loader for `.properties` files.
4
3
  *
@@ -8,3 +7,6 @@
8
7
  */
9
8
  declare const webpackLoader: (content: string) => string;
10
9
  export default webpackLoader;
10
+
11
+ // Enables type recognition for direct `.properties` file imports.
12
+ import '../properties-file.d.ts'
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __1=require(".."),webpackLoader=function(e){return"module.exports = ".concat(JSON.stringify((0,__1.getProperties)(e)),";")};exports.default=webpackLoader;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var __1=require(".."),webpackLoader=function(e){return"exports.properties = ".concat(JSON.stringify((0,__1.getProperties)(e)),";")};exports.default=webpackLoader;
@@ -1,7 +1,8 @@
1
- /** This allows to get the correct type when using `import` on `.properties` files. */
2
1
  declare module '*.properties' {
2
+ /** A key/value object representing the content of a `.properties` file. */
3
3
  const properties: {
4
- readonly [key: string]: string
4
+ /** The value of a `.properties` file key. */
5
+ [key: string]: string
5
6
  }
6
- export default properties
7
+ export { properties }
7
8
  }
@@ -1,4 +1,4 @@
1
- import { Properties } from '../properties';
1
+ import { Properties } from '../properties.js';
2
2
  /** The default separator between keys and values. */
3
3
  export declare const DEFAULT_SEPARATOR = "=";
4
4
  /** The default character used as comment delimiter. */
@@ -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";import{Properties}from"../properties";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}(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}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 d=e.split(/\r?\n/).map((function(e){return escapeKey(e,a)})).join("\\\n"),p=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(d).concat(s).concat(p).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 d="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,d)),!1),__read(c),!1),__read(this.lines.slice(d)),!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"),d=(null!==(t=n.newValue)&&void 0!==t?t:this.getValueWithNewlines(a)).split(/\r?\n/).map((function(e){return escapeValue(e,s)})).join("\\\n"),p="".concat(n.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),u=void 0===n.newComment?"":"".concat("".concat(p).concat(n.newComment).split(/\r?\n/).join("\n".concat(p)),"\n"),_="".concat(u).concat(l).concat(c).concat(d).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}(Properties);export{PropertiesEditor};
@@ -1,6 +1,5 @@
1
- /// <reference types="./properties-file" />
2
1
  /// <reference types="node" />
3
- export { Properties } from './properties';
2
+ export { Properties } from './properties.js';
4
3
  /**
5
4
  * A key-value pair object.
6
5
  */
@@ -15,3 +14,6 @@ export type KeyValuePairObject = {
15
14
  * @returns A key/value object representing the content of a `.properties` file.
16
15
  */
17
16
  export declare const getProperties: (content: string | Buffer) => KeyValuePairObject;
17
+
18
+ // Enables type recognition for direct `.properties` file imports.
19
+ import './properties-file.d.ts'
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{Properties}from"./properties";export{Properties}from"./properties";export var getProperties=function(r){return new Properties(r).toObject()};
1
+ import{Properties}from"./properties.js";export{Properties}from"./properties.js";export var getProperties=function(r){return new Properties(r).toObject()};
@@ -1,4 +1,3 @@
1
- /// <reference types="../properties-file" />
2
1
  /**
3
2
  * Webpack file loader for `.properties` files.
4
3
  *
@@ -8,3 +7,6 @@
8
7
  */
9
8
  declare const webpackLoader: (content: string) => string;
10
9
  export default webpackLoader;
10
+
11
+ // Enables type recognition for direct `.properties` file imports.
12
+ import '../properties-file.d.ts'
@@ -1 +1 @@
1
- import{getProperties}from"..";var webpackLoader=function(e){return"module.exports = ".concat(JSON.stringify(getProperties(e)),";")};export default webpackLoader;
1
+ import{getProperties}from"../index.js";var webpackLoader=function(e){return"exports.properties = ".concat(JSON.stringify(getProperties(e)),";")};export default webpackLoader;
@@ -1,7 +1,8 @@
1
- /** This allows to get the correct type when using `import` on `.properties` files. */
2
1
  declare module '*.properties' {
2
+ /** A key/value object representing the content of a `.properties` file. */
3
3
  const properties: {
4
- readonly [key: string]: string
4
+ /** The value of a `.properties` file key. */
5
+ [key: string]: string
5
6
  }
6
- export default properties
7
+ export { properties }
7
8
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { KeyValuePairObject } from '.';
3
- import { Property } from './property';
2
+ import { KeyValuePairObject } from './index.js';
3
+ import { Property } from './property.js';
4
4
  /**
5
5
  * Byte-order mark.
6
6
  */
@@ -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";import{PropertyLine}from"./property-line";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 t<0?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],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 t<0?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,4 +1,4 @@
1
- import { PropertyLine } from './property-line';
1
+ import { PropertyLine } from './property-line.js';
2
2
  /**
3
3
  * Object representing a property (key/value).
4
4
  */
@@ -1 +1 @@
1
- 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.")};import{unescapeContent}from"./unescape";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.hasNoValue=!1,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.hasNoValue||(this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber))):this.hasNoValue&&(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},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.hasNoValue||this.separatorPosition)){try{for(var n=__values(this.linesContent.matchAll(/[\t\f :=]/g)),o=n.next();!o.done;o=n.next()){var r=o.value.index,a=this.linesContent.slice(0,r).match(/(?<backslashes>\\+)$/);if(null==a?void 0:a.groups)if(!!(a.groups.backslashes.length%2))continue;var h="";this.separatorPosition=r;var l=this.linesContent.slice(r),p=l.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),u=(null===(i=null==p?void 0:p.groups)||void 0===i?void 0:i.whitespace)||"";if(u.length>0&&(h+=u,l=l.slice(u.length)),/[:=]/.test(l[0])){h+=l[0];var c=(l=l.slice(1)).match(/^(?<whitespace>[\t\n\v\f\r ]+)/);h+=(null===(s=null==c?void 0:c.groups)||void 0===s?void 0:s.whitespace)||""}this.separatorLength=h.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),r||(this.hasNoKey=!0);break}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}void 0===this.separatorPosition?this.hasNoValue=!0:this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();export{Property};
1
+ 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.")};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.hasNoValue=!1,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.hasNoValue||(this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber))):this.hasNoValue&&(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))},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.hasNoValue||this.separatorPosition)){try{for(var n=__values(this.linesContent.matchAll(/[\t\f :=]/g)),o=n.next();!o.done;o=n.next()){var r=o.value.index,a=this.linesContent.slice(0,r).match(/(?<backslashes>\\+)$/);if(null==a?void 0:a.groups)if(!!(a.groups.backslashes.length%2))continue;var h="";this.separatorPosition=r;var l=this.linesContent.slice(r),p=l.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),u=(null===(i=null==p?void 0:p.groups)||void 0===i?void 0:i.whitespace)||"";if(u.length>0&&(h+=u,l=l.slice(u.length)),/[:=]/.test(l[0])){h+=l[0];var c=(l=l.slice(1)).match(/^(?<whitespace>[\t\n\v\f\r ]+)/);h+=(null===(s=null==c?void 0:c.groups)||void 0===s?void 0:s.whitespace)||""}this.separatorLength=h.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),r||(this.hasNoKey=!0);break}}catch(e){t={error:e}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(t)throw t.error}}void 0===this.separatorPosition?this.hasNoValue=!0:this.newlinePositions.length>0&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}},t}();export{Property};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "properties-file",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": ".properties file parser, editor, formatter and Webpack loader.",
5
5
  "keywords": [
6
6
  ".properties",
@@ -84,22 +84,23 @@
84
84
  ],
85
85
  "scripts": {
86
86
  "add-file-type-declaration": "node ./lib/esm/add-import-type.js && find ./lib -name 'add-import-type.*' -type f -delete",
87
- "build": "check-node-version --node '>=16' && npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json && tsc -p tsconfig.build-scripts.json && node lib/build-scripts/run-all.js && npm run test",
87
+ "build": "check-node-version --node '>=16' && npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json && tsc -p tsconfig.build-scripts.json && node lib/build-scripts/build.js && npm run test",
88
88
  "ci": "npm run build",
89
- "lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .",
89
+ "depcheck": "depcheck",
90
90
  "lint-fix": "eslint --fix .",
91
- "lint-print-config": "eslint --print-config ./eslintrc.yaml",
92
91
  "prettier": "prettier --write .",
93
92
  "release": "dotenv -- release-it --only-version",
94
93
  "test": "jest --coverage"
95
94
  },
96
95
  "devDependencies": {
96
+ "@eslint/js": "^8.57.0",
97
97
  "@release-it/conventional-changelog": "8.0.1",
98
98
  "@types/jest": "29.5.12",
99
- "@types/node": "^20.11.21",
100
- "@typescript-eslint/eslint-plugin": "7.1.0",
101
- "@typescript-eslint/parser": "7.1.0",
99
+ "@types/node": "^20.11.24",
100
+ "@typescript-eslint/eslint-plugin": "7.1.1",
101
+ "@typescript-eslint/parser": "7.1.1",
102
102
  "check-node-version": "^4.2.1",
103
+ "depcheck": "^1.4.7",
103
104
  "dotenv-cli": "7.3.0",
104
105
  "eslint": "8.57.0",
105
106
  "eslint-config-prettier": "9.1.0",
@@ -113,7 +114,6 @@
113
114
  "eslint-plugin-prettier": "5.1.3",
114
115
  "eslint-plugin-tsdoc": "0.2.17",
115
116
  "eslint-plugin-unicorn": "51.0.1",
116
- "glob": "^10.3.10",
117
117
  "globals": "^14.0.0",
118
118
  "jest": "29.7.0",
119
119
  "jsonc-eslint-parser": "^2.4.0",
@@ -123,7 +123,6 @@
123
123
  "release-it": "17.1.1",
124
124
  "terser": "^5.28.1",
125
125
  "ts-jest": "29.1.2",
126
- "ts-node": "10.9.2",
127
126
  "typescript": "5.3.3"
128
127
  },
129
128
  "engines": {