properties-file 5.0.1 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cjs/editor/index.d.ts +21 -1
- package/dist/cjs/editor/index.js +1 -1
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/editor/index.d.ts +21 -1
- package/dist/esm/editor/index.js +1 -1
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/parse-properties.d.ts +0 -22
- package/dist/cjs/parse-properties.js +0 -1
- package/dist/esm/parse-properties.d.ts +0 -22
- package/dist/esm/parse-properties.js +0 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://opensource.org/licenses/MIT)
|
|
4
4
|
[](https://www.npmjs.com/package/properties-file)
|
|
5
5
|

|
|
6
|
-

|
|
7
7
|

|
|
8
8
|
|
|
9
9
|
`.properties` file parser, editor, formatter and bundler integrations.
|
|
@@ -28,7 +28,7 @@ npm install properties-file
|
|
|
28
28
|
- `PropertiesEditor` enables insertion, edition, and removal of entries while preserving formatting.
|
|
29
29
|
- `escapeKey` and `escapeValue` convert any content to `.properties` compatible format.
|
|
30
30
|
- Bundler integrations for Webpack, Rollup/Vite, esbuild, and Bun to import `.properties` files directly. See [BUNDLER.md](./docs/BUNDLER.md).
|
|
31
|
-
- **Tiny with 0 dependencies** — `getProperties` is only
|
|
31
|
+
- **Tiny with 0 dependencies** — `getProperties` is only 1014 B min+gzip.
|
|
32
32
|
- **Runs everywhere** — compiled to ES5, works in any browser and on Node.js all the way back to v0.10 (2013). [Verified via Docker](./tests/node-compat/).
|
|
33
33
|
- **100% test coverage** based on the output from a Java implementation.
|
|
34
34
|
- Active maintenance (many popular `.properties` packages have been inactive for years). See our [detailed comparison](./docs/COMPARISON.md) with other packages.
|
|
@@ -89,12 +89,28 @@ export type DeleteOptions = {
|
|
|
89
89
|
* the previous property) are also removed.
|
|
90
90
|
*/
|
|
91
91
|
deleteLeadingNodes?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Which occurrence of the key to delete when duplicates exist.
|
|
94
|
+
* - `'last'` (default) — deletes the last occurrence (the effective value in
|
|
95
|
+
* Java's last-wins semantics).
|
|
96
|
+
* - `'first'` — deletes the first occurrence. Useful for cleaning up duplicate
|
|
97
|
+
* keys while keeping the effective value.
|
|
98
|
+
*/
|
|
99
|
+
occurrence?: 'first' | 'last';
|
|
92
100
|
};
|
|
93
101
|
/**
|
|
94
102
|
* An editor for `.properties` files that extends the lossless {@link Properties}
|
|
95
103
|
* parser with insert, update, delete, and upsert operations.
|
|
96
104
|
*/
|
|
97
105
|
export declare class PropertiesEditor extends Properties {
|
|
106
|
+
/**
|
|
107
|
+
* Find the index of the first property node with the given key.
|
|
108
|
+
*
|
|
109
|
+
* @param key - The unescaped key to search for.
|
|
110
|
+
*
|
|
111
|
+
* @returns The index in `this.nodes`, or `-1` if not found.
|
|
112
|
+
*/
|
|
113
|
+
private findFirstPropertyIndex;
|
|
98
114
|
/**
|
|
99
115
|
* Find the index of the last property node with the given key.
|
|
100
116
|
*
|
|
@@ -142,7 +158,11 @@ export declare class PropertiesEditor extends Properties {
|
|
|
142
158
|
*/
|
|
143
159
|
upsert(key: string, value: string, options?: UpsertOptions): void;
|
|
144
160
|
/**
|
|
145
|
-
* Delete
|
|
161
|
+
* Delete an occurrence of a property.
|
|
162
|
+
*
|
|
163
|
+
* By default, deletes the last occurrence (the effective value in Java's last-wins
|
|
164
|
+
* semantics). Use `{ occurrence: 'first' }` to delete the first occurrence instead,
|
|
165
|
+
* which is useful for cleaning up duplicate keys while keeping the effective value.
|
|
146
166
|
*
|
|
147
167
|
* @param key - The unescaped key to delete.
|
|
148
168
|
* @param options - Delete options.
|
package/dist/cjs/editor/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,r){return null!=r&&"undefined"!=typeof Symbol&&r[Symbol.hasInstance]?!!r[Symbol.hasInstance](e):e instanceof r}function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];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,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!_instanceof(e,r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),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,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}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,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}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,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):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,r,t,n){var o,i=!0===t.escapeUnicode,a=(0,_index.escapeKey)(e,i),s=(0,_index.escapeValue)(r,i),l=" "===t.separator?void 0:null!==(o=t.separator)&&void 0!==o?o:DEFAULT_SEPARATOR,c=l?" ":"",u=l?"".concat(" ").concat(l).concat(c):" ",p="".concat(a).concat(u).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:p,leadingWhitespace:"",key:e,escapedKey:a,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){var r=1,t=!0,n=!1,o=void 0;try{for(var i,a=e[Symbol.iterator]();!(t=(i=a.next()).done);t=!0){var s=i.value;if("property"===s.type){var l=s.rawLines.length;s.startingLineNumber=r,s.endingLineNumber=r+l-1,r+=l}else s.lineNumber=r,r++}}catch(e){n=!0,o=e}finally{try{t||null==a.return||a.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:"findFirstPropertyIndex",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"findLastPropertyIndex",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"insert",value:function(e,r,t){var n,o,i=[];if(void 0!==(null==t?void 0:t.comment)){var a,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(a=i).push.apply(a,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(i.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastPropertyIndex(t.referenceKey);if(-1!==l){var c,u="before"===t.position?l:l+1;return(c=this.nodes).splice.apply(c,[u,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(n=this.nodes).push.apply(n,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertComment",value:function(e,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,i=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var a=this.findLastPropertyIndex(r.referenceKey);if(-1!==a){var s,l="before"===r.position?a:a+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(i))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(i)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastPropertyIndex(e.referenceKey);if(-1!==t){var n="before"===e.position?t:t+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,i=this.findLastPropertyIndex(e);if(-1===i)return!1;var a=this.nodes[i],s=null!==(t=r.newKey)&&void 0!==t?t:a.key,l=null!==(n=r.newValue)&&void 0!==n?n:a.value,c=!0===r.escapeUnicode,u=c?(0,_index.escapeKey)(s,!0):void 0!==r.newKey?(0,_index.escapeKey)(s):a.escapedKey,p=c?(0,_index.escapeValue)(l,!0):void 0!==r.newValue?(0,_index.escapeValue)(l):a.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:a.separatorChar,d=r.separator?" ":a.separatorLeading,y=r.separator?_?" ":"":a.separatorTrailing,f=_?"".concat(d).concat(_).concat(y):d,m="".concat(u).concat(f).concat(p).split(REGEX_NEWLINE),h={type:"property",rawLines:m,leadingWhitespace:a.leadingWhitespace,key:s,escapedKey:u,separatorLeading:d,separatorChar:_,separatorTrailing:y,value:l,escapedValue:p,startingLineNumber:a.startingLineNumber,endingLineNumber:a.startingLineNumber+m.length-1};if(void 0!==r.newComment){for(var v,b=i,L=i-1;L>=0&&"property"!==this.nodes[L].type;L--)b=L;var E=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,g=buildCommentNodes(r.newComment,E,0);(v=this.nodes).splice.apply(v,[b,i-b+1].concat(_to_consumable_array(g),[h]))}else this.nodes[i]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){-1!==this.findLastPropertyIndex(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstPropertyIndex(e):this.findLastPropertyIndex(e);if(-1!==t){var n=this.nodes[t];if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var o=t,i=t-1;i>=0&&"property"!==this.nodes[i].type;i--)o=i;this.nodes.splice(o,t-o+1)}else this.nodes.splice(t,1);return recalculateLineNumbers(this.nodes),n}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),e}();
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export type KeyValuePairObject = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts the content of a `.properties` file to a key-value pair object.
|
|
9
9
|
*
|
|
10
|
+
* This is a self-contained, zero-dependency parser optimized for minimal
|
|
11
|
+
* bundle size. It implements the Java `java.util.Properties` specification:
|
|
12
|
+
*
|
|
13
|
+
* - BOM detection and skipping
|
|
14
|
+
* - Comment lines (`#` or `!`)
|
|
15
|
+
* - Line continuations (trailing odd backslash)
|
|
16
|
+
* - Key-value separator detection (`=`, `:`, or whitespace)
|
|
17
|
+
* - Escape sequence processing (`\\n`, `\\t`, `\\r`, `\\f`, `\\\\`, `\\uXXXX`)
|
|
18
|
+
* - Last-value-wins semantics for duplicate keys
|
|
19
|
+
*
|
|
10
20
|
* @param content - The content of a `.properties` file.
|
|
11
21
|
*
|
|
12
22
|
* @returns A key/value object representing the content of a `.properties` file.
|
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"getProperties",{enumerable:!0,get:function(){return getProperties}});var
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"getProperties",{enumerable:!0,get:function(){return getProperties}});var CH_TAB=9,CH_FF=12,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,r,t){for(;r<t;){var C=e.charCodeAt(r);if(C!==CH_SPACE&&C!==CH_TAB&&C!==CH_FF)break;r++}return r},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){for(var r=e.length,t="",C=0,a=0;a<r;)if(e.charCodeAt(a)===CH_BACKSLASH){switch(a>C&&(t+=e.slice(C,a)),a++,e.charCodeAt(a)){case CH_LOWER_N:t+="\n",a++;break;case CH_LOWER_T:t+="\t",a++;break;case CH_LOWER_R:t+="\r",a++;break;case CH_LOWER_F:t+="\f",a++;break;case CH_LOWER_U:if(a+4>=r||!isHexDigit(e.charCodeAt(a+1))||!isHexDigit(e.charCodeAt(a+2))||!isHexDigit(e.charCodeAt(a+3))||!isHexDigit(e.charCodeAt(a+4))){var i=e.slice(a-1,a+5);throw new Error("malformed escaped unicode characters '".concat(i,"'"))}var c=hexValue(e.charCodeAt(a+1))<<12|hexValue(e.charCodeAt(a+2))<<8|hexValue(e.charCodeAt(a+3))<<4|hexValue(e.charCodeAt(a+4));t+=String.fromCharCode(c),a+=5;break;default:t+=e.charAt(a),a++}C=a}else a++;return C<r&&(t+=e.slice(C,r)),t},getProperties=function(e){for(var r="string"==typeof e?e:e.toString(),t={},C=(r.length>0&&r.charCodeAt(0)===CH_BOM?r.slice(1):r).split(/\r\n|\r|\n/),a=C.length,i=0;i<a;){var c=C[i],o=c.length,s=skipWhitespace(c,0,o);if(s>=o)i++;else{var H=c.charCodeAt(s);if(H!==CH_HASH&&H!==CH_BANG){for(var _=0,n=o-1;n>=0&&c.charCodeAt(n)===CH_BACKSLASH;n--)_++;var A=_%2==1,h=void 0,l=void 0;if(A){var f=(s>0?c.slice(s):c).slice(0,-1),d=[f];for(l=-1!==f.indexOf("\\");A&&i+1<a;){var u=C[++i],p=u.length,O=skipWhitespace(u,0,p);_=0;for(var v=p-1;v>=O&&u.charCodeAt(v)===CH_BACKSLASH;v--)_++;var L=(A=_%2==1)?u.slice(O,p-1):u.slice(O);l||-1===L.indexOf("\\")||(l=!0),d.push(L)}h=d.join("")}else l=-1!==(h=s>0?c.slice(s):c).indexOf("\\");for(var S=h.length,g=0,E=!1;g<S;){var x=h.charCodeAt(g);if(x!==CH_BACKSLASH){if(!E&&(x===CH_EQUALS||x===CH_COLON||x===CH_SPACE||x===CH_TAB||x===CH_FF))break;E=!1,g++}else E=!E,g++}var W=g;if(W<S){var B=h.charCodeAt(W);B!==CH_SPACE&&B!==CH_TAB&&B!==CH_FF||(W=skipWhitespace(h,W,S))<S&&(B=h.charCodeAt(W)),W<S&&(B===CH_EQUALS||B===CH_COLON)&&(W++,W=skipWhitespace(h,W,S))}var k=h.slice(0,g),R=h.slice(W);t[l?unescapeContent(k):k]=l?unescapeContent(R):R,i++}else i++}}return t};
|
|
@@ -89,12 +89,28 @@ export type DeleteOptions = {
|
|
|
89
89
|
* the previous property) are also removed.
|
|
90
90
|
*/
|
|
91
91
|
deleteLeadingNodes?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Which occurrence of the key to delete when duplicates exist.
|
|
94
|
+
* - `'last'` (default) — deletes the last occurrence (the effective value in
|
|
95
|
+
* Java's last-wins semantics).
|
|
96
|
+
* - `'first'` — deletes the first occurrence. Useful for cleaning up duplicate
|
|
97
|
+
* keys while keeping the effective value.
|
|
98
|
+
*/
|
|
99
|
+
occurrence?: 'first' | 'last';
|
|
92
100
|
};
|
|
93
101
|
/**
|
|
94
102
|
* An editor for `.properties` files that extends the lossless {@link Properties}
|
|
95
103
|
* parser with insert, update, delete, and upsert operations.
|
|
96
104
|
*/
|
|
97
105
|
export declare class PropertiesEditor extends Properties {
|
|
106
|
+
/**
|
|
107
|
+
* Find the index of the first property node with the given key.
|
|
108
|
+
*
|
|
109
|
+
* @param key - The unescaped key to search for.
|
|
110
|
+
*
|
|
111
|
+
* @returns The index in `this.nodes`, or `-1` if not found.
|
|
112
|
+
*/
|
|
113
|
+
private findFirstPropertyIndex;
|
|
98
114
|
/**
|
|
99
115
|
* Find the index of the last property node with the given key.
|
|
100
116
|
*
|
|
@@ -142,7 +158,11 @@ export declare class PropertiesEditor extends Properties {
|
|
|
142
158
|
*/
|
|
143
159
|
upsert(key: string, value: string, options?: UpsertOptions): void;
|
|
144
160
|
/**
|
|
145
|
-
* Delete
|
|
161
|
+
* Delete an occurrence of a property.
|
|
162
|
+
*
|
|
163
|
+
* By default, deletes the last occurrence (the effective value in Java's last-wins
|
|
164
|
+
* semantics). Use `{ occurrence: 'first' }` to delete the first occurrence instead,
|
|
165
|
+
* which is useful for cleaning up duplicate keys while keeping the effective value.
|
|
146
166
|
*
|
|
147
167
|
* @param key - The unescaped key to delete.
|
|
148
168
|
* @param options - Delete options.
|
package/dist/esm/editor/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function _array_like_to_array(e,
|
|
1
|
+
function _array_like_to_array(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];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,r,t){return r=_get_prototype_of(r),_possible_constructor_return(e,_is_native_reflect_construct()?Reflect.construct(r,t||[],_get_prototype_of(e).constructor):r.apply(e,t))}function _class_call_check(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _create_class(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),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,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_set_prototype_of(e,r)}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,r){return!r||"object"!==_type_of(r)&&"function"!=typeof r?_assert_this_initialized(e):r}function _set_prototype_of(e,r){return _set_prototype_of=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e},_set_prototype_of(e,r)}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,r){if(e){if("string"==typeof e)return _array_like_to_array(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(t):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_array_like_to_array(e,r):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,r,t,n){var o,a=!0===t.escapeUnicode,i=escapeKey(e,a),s=escapeValue(r,a),l=" "===t.separator?void 0:null!==(o=t.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:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+p.length-1}},buildCommentNodes=function(e,r,t){return e.split(REGEX_NEWLINE).map(function(e,n){return""===e?{type:"blank",rawLine:"",lineNumber:t+n}:{type:"comment",rawLine:"".concat(r," ").concat(e),leadingWhitespace:"",delimiter:r,body:" ".concat(e),lineNumber:t+n}})},recalculateLineNumbers=function(e){var r=1,t=!0,n=!1,o=void 0;try{for(var a,i=e[Symbol.iterator]();!(t=(a=i.next()).done);t=!0){var s=a.value;if("property"===s.type){var l=s.rawLines.length;s.startingLineNumber=r,s.endingLineNumber=r+l-1,r+=l}else s.lineNumber=r,r++}}catch(e){n=!0,o=e}finally{try{t||null==i.return||i.return()}finally{if(n)throw o}}};export var PropertiesEditor=function(e){"use strict";function r(){return _class_call_check(this,r),_call_super(this,r,arguments)}return _inherits(r,e),_create_class(r,[{key:"findFirstPropertyIndex",value:function(e){for(var r=0;r<this.nodes.length;r++){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"findLastPropertyIndex",value:function(e){for(var r=this.nodes.length-1;r>=0;r--){var t=this.nodes[r];if("property"===t.type&&t.key===e)return r}return-1}},{key:"insert",value:function(e,r,t){var n,o,a=[];if(void 0!==(null==t?void 0:t.comment)){var i,s=null!==(o=t.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER;(i=a).push.apply(i,_to_consumable_array(buildCommentNodes(t.comment,s,0)))}if(a.push(buildPropertyNode(e,r,{escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator},0)),null==t?void 0:t.referenceKey){var l=this.findLastPropertyIndex(t.referenceKey);if(-1!==l){var c,u="before"===t.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,r){var t,n,o=null!==(n=null==r?void 0:r.commentDelimiter)&&void 0!==n?n:DEFAULT_COMMENT_DELIMITER,a=buildCommentNodes(e,o,0);if(null==r?void 0:r.referenceKey){var i=this.findLastPropertyIndex(r.referenceKey);if(-1!==i){var s,l="before"===r.position?i:i+1;return(s=this.nodes).splice.apply(s,[l,0].concat(_to_consumable_array(a))),void recalculateLineNumbers(this.nodes)}}(t=this.nodes).push.apply(t,_to_consumable_array(a)),recalculateLineNumbers(this.nodes)}},{key:"insertBlankLine",value:function(e){var r={type:"blank",rawLine:"",lineNumber:0};if(null==e?void 0:e.referenceKey){var t=this.findLastPropertyIndex(e.referenceKey);if(-1!==t){var n="before"===e.position?t:t+1;return this.nodes.splice(n,0,r),void recalculateLineNumbers(this.nodes)}}this.nodes.push(r),recalculateLineNumbers(this.nodes)}},{key:"update",value:function(e,r){var t,n,o,a=this.findLastPropertyIndex(e);if(-1===a)return!1;var i=this.nodes[a],s=null!==(t=r.newKey)&&void 0!==t?t:i.key,l=null!==(n=r.newValue)&&void 0!==n?n:i.value,c=!0===r.escapeUnicode,u=c?escapeKey(s,!0):void 0!==r.newKey?escapeKey(s):i.escapedKey,p=c?escapeValue(l,!0):void 0!==r.newValue?escapeValue(l):i.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:i.separatorChar,d=r.separator?" ":i.separatorLeading,y=r.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!==r.newComment){for(var h,b=a,L=a-1;L>=0&&"property"!==this.nodes[L].type;L--)b=L;var g=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,E=buildCommentNodes(r.newComment,g,0);(h=this.nodes).splice.apply(h,[b,a-b+1].concat(_to_consumable_array(E),[v]))}else this.nodes[a]=v;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){-1!==this.findLastPropertyIndex(e)?this.update(e,{newValue:r,escapeUnicode:null==t?void 0:t.escapeUnicode,separator:null==t?void 0:t.separator,newComment:null==t?void 0:t.comment,commentDelimiter:null==t?void 0:t.commentDelimiter}):this.insert(e,r,t)}},{key:"delete",value:function(e,r){var t="first"===(null==r?void 0:r.occurrence)?this.findFirstPropertyIndex(e):this.findLastPropertyIndex(e);if(-1!==t){var n=this.nodes[t];if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var o=t,a=t-1;a>=0&&"property"!==this.nodes[a].type;a--)o=a;this.nodes.splice(o,t-o+1)}else this.nodes.splice(t,1);return recalculateLineNumbers(this.nodes),n}}},{key:"deleteAll",value:function(e){for(var r=[],t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];"property"===n.type&&n.key===e&&(this.nodes.splice(t,1),r.push(n))}return r.length>0&&recalculateLineNumbers(this.nodes),r.reverse()}}]),r}(Properties);
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -7,6 +7,16 @@ export type KeyValuePairObject = {
|
|
|
7
7
|
/**
|
|
8
8
|
* Converts the content of a `.properties` file to a key-value pair object.
|
|
9
9
|
*
|
|
10
|
+
* This is a self-contained, zero-dependency parser optimized for minimal
|
|
11
|
+
* bundle size. It implements the Java `java.util.Properties` specification:
|
|
12
|
+
*
|
|
13
|
+
* - BOM detection and skipping
|
|
14
|
+
* - Comment lines (`#` or `!`)
|
|
15
|
+
* - Line continuations (trailing odd backslash)
|
|
16
|
+
* - Key-value separator detection (`=`, `:`, or whitespace)
|
|
17
|
+
* - Escape sequence processing (`\\n`, `\\t`, `\\r`, `\\f`, `\\\\`, `\\uXXXX`)
|
|
18
|
+
* - Last-value-wins semantics for duplicate keys
|
|
19
|
+
*
|
|
10
20
|
* @param content - The content of a `.properties` file.
|
|
11
21
|
*
|
|
12
22
|
* @returns A key/value object representing the content of a `.properties` file.
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var CH_TAB=9,CH_FF=12,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,r,C){for(;r<C;){var a=e.charCodeAt(r);if(a!==CH_SPACE&&a!==CH_TAB&&a!==CH_FF)break;r++}return r},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){for(var r=e.length,C="",a=0,t=0;t<r;)if(e.charCodeAt(t)===CH_BACKSLASH){switch(t>a&&(C+=e.slice(a,t)),t++,e.charCodeAt(t)){case CH_LOWER_N:C+="\n",t++;break;case CH_LOWER_T:C+="\t",t++;break;case CH_LOWER_R:C+="\r",t++;break;case CH_LOWER_F:C+="\f",t++;break;case CH_LOWER_U:if(t+4>=r||!isHexDigit(e.charCodeAt(t+1))||!isHexDigit(e.charCodeAt(t+2))||!isHexDigit(e.charCodeAt(t+3))||!isHexDigit(e.charCodeAt(t+4))){var i=e.slice(t-1,t+5);throw new Error("malformed escaped unicode characters '".concat(i,"'"))}var c=hexValue(e.charCodeAt(t+1))<<12|hexValue(e.charCodeAt(t+2))<<8|hexValue(e.charCodeAt(t+3))<<4|hexValue(e.charCodeAt(t+4));C+=String.fromCharCode(c),t+=5;break;default:C+=e.charAt(t),t++}a=t}else t++;return a<r&&(C+=e.slice(a,r)),C};export var getProperties=function(e){for(var r="string"==typeof e?e:e.toString(),C={},a=(r.length>0&&r.charCodeAt(0)===CH_BOM?r.slice(1):r).split(/\r\n|\r|\n/),t=a.length,i=0;i<t;){var c=a[i],H=c.length,_=skipWhitespace(c,0,H);if(_>=H)i++;else{var o=c.charCodeAt(_);if(o!==CH_HASH&&o!==CH_BANG){for(var s=0,A=H-1;A>=0&&c.charCodeAt(A)===CH_BACKSLASH;A--)s++;var n=s%2==1,h=void 0,l=void 0;if(n){var f=(_>0?c.slice(_):c).slice(0,-1),d=[f];for(l=-1!==f.indexOf("\\");n&&i+1<t;){var v=a[++i],u=v.length,L=skipWhitespace(v,0,u);s=0;for(var O=u-1;O>=L&&v.charCodeAt(O)===CH_BACKSLASH;O--)s++;var S=(n=s%2==1)?v.slice(L,u-1):v.slice(L);l||-1===S.indexOf("\\")||(l=!0),d.push(S)}h=d.join("")}else l=-1!==(h=_>0?c.slice(_):c).indexOf("\\");for(var p=h.length,E=0,g=!1;E<p;){var W=h.charCodeAt(E);if(W!==CH_BACKSLASH){if(!g&&(W===CH_EQUALS||W===CH_COLON||W===CH_SPACE||W===CH_TAB||W===CH_FF))break;g=!1,E++}else g=!g,E++}var x=E;if(x<p){var B=h.charCodeAt(x);B!==CH_SPACE&&B!==CH_TAB&&B!==CH_FF||(x=skipWhitespace(h,x,p))<p&&(B=h.charCodeAt(x)),x<p&&(B===CH_EQUALS||B===CH_COLON)&&(x++,x=skipWhitespace(h,x,p))}var k=h.slice(0,E),R=h.slice(x);C[l?unescapeContent(k):k]=l?unescapeContent(R):R,i++}else i++}}return C};
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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};
|
|
@@ -1,22 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
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};
|