properties-file 4.0.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +94 -97
  2. package/dist/cjs/bundler/bun.js +1 -1
  3. package/dist/cjs/bundler/esbuild.js +1 -1
  4. package/dist/cjs/bundler/rollup.js +1 -1
  5. package/dist/cjs/bundler/webpack.js +1 -1
  6. package/dist/cjs/editor/index.d.ts +100 -93
  7. package/dist/cjs/editor/index.js +1 -1
  8. package/dist/cjs/escape/index.js +1 -1
  9. package/dist/cjs/index.d.ts +0 -1
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/package.json +1 -1
  12. package/dist/cjs/parse-properties.d.ts +22 -0
  13. package/dist/cjs/parse-properties.js +1 -0
  14. package/dist/cjs/parser/index.d.ts +3 -0
  15. package/dist/cjs/parser/index.js +1 -0
  16. package/dist/cjs/parser/nodes.d.ts +156 -0
  17. package/dist/cjs/parser/nodes.js +1 -0
  18. package/dist/cjs/parser/normalize.d.ts +12 -0
  19. package/dist/cjs/parser/normalize.js +1 -0
  20. package/dist/cjs/parser/parse.d.ts +23 -0
  21. package/dist/cjs/parser/parse.js +1 -0
  22. package/dist/cjs/parser/properties.d.ts +93 -0
  23. package/dist/cjs/parser/properties.js +1 -0
  24. package/dist/cjs/unescape/index.d.ts +4 -0
  25. package/dist/cjs/unescape/index.js +1 -1
  26. package/dist/esm/editor/index.d.ts +100 -93
  27. package/dist/esm/editor/index.js +1 -1
  28. package/dist/esm/escape/index.js +1 -1
  29. package/dist/esm/index.d.ts +0 -1
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/parse-properties.d.ts +22 -0
  32. package/dist/esm/parse-properties.js +1 -0
  33. package/dist/esm/parser/index.d.ts +3 -0
  34. package/dist/esm/parser/index.js +1 -0
  35. package/dist/esm/parser/nodes.d.ts +156 -0
  36. package/dist/esm/parser/nodes.js +1 -0
  37. package/dist/esm/parser/normalize.d.ts +12 -0
  38. package/dist/esm/parser/normalize.js +1 -0
  39. package/dist/esm/parser/parse.d.ts +23 -0
  40. package/dist/esm/parser/parse.js +1 -0
  41. package/dist/esm/parser/properties.d.ts +93 -0
  42. package/dist/esm/parser/properties.js +1 -0
  43. package/dist/esm/unescape/index.d.ts +4 -0
  44. package/dist/esm/unescape/index.js +1 -1
  45. package/package.json +33 -21
  46. package/dist/cjs/properties.d.ts +0 -96
  47. package/dist/cjs/properties.js +0 -1
  48. package/dist/cjs/property-line.d.ts +0 -22
  49. package/dist/cjs/property-line.js +0 -1
  50. package/dist/cjs/property.d.ts +0 -81
  51. package/dist/cjs/property.js +0 -1
  52. package/dist/esm/properties.d.ts +0 -96
  53. package/dist/esm/properties.js +0 -1
  54. package/dist/esm/property-line.d.ts +0 -22
  55. package/dist/esm/property-line.js +0 -1
  56. package/dist/esm/property.d.ts +0 -81
  57. package/dist/esm/property.js +0 -1
@@ -1,154 +1,161 @@
1
- import { KeyValuePairObject } from '../index.js';
2
- import { Properties } from '../properties.js';
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
+ /**
10
+ * Insert relative to this key (last occurrence). If the key is not found,
11
+ * the property is appended at the end.
12
+ */
14
13
  referenceKey?: string;
15
- /** The position of the insertion related to the `referenceKey` (default is `after`) */
14
+ /** Position relative to the reference key. Default: `'after'`. */
16
15
  position?: 'before' | 'after';
17
- /** Escape unicode characters into ISO-8859-1 compatible encoding? */
16
+ /** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
18
17
  escapeUnicode?: boolean;
19
- /** The key/value separator character. */
18
+ /** Separator character to use between key and value. Default: `'='`. */
20
19
  separator?: KeyValuePairSeparator;
21
- /** A comment to insert before. */
20
+ /**
21
+ * Comment text to prepend before the property. Supports multi-line: newlines
22
+ * in the string create separate comment nodes. Empty lines within the text
23
+ * become blank line nodes.
24
+ */
22
25
  comment?: string;
23
- /** The comment's delimiter. */
26
+ /** Delimiter character for the comment. Default: `'#'`. */
24
27
  commentDelimiter?: CommentDelimiter;
25
28
  };
26
- /** Options on the `Properties.insertComment` method. */
29
+ /** Options for {@link PropertiesEditor.insertComment}. */
27
30
  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. */
