properties-file 3.3.18 → 3.4.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.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +281 -281
  3. package/lib/cjs/editor/index.js +1 -0
  4. package/lib/{escape → cjs/escape}/index.d.ts +2 -2
  5. package/lib/cjs/escape/index.js +1 -0
  6. package/lib/cjs/index.js +1 -0
  7. package/lib/cjs/loader/webpack.js +1 -0
  8. package/lib/cjs/package.json +1 -0
  9. package/lib/{properties-file.d.ts → cjs/properties-file.d.ts} +7 -7
  10. package/lib/cjs/properties.js +1 -0
  11. package/lib/{property-line.d.ts → cjs/property-line.d.ts} +1 -1
  12. package/lib/cjs/property-line.js +1 -0
  13. package/lib/cjs/property.js +1 -0
  14. package/lib/cjs/unescape/index.js +1 -0
  15. package/lib/esm/editor/index.d.ts +139 -0
  16. package/lib/esm/editor/index.js +1 -0
  17. package/lib/esm/escape/index.d.ts +18 -0
  18. package/lib/esm/escape/index.js +1 -0
  19. package/lib/esm/index.d.ts +17 -0
  20. package/lib/esm/index.js +1 -0
  21. package/lib/esm/loader/webpack.d.ts +10 -0
  22. package/lib/esm/loader/webpack.js +1 -0
  23. package/lib/esm/properties-file.d.ts +7 -0
  24. package/lib/esm/properties.d.ts +95 -0
  25. package/lib/esm/properties.js +1 -0
  26. package/lib/esm/property-line.d.ts +22 -0
  27. package/lib/esm/property-line.js +1 -0
  28. package/lib/esm/property.d.ts +83 -0
  29. package/lib/esm/property.js +1 -0
  30. package/lib/esm/unescape/index.d.ts +11 -0
  31. package/lib/esm/unescape/index.js +1 -0
  32. package/package.json +132 -100
  33. package/lib/editor/index.js +0 -74
  34. package/lib/escape/index.js +0 -23
  35. package/lib/index.js +0 -9
  36. package/lib/loader/webpack.js +0 -7
  37. package/lib/properties.js +0 -52
  38. package/lib/property-line.js +0 -9
  39. package/lib/property.js +0 -39
  40. package/lib/unescape/index.js +0 -17
  41. /package/lib/{editor → cjs/editor}/index.d.ts +0 -0
  42. /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
  43. /package/lib/{loader → cjs/loader}/webpack.d.ts +0 -0
  44. /package/lib/{properties.d.ts → cjs/properties.d.ts} +0 -0
  45. /package/lib/{property.d.ts → cjs/property.d.ts} +0 -0
  46. /package/lib/{unescape → cjs/unescape}/index.d.ts +0 -0
@@ -0,0 +1 @@
1
+ { "type": "commonjs" }
@@ -1,7 +1,7 @@
1
- /** This allows to get the correct type when using `import` on `.properties` files. */
2
- declare module '*.properties' {
3
- const properties: {
4
- readonly [key: string]: string
5
- }
6
- export default properties
7
- }
1
+ /** This allows to get the correct type when using `import` on `.properties` files. */
2
+ declare module '*.properties' {
3
+ const properties: {
4
+ readonly [key: string]: string
5
+ }
6
+ export default properties
7
+ }
@@ -0,0 +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 t<0?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;
@@ -2,7 +2,7 @@
2
2
  * Object representing a line from the content of .properties file.
3
3
  */
