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