31
+ /**
32
+ * Insert relative to this key (last occurrence). If the key is not found,
33
+ * the comment is appended at the end.
34
+ */
29
35
  referenceKey?: string;
30
- /** The position of the insertion related to the `referenceKey` (default is `after`) */
36
+ /** Position relative to the reference key. Default: `'after'`. */
31
37
  position?: 'before' | 'after';
32
- /** The comment's delimiter. */
38
+ /** Delimiter character for the comment. Default: `'#'`. */
33
39
  commentDelimiter?: CommentDelimiter;
34
40
  };
35
- /** Options on the `Properties.update` method. */
41
+ /** Options for {@link PropertiesEditor.insertBlankLine}. */
42
+ export type InsertBlankLineOptions = {
43
+ /**
44
+ * Insert relative to this key (last occurrence). If the key is not found,
45
+ * the blank line is appended at the end.
46
+ */
47
+ referenceKey?: string;
48
+ /** Position relative to the reference key. Default: `'after'`. */
49
+ position?: 'before' | 'after';
50
+ };
51
+ /** Options for {@link PropertiesEditor.update}. */
36
52
  export type UpdateOptions = {
37
- /** Optionally replace the existing value with a new value. */
53
+ /** Replacement value. When not set, the original value is preserved. */
38
54
  newValue?: string;
39
- /** Optionally replace the existing key with a new key name. */
55
+ /** Replacement key (rename). When not set, the original key is preserved. */
40
56
  newKey?: string;
41
- /** Escape unicode characters into ISO-8859-1 compatible encoding? */
57
+ /** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
42
58
  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). */
59
+ /** New separator character. When not set, the original separator is preserved. */
60
+ separator?: KeyValuePairSeparator;
61
+ /**
62
+ * Replacement comment text. When set, all comment and blank line nodes immediately
63
+ * preceding the property (up to the previous property) are removed and replaced
64
+ * with the new comment. Supports multi-line via newlines in the string.
65
+ */
46
66
  newComment?: string;
47
- /** The comment's delimiter. */
67
+ /** Delimiter character for the new comment. Default: `'#'`. */
48
68
  commentDelimiter?: CommentDelimiter;
49
69
  };
50
- /** Options on the `Properties.upsert` method. */
70
+ /** Options for {@link PropertiesEditor.upsert}. */
51
71
  export type UpsertOptions = {
52
- /** Escape unicode characters into ISO-8859-1 compatible encoding? */
72
+ /** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
53
73
  escapeUnicode?: boolean;
54
- /** The key/value separator character. */
74
+ /** Separator character. Default: `'='`. */
55
75
  separator?: KeyValuePairSeparator;
56
- /** A comment to insert before. */
76
+ /**
77
+ * Comment text. When inserting a new property, this is prepended as a comment.
78
+ * When updating an existing property, this replaces the leading comment nodes.
79
+ */
57
80
  comment?: string;
58
- /** The comment's delimiter. */
81
+ /** Delimiter character for the comment. Default: `'#'`. */
59
82
  commentDelimiter?: CommentDelimiter;
60
83
  };
84
+ /** Options for {@link PropertiesEditor.delete}. */
85
+ export type DeleteOptions = {
86
+ /**
87
+ * If `false`, only the property node itself is removed. If `true` (default),
88
+ * all comment and blank line nodes immediately preceding the property (up to
89
+ * the previous property) are also removed.
90
+ */
91
+ deleteLeadingNodes?: boolean;
92
+ };
61
93
  /**
62
- * A .properties file editor.
94
+ * An editor for `.properties` files that extends the lossless {@link Properties}
95
+ * parser with insert, update, delete, and upsert operations.
63
96
  */