4
4
  export declare class PropertyLine {
5
- /** The line content, minus the trailing \ that identifies that the line is continuing. */
5
+ /** The line content, minus the trailing `\` that identifies that the line is continuing. */
6
6
  content: string;
7
7
  /** True if the line is continuing to the next line, otherwise false. */
8
8
  isContinuing: boolean;
@@ -0,0 +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 s=this.content.match(/(?<backslashes>\\+)$/);(null==s?void 0:s.groups)&&(this.isContinuing=!!(s.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}};exports.PropertyLine=PropertyLine;
@@ -0,0 +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.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(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.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}();exports.Property=Property;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unescapeContent=void 0;var unescapeContent=function(e){return e.replace(/\\[^u]|\\u.{4}/g,(function(e){var r=e.charAt(1);switch(r){case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case"u":var t=e.slice(2,6);if(!/[\da-f]{4}/i.test(t))throw new Error("malformed escaped unicode characters '\\u".concat(t,"'"));return String.fromCodePoint(Number.parseInt(t,16));default:return r}}))};exports.unescapeContent=unescapeContent;
@@ -0,0 +1,139 @@
1
+ import { Properties } from '../properties';
2
+ /** The default separator between keys and values. */
3
+ export declare const DEFAULT_SEPARATOR = "=";
4
+ /** The default character used as comment delimiter. */
5
+ export declare const DEFAULT_COMMENT_DELIMITER = "#";
6
+ /** Characters that can be used as key-value pair separators. */
7
+ export type KeyValuePairSeparator = ' ' | ':' | '=';
8
+ /** Characters that can be used as comment delimiters. */
9
+ export type CommentDelimiter = '#' | '!';
10
+ /** Options on the `Properties.insert` method. */
11
+ export type InsertOptions = {
12
+ /** The name of the key to insert before or after. If the key not found, the new property will not be inserted. */
13
+ referenceKey?: string;
14
+ /** The position of the insertion related to the `referenceKey` (default is `after`) */
15
+ position?: 'before' | 'after';
16
+ /** Escape unicode characters into ISO-8859-1 compatible encoding? */
17
+ escapeUnicode?: boolean;
18
+ /** The key/value separator character. */
19
+ separator?: KeyValuePairSeparator;
20
+ /** A comment to insert before. */
21
+ comment?: string;
22
+ /** The comment's delimiter. */
23
+ commentDelimiter?: CommentDelimiter;
24
+ };
25
+ /** Options on the `Properties.insertComment` method. */
26
+ export type InsertCommentOptions = {
27
+ /** The name of the key to insert before or after. If the key not found, the new property will not be inserted. */
28
+ referenceKey?: string;
29
+ /** The position of the insertion related to the `referenceKey` (default is `after`) */
30
+ position?: 'before' | 'after';
31
+ /** The comment's delimiter. */
32
+ commentDelimiter?: CommentDelimiter;
33
+ };
34
+ /** Options on the `Properties.update` method. */
35
+ export type UpdateOptions = {
36
+ /** Optionally replace the existing value with a new value. */
37
+ newValue?: string;
38
+ /** Optionally replace the existing key with a new key name. */
39
+ newKey?: string;
40
+ /** Escape unicode characters into ISO-8859-1 compatible encoding? */
41
+ escapeUnicode?: boolean;
42
+ /** A key/value separator character. */
43
+ separator?: ' ' | ':' | '=';
44
+ /** Optionally insert a new comment, or replace the existing one (including white-space characters). */
45
+ newComment?: string;
46
+ /** The comment's delimiter. */
47
+ commentDelimiter?: CommentDelimiter;
48
+ };
49
+ /** Options on the `Properties.upsert` method. */
50
+ export type UpsertOptions = {
51
+ /** Escape unicode characters into ISO-8859-1 compatible encoding? */
52
+ escapeUnicode?: boolean;
53
+ /** The key/value separator character. */
54
+ separator?: KeyValuePairSeparator;
55
+ /** A comment to insert before. */
56
+ comment?: string;
57
+ /** The comment's delimiter. */
58
+ commentDelimiter?: CommentDelimiter;
59
+ };
60
+ /**
61
+ * A .properties file editor.
62
+ */
63
+ export declare class PropertiesEditor extends Properties {
64
+ /** Is line parsing required to re-async the object's properties? */
65
+ private needsLineParsing;
66
+ /**
67
+ * Create `PropertiesEditor` object.
68
+ *
69
+ * @param content - The content of a `.properties` file.
70
+ */
71
+ constructor(content: string);
72
+ /**
73
+ * Parse the `.properties` content line by line only when needed.
74
+ */
75
+ private parseLinesIfNeeded;
76
+ /**
77
+ * Insert a new property in the existing object (by default it will be at the end).
78
+ *
79
+ * @param key - A property key (unescaped).
80
+ * @param value - A property value (unescaped).
81
+ * @param options - Additional options.
82
+ *
83
+ * @returns True if the key was inserted, otherwise false.
84
+ */
85
+ insert(key: string, value: string, options?: InsertOptions): boolean;
86
+ /**
87
+ * Insert a new comment in the existing object (by default it will be at the end).
88
+ *
89
+ * @param comment - The comment to add.
90
+ * @param options - Additional options.
91
+ *
92
+ * @returns True if the comment was inserted, otherwise false.
93
+ */
94
+ insertComment(comment: string, options?: InsertCommentOptions): boolean;
95
+ /**
96
+ * Delete the last occurrence of a given key from the existing object.
97
+ *
98
+ * @param key - The name of the key to delete.
99
+ * @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
100
+ *
101
+ * @returns True if the key was deleted, otherwise false.
102
+ */
103
+ delete(key: string, deleteCommentsAndWhiteSpace?: boolean): boolean;
104
+ /**
105
+ * Restore the original newline characters of a key.
106
+ *
107
+ * @param property - A property object.
108
+ *
109
+ * @returns The key with its original newlines characters restored.
110
+ */
111
+ private getKeyWithNewlines;
112
+ /**
113
+ * Restore the original newline characters of a value.
114
+ *
115
+ * @param property - A property object.
116
+ *
117
+ * @returns The value with its original newlines characters restored.
118
+ */
119
+ private getValueWithNewlines;
120
+ /**
121
+ * Update the last occurrence of a given key from the existing object.
122
+ *
123
+ * @param key - The name of the key to update.
124
+ * @param options - Additional options.
125
+ *
126
+ * @returns True if the key was updated, otherwise false.
127
+ */
128
+ update(key: string, options?: UpdateOptions): boolean;
129
+ /**
130
+ * Update a key if it exist, otherwise add it at the end.
131
+ *
132
+ * @param key - A property key (unescaped).
133
+ * @param value - A property value (unescaped).
134
+ * @param options - Additional options.
135
+ *
136
+ * @returns True if the key was updated or inserted, otherwise false.
137
+ */
138
+ upsert(key: string, value: string, options?: UpsertOptions): boolean;
139
+ }
@@ -0,0 +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};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Escape a property key.
3
+ *
4
+ * @param unescapedKey - A property key to be escaped.
5
+ * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
6
+ *
7
+ * @returns The escaped key.
8
+ */
9
+ export declare const escapeKey: (unescapedKey: string, escapeUnicode?: boolean) => string;
10
+ /**
11
+ * Escape property value.
12
+ *
13
+ * @param unescapedValue - Property value to be escaped.
14
+ * @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
15
+ *
16
+ * @returns The escaped value.
17
+ */
18
+ export declare const escapeValue: (unescapedValue: string, escapeUnicode?: boolean) => string;
@@ -0,0 +1 @@
1
+ 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 escapeContent=function(e,t,n){return e.replace(new RegExp("[\\s!#:=\\\\".concat(n?"\\u0000-\\u001F\\u007F-\\uFFFF":"","]"),"g"),(function(e,n){switch(e){case" ":return t||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".concat(e.codePointAt(0).toString(16).padStart(4,"0"))}}))};
@@ -0,0 +1,17 @@
1
+ /// <reference types="./properties-file" />
2
+ /// <reference types="node" />
3
+ export { Properties } from './properties';
4
+ /**
5
+ * A key-value pair object.
6
+ */
7
+ export type KeyValuePairObject = {
8
+ [key: string]: string;
9
+ };
10
+ /**
11
+ * Converts the content of a `.properties` file to a key-value pair object.
12
+ *
13
+ * @param content - The content of a `.properties` file.
14
+ *
15
+ * @returns A key/value object representing the content of a `.properties` file.
16
+ */
17
+ export declare const getProperties: (content: string | Buffer) => KeyValuePairObject;
@@ -0,0 +1 @@
1
+ import{Properties}from"./properties";export{Properties}from"./properties";export var getProperties=function(r){return new Properties(r).toObject()};
@@ -0,0 +1,10 @@
1
+ /// <reference types="../properties-file" />
2
+ /**
3
+ * Webpack file loader for `.properties` files.
4
+ *
5
+ * @param content - the content of a `.properties` file.
6
+ *
7
+ * @returns A Webpack file loader string containing the content of a `.properties` file.
8
+ */
9
+ declare const webpackLoader: (content: string) => string;
10
+ export default webpackLoader;
@@ -0,0 +1 @@
1
+ import{getProperties}from"..";var webpackLoader=function(e){return"module.exports = ".concat(JSON.stringify(getProperties(e)),";")};export default webpackLoader;
@@ -0,0 +1,7 @@
1
+ /** This allows to get the correct type when using `import` on `.properties` files. */
2
+ declare module '*.properties' {
3
+ const properties: {
4
+ readonly [key: string]: string
5
+ }
6
+ export default properties
7
+ }
@@ -0,0 +1,95 @@
1
+ /// <reference types="node" />
2
+ import { KeyValuePairObject } from '.';
3
+ import { Property } from './property';
4
+ /**
5
+ * Byte-order mark.
6
+ */
7
+ export declare const BOM = "\uFEFF";
8
+ export declare const BOM_CODE_POINT: number | undefined;
9
+ /** The default end of line character. */
10
+ export declare const DEFAULT_END_OF_LINE_CHARACTER = "\n";
11
+ /**
12
+ * Get the first end of line (EOL) character from multiline content.
13
+ *
14
+ * @param content - The content of a `.properties` file.
15
+ *
16
+ * @returns The multiline content's first end of line (EOL) character.
17
+ */
18
+ export declare const getFirstEolCharacter: (content: string) => string | undefined;
19
+ /**
20
+ * A class representing the content of a .properties file.
21
+ */
22
+ export declare class Properties {
23
+ /** Does the .properties content starts with a BOM character? */
24
+ readonly hasBom: boolean;
25
+ /** The end of line character. */
26
+ readonly eolCharacter: string;
27
+ /** `.properties` content split by line. */
28
+ protected lines: string[];
29
+ /** The collection of property object. */
30
+ collection: Property[];
31
+ /** Object associating keys with their starting line numbers. */
32
+ keyLineNumbers: KeyLineNumbers;
33
+ /**
34
+ * Create `Properties` object.
35
+ *
36
+ * @param content - The content of a `.properties` file.
37
+ */
38
+ constructor(content: string | Buffer);
39
+ /**
40
+ * Parse the `.properties` content line by line.
41
+ */
42
+ protected parseLines(): void;
43
+ /**
44
+ * Add a property object into a properties object collection.
45
+ *
46
+ * @param property - A property object, or undefined.
47
+ *
48
+ * @returns Undefined so that we conveniently overwrite the property object.
49
+ */
50
+ private addToCollection;
51
+ /**
52
+ * Get keys that have collisions (more than one occurrence).
53
+ */
54
+ getKeyCollisions(): KeyCollisions[];
55
+ /**
56
+ * Get the key/value object representing the properties.
57
+ *
58
+ * @returns A key/value object representing the properties.
59
+ */
60
+ toObject(): KeyValuePairObject;
61
+ /**
62
+ * Format the object in `.properties`.
63
+ *
64
+ * @param endOfLineCharacter - The character used for end of lines.
65
+ *
66
+ * @returns The object in `.properties` format.
67
+ */
68
+ format(endOfLineCharacter?: '\n' | '\r\n'): string;
69
+ }
70
+ /**
71
+ * Object associating keys with their line numbers.
72
+ */
73
+ export type KeyLineNumbers = {
74
+ [key: string]: number[];
75
+ };
76
+ /**
77
+ * A class representing key within a .properties file that had collisions (more than one occurrence).
78
+ */
79
+ export declare class KeyCollisions {
80
+ /** The key with collisions. */
81
+ key: string;
82
+ /** The starting line numbers where collisions are found. */
83
+ startingLineNumbers: number[];
84
+ /**
85
+ * Create a new key collision object.
86
+ *
87
+ * @param key - The key with collisions.
88
+ * @param startingLineNumbers - The starting line numbers where collisions are found.
89
+ */
90
+ constructor(key: string, startingLineNumbers: number[]);
91
+ /**
92
+ * Get the number of the line from which the value will be used.
93
+ */
94
+ getApplicableLineNumber(): number | undefined;
95
+ }
@@ -0,0 +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};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Object representing a line from the content of .properties file.
3
+ */
4
+ export declare class PropertyLine {
5
+ /** The line content, minus the trailing `\` that identifies that the line is continuing. */
6
+ content: string;
7
+ /** True if the line is continuing to the next line, otherwise false. */
8
+ isContinuing: boolean;
9
+ /** True if the line is blank, otherwise false. */
10
+ isBlank: boolean;
11
+ /** True if the line is a comment, otherwise false. */
12
+ isComment: boolean;
13
+ /** Is the line object a continuation from a previous line? */
14
+ isMultiline: boolean;
15
+ /**
16
+ * Create a new line object.
17
+ *
18
+ * @param line - The raw content of a line.
19
+ * @param isMultiline - Is the line spreading on multiple lines?
20
+ */
21
+ constructor(line: string, isMultiline: boolean);
22
+ }
@@ -0,0 +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 s=this.content.match(/(?<backslashes>\\+)$/);(null==s?void 0:s.groups)&&(this.isContinuing=!!(s.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}};export{PropertyLine};
@@ -0,0 +1,83 @@
1
+ import { PropertyLine } from './property-line';
2
+ /**
3
+ * Object representing a property (key/value).
4
+ */
5
+ export declare class Property {
6
+ /** The content of one or multiple lines when applicable. */
7
+ linesContent: string;
8
+ /** The property key (unescaped). */
9
+ key: string;
10
+ /** The property key, including its escaped characters. */
11
+ escapedKey: string;
12
+ /** Is the key empty? */
13
+ private hasNoKey;
14
+ /** Does the key definition spread across multiple lines? */
15
+ private hasMultilineKey;
16
+ /** Starting line numbers of property objects with the same key. */
17
+ keyCollisionLines: number[];
18
+ /** Was the property's key used more than once? */
19
+ hasKeyCollisions: boolean;
20
+ /** The key/value pair separator */
21
+ separator: string | undefined;
22
+ /** The length of the key/value pair separator, including its whitespace characters. */
23
+ separatorLength: number | undefined;
24
+ /** The starting position of the key/value pair separator. */
25
+ separatorPosition: number | undefined;
26
+ /** The property value (unescaped). */
27
+ value: string;
28
+ /** The starting position of the value. */
29
+ valuePosition: number | undefined;
30
+ /** The property value, including its escaped characters. */
31
+ escapedValue: string;
32
+ /** Is the value empty? */
33
+ private hasNoValue;
34
+ /** Positions of the newline characters if any. */
35
+ newlinePositions: number[];
36
+ /** The line number at which the property starts. */
37
+ readonly startingLineNumber: number;
38
+ /** The line number at which the property ends. */
39
+ endingLineNumber: number;
40
+ /** The previous property object if it exists. */
41
+ readonly previousProperty?: Property;
42
+ /** The next property object if it exists. */
43
+ nextProperty?: Property;
44
+ /**
45
+ * Create a new property object.
46
+ *
47
+ * @param propertyLine - A property line object.
48
+ * @param startingLineNumber - The line number at which the property starts.
49
+ */
50
+ constructor(propertyLine: PropertyLine, startingLineNumber: number, previousProperty?: Property);
51
+ /**
52
+ * Set the next property object.
53
+ *
54
+ * @param property - The next property object
55
+ */
56
+ setNextProperty(property: Property): void;
57
+ /**
58
+ * Add the a line to a multiline property object.
59
+ *
60
+ * @param propertyLine - A property line object.
61
+ */
62
+ addLine(propertyLine: PropertyLine): void;
63
+ /**
64
+ * Set the property's key and value.
65
+ */
66
+ setKeyAndValue(): void;
67
+ /**
68
+ * Unescape the content from either key or value of a property.
69
+ *
70
+ * @param escapedContent - The content to unescape.
71
+ * @param startingLineNumber - The starting line number of the content being unescaped.
72
+ *
73
+ * @returns The unescaped content.
74
+ *
75
+ * @throws {@link Error}
76
+ * This exception is thrown if malformed escaped unicode characters are present.
77
+ */
78
+ private unescapeLine;
79
+ /**
80
+ * Find the character separating the key from the value.
81
+ */
82
+ private findSeparator;
83
+ }
@@ -0,0 +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};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Unescape the content from either key or value of a property.
3
+ *
4
+ * @param escapedContent - The content to unescape.
5
+ *
6
+ * @returns The unescaped content.
7
+ *
8
+ * @throws {@link Error}
9
+ * This exception is thrown if malformed escaped unicode characters are present.
10
+ */
11
+ export declare const unescapeContent: (escapedContent: string) => string;
@@ -0,0 +1 @@
1
+ export var unescapeContent=function(r){return r.replace(/\\[^u]|\\u.{4}/g,(function(r){var e=r.charAt(1);switch(e){case"f":return"\f";case"n":return"\n";case"r":return"\r";case"t":return"\t";case"u":var t=r.slice(2,6);if(!/[\da-f]{4}/i.test(t))throw new Error("malformed escaped unicode characters '\\u".concat(t,"'"));return String.fromCodePoint(Number.parseInt(t,16));default:return e}}))};