64
97
  export declare class PropertiesEditor extends Properties {
65
- /** Is line parsing required to re-async the object's properties? */
66
- private needsLineParsing;
67
- /**
68
- * Create `PropertiesEditor` object.
69
- *
70
- * @param content - The content of a `.properties` file.
71
- */
72
- constructor(content: string);
73
98
  /**
74
- * Find the last occurrence of a property by key (iterates backward for performance).
99
+ * Find the index of the last property node with the given key.
75
100
  *
76
- * @param key - The property key to search for.
101
+ * @param key - The unescaped key to search for.
77
102
  *
78
- * @returns The last matching property, or undefined if not found.
79
- */
80
- private findLastPropertyByKey;
81
- /**
82
- * Parse the `.properties` content line by line only when needed.
103
+ * @returns The index in `this.nodes`, or `-1` if not found.
83
104
  */
84
- private parseLinesIfNeeded;
105
+ private findLastPropertyIndex;
85
106
  /**
86
- * Insert a new property in the existing object (by default it will be at the end).
107
+ * Insert a new property.
87
108
  *
88
- * @param key - A property key (unescaped).
89
- * @param value - A property value (unescaped).
90
- * @param options - Additional options.
91
- *
92
- * @returns True if the key was inserted, otherwise false.
109
+ * @param key - The unescaped key.
110
+ * @param value - The unescaped value.
111
+ * @param options - Insert options.
93
112
  */
94
- insert(key: string, value: string, options?: InsertOptions): boolean;
113
+ insert(key: string, value: string, options?: InsertOptions): void;
95
114
  /**
96
- * Insert a new comment in the existing object (by default it will be at the end).
97
- *
98
- * @param comment - The comment to add.
99
- * @param options - Additional options.
115
+ * Insert a comment.
100
116
  *
101
- * @returns True if the comment was inserted, otherwise false.
117
+ * @param comment - The comment text (may contain newlines).
118
+ * @param options - Insert comment options.
102
119
  */
103
- insertComment(comment: string, options?: InsertCommentOptions): boolean;
120
+ insertComment(comment: string, options?: InsertCommentOptions): void;
104
121
  /**
105
- * Delete the last occurrence of a given key from the existing object.
122
+ * Insert a blank line.
106
123
  *
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.
109
- *
110
- * @returns True if the key was deleted, otherwise false.
124
+ * @param options - Insert blank line options.
111
125
  */
112
- delete(key: string, deleteCommentsAndWhiteSpace?: boolean): boolean;
126
+ insertBlankLine(options?: InsertBlankLineOptions): void;
113
127
  /**
114
- * Restore the original newline characters of a key.
128
+ * Update an existing property.
115
129
  *
116
- * @param property - A property object.
130
+ * @param key - The unescaped key to update (uses last occurrence).
131
+ * @param options - Update options.
117
132
  *
118
- * @returns The key with its original newlines characters restored.
133
+ * @returns `true` if the property was found and updated, `false` otherwise.
119
134
  */
120
- private getKeyWithNewlines;
135
+ update(key: string, options: UpdateOptions): boolean;
121
136
  /**
122
- * Restore the original newline characters of a value.
123
- *
124
- * @param property - A property object.
137
+ * Update a property if it exists, or insert it if it doesn't.
125
138
  *
126
- * @returns The value with its original newlines characters restored.
139
+ * @param key - The unescaped key.
140
+ * @param value - The unescaped value.
141
+ * @param options - Upsert options.
127
142
  */
128
- private getValueWithNewlines;
143
+ upsert(key: string, value: string, options?: UpsertOptions): void;
129
144
  /**
130
- * Update the last occurrence of a given key from the existing object.
145
+ * Delete the last occurrence of a property (the effective value in last-wins semantics).
131
146
  *
132
- * @param key - The name of the key to update.
133
- * @param options - Additional options.
147
+ * @param key - The unescaped key to delete.
148
+ * @param options - Delete options.
134
149
  *
135
- * @returns True if the key was updated, otherwise false.
150
+ * @returns The deleted {@link PropertyNode}, or `undefined` if the key was not found.
136
151
  */
137
- update(key: string, options?: UpdateOptions): boolean;
152
+ delete(key: string, options?: DeleteOptions): PropertyNode | undefined;
138
153
  /**
139
- * Update a key if it exist, otherwise add it at the end.
154
+ * Delete all occurrences of a key.
140
155
  *
141
- * @param key - A property key (unescaped).
142
- * @param value - A property value (unescaped).
143
- * @param options - Additional options.
144
- *
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.
156
+ * @param key - The unescaped key to delete.
150
157
  *
151
- * @returns A key/value object representing the properties.
158
+ * @returns An array of the deleted {@link PropertyNode} instances.
152
159
  */
153
- toObject(): KeyValuePairObject;
160
+ deleteAll(key: string): PropertyNode[];
154
161
  }
@@ -1 +1 @@
1
- var __extends=this&&this.__extends||function(){var e=function(n,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])},e(n,r)};return function(n,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function t(){this.constructor=n}e(n,r),n.prototype=null===r?Object.create(r):(t.prototype=r.prototype,new t)}}(),__read=this&&this.__read||function(e,n){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var t,i,o=r.call(e),a=[];try{for(;(void 0===n||n-- >0)&&!(t=o.next()).done;)a.push(t.value)}catch(e){i={error:e}}finally{try{t&&!t.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return a},__spreadArray=this&&this.__spreadArray||function(e,n,r){if(r||2===arguments.length)for(var t,i=0,o=n.length;i<o;i++)!t&&i in n||(t||(t=Array.prototype.slice.call(n,0,i)),t[i]=n[i]);return e.concat(t||Array.prototype.slice.call(n))};import{escapeKey,escapeValue}from"../escape/index.js";import{Properties,REGEX_NEWLINE}from"../properties.js";var REGEX_NEWLINE_GLOBAL=/\r?\n/g,REGEX_LF=/\n/;export var DEFAULT_SEPARATOR="=";export var DEFAULT_COMMENT_DELIMITER="#";var PropertiesEditor=function(e){function n(n){var r=e.call(this,n)||this;return r.needsLineParsing=!1,r}return __extends(n,e),n.prototype.findLastPropertyByKey=function(e){for(var n=this.collection.length-1;n>=0;n--){var r=this.collection[n];if(r.key===e)return r}},n.prototype.parseLinesIfNeeded=function(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)},n.prototype.insert=function(e,n,r){var t,i,o,a=(null==r?void 0:r.escapeUnicode)||!1,s=(null==r?void 0:r.separator)?" "===r.separator?" ":" ".concat(r.separator," "):" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),c=null==r?void 0:r.referenceKey,l=(null==r?void 0:r.position)||"after";c&&this.parseLinesIfNeeded();var p=e.split(REGEX_NEWLINE).map(function(e){return escapeKey(e,a)}).join("\\\n"),d=n.split(REGEX_NEWLINE).map(function(e){return escapeValue(e,a)}).join("\\\n"),u="".concat((null==r?void 0:r.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),_=void 0===(null==r?void 0:r.comment)?"":"".concat("".concat(u).concat(r.comment).split(REGEX_NEWLINE).join("\n".concat(u)),"\n"),y="".concat(_).concat(p).concat(s).concat(d).split(REGEX_LF);if(void 0===c)return(t=this.lines).push.apply(t,__spreadArray([],__read(y),!1)),this.needsLineParsing=!0,!0;var v=this.findLastPropertyByKey(c);if(v){var f="after"===l?v.endingLineNumber:null!==(o=null===(i=v.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,f)),!1),__read(y),!1),__read(this.lines.slice(f)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.insertComment=function(e,n){var r,t,i,o=null==n?void 0:n.referenceKey,a=(null==n?void 0:n.position)||"after";o&&this.parseLinesIfNeeded();var s="".concat((null==n?void 0:n.commentDelimiter)||DEFAULT_COMMENT_DELIMITER," "),c="".concat(s).concat(e).replace(REGEX_NEWLINE_GLOBAL,"\n".concat(s)).split(REGEX_LF);if(void 0===o)return(r=this.lines).push.apply(r,__spreadArray([],__read(c),!1)),this.needsLineParsing=!0,!0;var l=this.findLastPropertyByKey(o);if(l){var p="after"===a?l.endingLineNumber:null!==(i=null===(t=l.previousProperty)||void 0===t?void 0:t.endingLineNumber)&&void 0!==i?i:0;return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,p)),!1),__read(c),!1),__read(this.lines.slice(p)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.delete=function(e,n){var r,t;void 0===n&&(n=!0),this.parseLinesIfNeeded();var i=this.findLastPropertyByKey(e);if(i){var o=n?null!==(t=null===(r=i.previousProperty)||void 0===r?void 0:r.endingLineNumber)&&void 0!==t?t:0:i.startingLineNumber-1,a=i.endingLineNumber;return this.lines=__spreadArray(__spreadArray([],__read(this.lines.slice(0,o)),!1),__read(this.lines.slice(a)),!1),this.needsLineParsing=!0,!0}return!1},n.prototype.getKeyWithNewlines=function(e){return 0===e.newlinePositions.length?e.key:__spreadArray([],__read(e.key),!1).reduce(function(n,r,t){return"".concat(n).concat(-1!==e.newlinePositions.indexOf(t)?"\n":"").concat(r)},"")},n.prototype.getValueWithNewlines=function(e){return 0===e.newlinePositions.length||void 0===e.valuePosition?e.value:__spreadArray([],__read(e.value),!1).reduce(function(n,r,t){return"".concat(n).concat(-1!==e.newlinePositions.indexOf(t+e.valuePosition)?"\n":"").concat(r)},"")},n.prototype.update=function(e,n){var r,t,i,o;this.parseLinesIfNeeded();var a=this.findLastPropertyByKey(e);if(!a||!n)return!1;var s=n.escapeUnicode||!1,c=n.separator?" "===n.separator?" ":" ".concat(n.separator," "):a.separator||" ".concat(DEFAULT_SEPARATOR," ").replace(" "," "),l=(null!==(r=n.newKey)&&void 0!==r?r:this.getKeyWithNewlines(a)).split(REGEX_NEWLINE).map(function(e){return escapeKey(e,s)}).join("\\\n"),p=(null!==(t=n.newValue)&&void 0!==t?t:this.getValueWithNewlines(a)).split(REGEX_NEWLINE).map(function(e){return escapeValue(e,s)}).join("\\\n"),d="".concat(n.commentDelimiter||DEFAULT_COMMENT_DELIMITER," "),u=void 0===n.newComment?"":"".concat("".concat(d).concat(n.newComment).split(REGEX_NEWLINE).join("\n".concat(d)),"\n"),_="".concat(u).concat(l).concat(c).concat(p).split(REGEX_LF);return this.lines=__spreadArray(__spreadArray(__spreadArray([],__read(this.lines.slice(0,void 0===n.newComment?a.startingLineNumber-1:null!==(o=null===(i=a.previousProperty)||void 0===i?void 0:i.endingLineNumber)&&void 0!==o?o:0)),!1),__read(_),!1),__read(this.lines.slice(a.endingLineNumber)),!1),this.needsLineParsing=!0,!0},n.prototype.upsert=function(e,n,r){return this.parseLinesIfNeeded(),this.keyLineNumbers[e]?this.update(e,{newValue:n,newComment:null==r?void 0:r.comment,commentDelimiter:null==r?void 0:r.commentDelimiter,separator:null==r?void 0:r.separator,escapeUnicode:null==r?void 0:r.escapeUnicode}):this.insert(e,n,r)},n.prototype.toObject=function(){return this.parseLinesIfNeeded(),e.prototype.toObject.call(this)},n}(Properties);export{PropertiesEditor};
1
+ 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(!(e instanceof 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})()}import{escapeKey,escapeValue}from"../escape/index.js";import{Properties}from"../parser/properties.js";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=escapeKey(e,a),s=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}}};export var PropertiesEditor=function(e){"use strict";function t(){return _class_call_check(this,t),_call_super(this,t,arguments)}return _inherits(t,e),_create_class(t,[{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?escapeKey(s,!0):void 0!==t.newKey?escapeKey(s):i.escapedKey,p=c?escapeValue(l,!0):void 0!==t.newValue?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),v={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 h,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,N=buildCommentNodes(t.newComment,E,0);(h=this.nodes).splice.apply(h,[b,a-b+1].concat(_to_consumable_array(N),[v]))}else this.nodes[a]=v;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()}}]),t}(Properties);
@@ -1 +1 @@
1
- export var escapeKey=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!0,r)};export var escapeValue=function(e,r){return void 0===r&&(r=!1),escapeContent(e,!1,r)};var escapeContent=function(e,r,n){return e.replace(new RegExp("[\\s!#:=\\\\".concat(n?"\0--￿":"","]"),"g"),function(e,n){var t;switch(e){case" ":return r||0===n?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+(null!==(t=e.charCodeAt(0))&&void 0!==t?t:0).toString(16)).slice(-4)}})};
1
+ export var escapeKey=function(e){return escapeContent(e,!0,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};export var escapeValue=function(e){return escapeContent(e,!1,arguments.length>1&&void 0!==arguments[1]&&arguments[1])};var REGEX_ESCAPE_NO_UNICODE=/[\s!#:=\\]/g,REGEX_ESCAPE_UNICODE=/[\s!#:=\\\u0000-\u001F\u007F-\uFFFF]/g,escapeContent=function(e,r,t){var n=t?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,t){var n;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!==(n=e.charCodeAt(0))&&void 0!==n?n:0).toString(16)).slice(-4)}})};
@@ -1,4 +1,3 @@
1
- export { Properties } from './properties.js';
2
1
  /**
3
2
  * A key-value pair object.
4
3
  */
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{Properties}from"./properties.js";export{Properties}from"./properties.js";export var getProperties=function(r){return new Properties(r).toObject()};
1
+ import{parseProperties}from"./parse-properties.js";export var getProperties=function(r){return parseProperties(r)};
@@ -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
+ 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 A=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(A),c+=5;break;default:H+=e.charAt(c),c++}_=c}else c++;return _<r&&(H+=e.slice(_,r)),H};export var 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,A=0,o=!1;t<r&&(_=C.charCodeAt(t))!==CH_LF&&_!==CH_CR;)_===CH_BACKSLASH?(A++,o=!0):A=0,t++;if(A%2==1){var s=[C.slice(i,t-1)],h=o;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;A=0;for(var L=!1;t<r&&(_=C.charCodeAt(t))!==CH_LF&&_!==CH_CR;)_===CH_BACKSLASH?(A++,L=!0):A=0,t++;var d=A%2==1,f=d?t-1:t;if(s.push(C.slice(n,f)),L&&(h=!0),t<r&&(C.charCodeAt(t)===CH_CR?++t<r&&C.charCodeAt(t)===CH_LF&&t++:t++,H++),!d)break;t=skipWhitespace(C,t,r)}for(var p=s.join(""),S=p.length,u=0,F=!1;u<S;)if((_=p.charCodeAt(u))!==CH_BACKSLASH){if(!F&&(_===CH_EQUALS||_===CH_COLON||_===CH_SPACE||_===CH_TAB||_===CH_FF))break;F=!1,u++}else F=!F,u++;var l=u;l<S&&((_=p.charCodeAt(l))!==CH_SPACE&&_!==CH_TAB&&_!==CH_FF||(l=skipWhitespace(p,l,S))<S&&(_=p.charCodeAt(l)),l<S&&(_===CH_EQUALS||_===CH_COLON)&&(l++,l=skipWhitespace(p,l,S))),a[unescapeContent(p,0,u,h,c)]=unescapeContent(p,l,S,h,c)}else{var E=t;t<r&&(C.charCodeAt(t)===CH_CR?++t<r&&C.charCodeAt(t)===CH_LF&&t++:t++,H++);for(var O=i,R=!1;O<E;)if((_=C.charCodeAt(O))!==CH_BACKSLASH){if(!R&&(_===CH_EQUALS||_===CH_COLON||_===CH_SPACE||_===CH_TAB||_===CH_FF))break;R=!1,O++}else R=!R,O++;var k=O;k<E&&((_=C.charCodeAt(k))!==CH_SPACE&&_!==CH_TAB&&_!==CH_FF||(k=skipWhitespace(C,k,E))<E&&(_=C.charCodeAt(k)),k<E&&(_===CH_EQUALS||_===CH_COLON)&&(k++,k=skipWhitespace(C,k,E))),a[unescapeContent(C,i,O,o,c)]=unescapeContent(C,k,E,o,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
+ export{Properties}from"./properties.js";export{PropertiesNodeType}from"./nodes.js";
@@ -0,0 +1,156 @@
1
+ /** Constants for the `type` discriminator on each node. */
2
+ export declare const PropertiesNodeType: {
3
+ /** A property (key-value pair). */
4
+ readonly PROPERTY: "property";
5
+ /** A comment line (`#` or `!`). */
6
+ readonly COMMENT: "comment";
7
+ /** A blank line. */
8
+ readonly BLANK: "blank";
9
+ };
10
+ /**
11
+ * A property (key-value pair), potentially spanning multiple physical lines
12
+ * via backslash continuation.
13
+ */
14
+ export type PropertyNode = {
15
+ /** Discriminator. */
16
+ readonly type: 'property';
17
+ /** Physical lines as-is (without EOL characters), for lossless reconstruction. */
18
+ readonly rawLines: string[];
19
+ /** Leading whitespace before the key on the first physical line. */
20
+ readonly leadingWhitespace: string;
21
+ /** The unescaped key. */
22
+ readonly key: string;
23
+ /** The key as written in the source (after continuation joining, before unescaping). */
24
+ readonly escapedKey: string;
25
+ /** Whitespace between the key and the separator character. */
26
+ readonly separatorLeading: string;
27
+ /**
28
+ * The core separator character.
29
+ *
30
+ * - `'='` or `':'` when an explicit delimiter is used.
31
+ * - `undefined` when whitespace alone separates key from value, or when
32
+ * the property is key-only with no separator.
33
+ */
34
+ readonly separatorChar: '=' | ':' | undefined;
35
+ /** Whitespace between the separator character and the value. */
36
+ readonly separatorTrailing: string;
37
+ /** The unescaped value. */
38
+ readonly value: string;
39
+ /** The value as written in the source (after continuation joining, before unescaping). */
40
+ readonly escapedValue: string;
41
+ /** 1-based line number where this property starts. */
42
+ readonly startingLineNumber: number;
43
+ /** 1-based line number where this property ends. */
44
+ readonly endingLineNumber: number;
45
+ };
46
+ /**
47
+ * A comment line starting with `#` or `!`.
48
+ */
49
+ export type CommentNode = {
50
+ /** Discriminator. */
51
+ readonly type: 'comment';
52
+ /** The full line as-is (without the EOL character). */
53
+ readonly rawLine: string;
54
+ /** Leading whitespace before the delimiter. */
55
+ readonly leadingWhitespace: string;
56
+ /** The comment delimiter character. */
57
+ readonly delimiter: '#' | '!';
58
+ /** The text after the delimiter (including any space immediately after it). */
59
+ readonly body: string;
60
+ /** 1-based line number. */
61
+ readonly lineNumber: number;
62
+ };
63
+ /**
64
+ * A blank line (may contain only whitespace characters).
65
+ */
66
+ export type BlankLineNode = {
67
+ /** Discriminator. */
68
+ readonly type: 'blank';
69
+ /** The raw whitespace content of the line (without the EOL character). */
70
+ readonly rawLine: string;
71
+ /** 1-based line number. */
72
+ readonly lineNumber: number;
73
+ };
74
+ /** Discriminated union of all node types in a `.properties` file. */
75
+ export type PropertiesNode = PropertyNode | CommentNode | BlankLineNode;
76
+ /** A plain key-value pair object where every value is a string. */
77
+ export type KeyValuePairObject = {
78
+ [key: string]: string;
79
+ };
80
+ /** Information about a key that appears more than once. */
81
+ export type KeyCollisions = {
82
+ /** The duplicate key. */
83
+ key: string;
84
+ /** All property nodes with this key, in file order. */
85
+ nodes: PropertyNode[];
86
+ };
87
+ /**
88
+ * Options for {@link Properties.format} when producing normalized output.
89
+ *
90
+ * When no options are passed to `format()`, the output is a lossless reconstruction
91
+ * of the original content. Passing any option triggers normalization, rebuilding
92
+ * property lines from their parsed fields.
93
+ */
94
+ export type NormalizeOptions = {
95
+ /** Override the end-of-line character. Defaults to the EOL detected from the source. */
96
+ endOfLineCharacter?: '\n' | '\r\n';
97
+ /** If `true`, remove all comment lines from the output. Default: `false`. */
98
+ removeComments?: boolean;
99
+ /** If `true`, remove all blank lines from the output. Default: `false`. */
100
+ removeBlankLines?: boolean;
101
+ /** If `true`, strip leading whitespace from all property and comment lines. Default: `false`. */
102
+ removeLeadingWhitespace?: boolean;
103
+ /**
104
+ * If `true`, keep only the last occurrence of each duplicate key (Java's last-wins
105
+ * semantics). Earlier occurrences and their leading comment/blank line nodes are
106
+ * removed from the output. Set `deduplicateKeysKeepLeadingNodes` to `true` to
107
+ * preserve the leading nodes. Default: `false`.
108
+ */
109
+ deduplicateKeys?: boolean;
110
+ /**
111
+ * When `deduplicateKeys` is `true`, controls whether comment and blank line nodes
112
+ * preceding removed duplicates are preserved (`true`) or also removed (`false`).
113
+ * Default: `false` (leading nodes are removed along with the duplicate).
114
+ */
115
+ deduplicateKeysKeepLeadingNodes?: boolean;
116
+ /**
117
+ * Standardize the separator character across all properties. When set, every
118
+ * property is rewritten to use this separator. Original separators are preserved
119
+ * if not set. Use `' '` for whitespace-only separators (no `=` or `:`).
120
+ */
121
+ separatorChar?: '=' | ':' | ' ';
122
+ /**
123
+ * Whitespace to place before the separator character (e.g. `' '` for `key = value`,
124
+ * `''` for `key=value`). When not set, each property's original leading whitespace
125
+ * is preserved.
126
+ */
127
+ separatorLeading?: string;
128
+ /**
129
+ * Whitespace to place after the separator character (e.g. `' '` for `key = value`,
130
+ * `''` for `key=value`). When not set, each property's original trailing whitespace
131
+ * is preserved.
132
+ */
133
+ separatorTrailing?: string;
134
+ /**
135
+ * If `true`, re-escape all non-ASCII characters as `\\uXXXX` sequences. Useful for
136
+ * producing ISO-8859-1 compatible output. Default: `false` (preserves original encoding).
137
+ */
138
+ escapeUnicode?: boolean;
139
+ /**
140
+ * If `true`, collapse multiline keys and values (joined via `\\` line continuations)
141
+ * into single lines. Default: `false` (preserves original line structure).
142
+ */
143
+ collapseMultiline?: boolean;
144
+ /**
145
+ * Wrap keys at this character width using `\\` line continuations. Only applies to
146
+ * keys longer than the specified width. `\\uXXXX` sequences are never split across
147
+ * lines. `undefined` = no wrapping.
148
+ */
149
+ wrapKeysAt?: number;
150
+ /**
151
+ * Wrap values at this character width using `\\` line continuations. Only applies to
152
+ * values longer than the specified width. `\\uXXXX` sequences are never split across
153
+ * lines. `undefined` = no wrapping.
154
+ */
155
+ wrapValuesAt?: number;
156
+ };
@@ -0,0 +1 @@
1
+ export 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
+ import{escapeKey,escapeValue}from"../escape/index.js";var 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?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?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)};export var formatNormalized=function(e,a,r,i){var t,o,n=null!==(t=i.endOfLineCharacter)&&void 0!==t?t:r,p=void 0!==i.separatorChar||void 0!==i.separatorLeading||void 0!==i.separatorTrailing||!0===i.escapeUnicode||!0===i.collapseMultiline||void 0!==i.wrapKeysAt||void 0!==i.wrapValuesAt||!0===i.removeLeadingWhitespace;if(i.deduplicateKeys){for(var s={},d=[],c=e.length-1;c>=0;c--){var l=e[c];"property"===l.type&&(s[l.key]?d.push(c):s[l.key]=!0)}o={};var v=!0,u=!1,h=void 0;try{for(var f,y=d[Symbol.iterator]();!(v=(f=y.next()).done);v=!0){var g=f.value;if(o[g]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var L=g-1;L>=0&&"property"!==e[L].type;L--)o[L]=!0}}catch(e){u=!0,h=e}finally{try{v||null==y.return||y.return()}finally{if(u)throw h}}}for(var m=[],w=0;w<e.length;w++)if(!o||!o[w]){var A=e[w];switch(A.type){case"comment":if(i.removeComments)continue;m.push(i.removeLeadingWhitespace?"".concat(A.delimiter).concat(A.body):A.rawLine);break;case"blank":if(i.removeBlankLines)continue;m.push(A.rawLine);break;case"property":p?m.push(rebuildPropertyLine(A,i)):m.push(A.rawLines.join(n))}}return(a?BOM:"")+m.join(n)};
@@ -0,0 +1,23 @@
1
+ import type { PropertiesNode } from './nodes.js';
2
+ /** Result of parsing a `.properties` file. */
3
+ export type ParseResult = {
4
+ /** Whether the content starts with a BOM character. */
5
+ hasBom: boolean;
6
+ /** The detected end-of-line character sequence. */
7
+ eolCharacter: string;
8
+ /** All parsed nodes in file order. */
9
+ nodes: PropertiesNode[];
10
+ };
11
+ /**
12
+ * Parse a `.properties` file into a lossless sequence of nodes.
13
+ *
14
+ * Every element in the file — properties, comments, and blank lines — is
15
+ * preserved in order. Duplicate keys are all retained. The original content
16
+ * can be reconstructed exactly by joining node raw lines with the EOL
17
+ * character.
18
+ *
19
+ * @param content - The content of a `.properties` file.
20
+ *
21
+ * @returns The parse result with BOM info, detected EOL, and ordered nodes.
22
+ */
23
+ export declare const parseDocument: (content: string | Buffer) => ParseResult;
@@ -0,0 +1 @@
1
+ import{unescapeContent}from"../unescape/index.js";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_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};export var parseDocument=function(e){var r="string"==typeof e?e:e.toString(),a=r.length,i=0,s=a>0&&r.charCodeAt(0)===CH_BOM;s&&(i=1);for(var n="\n",t=i;t<a;t++){var C=r.charCodeAt(t);if(C===CH_CR){n=t+1<a&&r.charCodeAt(t+1)===CH_LF?"\r\n":"\r";break}if(C===CH_LF){n="\n";break}}for(var c=(i>0?r.slice(i):r).split(/\r\n|\r|\n/),o=[],l=0,h=c.length;l<h;){for(var H=c[l],p=l+1,v=0,A=H.length;v<A&&isWhitespace(H.charCodeAt(v));)v++;if(v>=A){var f={type:"blank",rawLine:H,lineNumber:p};o.push(f),l++}else{var _=H.charCodeAt(v);if(_!==CH_HASH&&_!==CH_BANG){for(var d=[H],u=p,g=v>0?H.slice(0,v):"",L=countTrailingBackslashes(H,A),S=L%2==1;S&&l+1<h;){var B=c[++l];d.push(B);var m=B.length;S=(L=countTrailingBackslashes(B,m))%2==1}var O=l+1,b=S,N=void 0;if(1===d.length){var k=v>0?H.slice(v):H;N=b?k.slice(0,-1):k}else{for(var y=[],W=0;W<d.length;W++){var F=d[W],E=void 0,T=void 0;if(0===W)E=v,T=F.length-1;else{E=0;for(var x=F.length;E<x&&isWhitespace(F.charCodeAt(E));)E++;T=W===d.length-1&&!b?x:x-1}y.push(F.slice(E,T))}N=y.join("")}for(var K=N.length,Q=0,U=!1;Q<K;){var w=N.charCodeAt(Q);if(w!==CH_BACKSLASH){if(!U&&(w===CH_EQUALS||w===CH_COLON||isWhitespace(w)))break;U=!1,Q++}else U=!U,Q++}var j=N.slice(0,Q),G="",M=void 0,P="",R=Q;if(R<K){for(var D=R;R<K&&isWhitespace(N.charCodeAt(R));)R++;if(R<K){var V=N.charCodeAt(R);if(V===CH_EQUALS||V===CH_COLON){G=N.slice(D,R),M=V===CH_EQUALS?"=":":";for(var q=++R;R<K&&isWhitespace(N.charCodeAt(R));)R++;P=N.slice(q,R)}else G=N.slice(D,R)}else G=N.slice(D,R)}var z=N.slice(R),I={type:"property",rawLines:d,leadingWhitespace:g,key:-1!==j.indexOf("\\")?unescapeContent(j):j,escapedKey:j,separatorLeading:G,separatorChar:M,separatorTrailing:P,value:-1!==z.indexOf("\\")?unescapeContent(z):z,escapedValue:z,startingLineNumber:u,endingLineNumber:O};o.push(I),l++}else{var J={type:"comment",rawLine:H,leadingWhitespace:v>0?H.slice(0,v):"",delimiter:_===CH_HASH?"#":"!",body:H.slice(v+1),lineNumber:p};o.push(J),l++}}}return{hasBom:s,eolCharacter:n,nodes:o}};