properties-file 3.3.19 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +281 -281
- package/lib/cjs/editor/index.js +1 -0
- package/lib/{escape → cjs/escape}/index.d.ts +2 -2
- package/lib/cjs/escape/index.js +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/loader/webpack.js +1 -0
- package/lib/cjs/package.json +1 -0
- package/lib/{properties-file.d.ts → cjs/properties-file.d.ts} +7 -7
- package/lib/cjs/properties.js +1 -0
- package/lib/{property-line.d.ts → cjs/property-line.d.ts} +1 -1
- package/lib/cjs/property-line.js +1 -0
- package/lib/cjs/property.js +1 -0
- package/lib/cjs/unescape/index.js +1 -0
- package/lib/esm/editor/index.d.ts +139 -0
- package/lib/esm/editor/index.js +1 -0
- package/lib/esm/escape/index.d.ts +18 -0
- package/lib/esm/escape/index.js +1 -0
- package/lib/esm/index.d.ts +17 -0
- package/lib/esm/index.js +1 -0
- package/lib/esm/loader/webpack.d.ts +10 -0
- package/lib/esm/loader/webpack.js +1 -0
- package/lib/esm/properties-file.d.ts +7 -0
- package/lib/esm/properties.d.ts +95 -0
- package/lib/esm/properties.js +1 -0
- package/lib/esm/property-line.d.ts +22 -0
- package/lib/esm/property-line.js +1 -0
- package/lib/esm/property.d.ts +83 -0
- package/lib/esm/property.js +1 -0
- package/lib/esm/unescape/index.d.ts +11 -0
- package/lib/esm/unescape/index.js +1 -0
- package/package.json +132 -100
- package/lib/editor/index.js +0 -74
- package/lib/escape/index.js +0 -23
- package/lib/index.js +0 -9
- package/lib/loader/webpack.js +0 -7
- package/lib/properties.js +0 -52
- package/lib/property-line.js +0 -9
- package/lib/property.js +0 -39
- package/lib/unescape/index.js +0 -17
- /package/lib/{editor → cjs/editor}/index.d.ts +0 -0
- /package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/lib/{loader → cjs/loader}/webpack.d.ts +0 -0
- /package/lib/{properties.d.ts → cjs/properties.d.ts} +0 -0
- /package/lib/{property.d.ts → cjs/property.d.ts} +0 -0
- /package/lib/{unescape → cjs/unescape}/index.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,100 +1,132 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "properties-file",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": ".properties file parser, editor, formatter and Webpack loader.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
".properties",
|
|
7
|
-
"properties",
|
|
8
|
-
".properties file",
|
|
9
|
-
"properties file",
|
|
10
|
-
"parser",
|
|
11
|
-
"editor",
|
|
12
|
-
"formatter",
|
|
13
|
-
"Java",
|
|
14
|
-
"intl",
|
|
15
|
-
"i18n",
|
|
16
|
-
"properties Webpack loader",
|
|
17
|
-
"Webpack loader",
|
|
18
|
-
"internationalization"
|
|
19
|
-
],
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/Avansai/properties-file.git"
|
|
23
|
-
},
|
|
24
|
-
"license": "MIT",
|
|
25
|
-
"author": "Avansai (https://avansai.com)",
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"lib/
|
|
42
|
-
|
|
43
|
-
"
|
|
44
|
-
"lib/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
"
|
|
99
|
-
|
|
100
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "properties-file",
|
|
3
|
+
"version": "3.4.0",
|
|
4
|
+
"description": ".properties file parser, editor, formatter and Webpack loader.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
".properties",
|
|
7
|
+
"properties",
|
|
8
|
+
".properties file",
|
|
9
|
+
"properties file",
|
|
10
|
+
"parser",
|
|
11
|
+
"editor",
|
|
12
|
+
"formatter",
|
|
13
|
+
"Java",
|
|
14
|
+
"intl",
|
|
15
|
+
"i18n",
|
|
16
|
+
"properties Webpack loader",
|
|
17
|
+
"Webpack loader",
|
|
18
|
+
"internationalization"
|
|
19
|
+
],
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Avansai/properties-file.git"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"author": "Avansai (https://avansai.com)",
|
|
26
|
+
"type": "module",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./lib/esm/index.d.ts",
|
|
31
|
+
"default": "./lib/esm/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./lib/cjs/index.d.ts",
|
|
35
|
+
"default": "./lib/cjs/index.js"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./editor": {
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./lib/esm/editor/index.d.ts",
|
|
41
|
+
"default": "./lib/esm/editor/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./lib/cjs/editor/index.d.ts",
|
|
45
|
+
"default": "./lib/cjs/editor/index.js"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./escape": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./lib/esm/escape/index.d.ts",
|
|
51
|
+
"default": "./lib/esm/escape/index.js"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./lib/cjs/escape/index.d.ts",
|
|
55
|
+
"default": "./lib/cjs/escape/index.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./unescape": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./lib/esm/unescape/index.d.ts",
|
|
61
|
+
"default": "./lib/esm/unescape/index.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./lib/cjs/unescape/index.d.ts",
|
|
65
|
+
"default": "./lib/cjs/unescape/index.js"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
"./webpack-loader": {
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./lib/esm/loader/webpack.d.ts",
|
|
71
|
+
"default": "./lib/esm/loader/webpack.js"
|
|
72
|
+
},
|
|
73
|
+
"require": {
|
|
74
|
+
"types": "./lib/cjs/loader/webpack.d.ts",
|
|
75
|
+
"default": "./lib/cjs/loader/webpack.js"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"main": "lib/cjs/index.js",
|
|
80
|
+
"module": "lib/esm/index.js",
|
|
81
|
+
"types": "lib/esm/index.d.ts",
|
|
82
|
+
"files": [
|
|
83
|
+
"lib"
|
|
84
|
+
],
|
|
85
|
+
"scripts": {
|
|
86
|
+
"add-file-type-declaration": "node ./lib/esm/add-import-type.js && find ./lib -name 'add-import-type.*' -type f -delete",
|
|
87
|
+
"build": "check-node-version --node '>=16' && npm run prettier && npm run lint-fix && rm -Rf ./lib && tsc -p tsconfig.cjs.json && tsc -p tsconfig.esm.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json && tsc -p tsconfig.build-scripts.json && node lib/build-scripts/run-all.js && npm run test",
|
|
88
|
+
"ci": "npm run build",
|
|
89
|
+
"lint-check": "eslint --ext .js --ext .jsx --ext .ts --ext .tsx --ext .json .",
|
|
90
|
+
"lint-fix": "eslint --fix .",
|
|
91
|
+
"lint-print-config": "eslint --print-config ./eslintrc.yaml",
|
|
92
|
+
"prettier": "prettier --write .",
|
|
93
|
+
"release": "dotenv -- release-it --only-version",
|
|
94
|
+
"test": "jest --coverage"
|
|
95
|
+
},
|
|
96
|
+
"devDependencies": {
|
|
97
|
+
"@release-it/conventional-changelog": "8.0.1",
|
|
98
|
+
"@types/jest": "29.5.12",
|
|
99
|
+
"@types/node": "^20.11.21",
|
|
100
|
+
"@typescript-eslint/eslint-plugin": "7.1.0",
|
|
101
|
+
"@typescript-eslint/parser": "7.1.0",
|
|
102
|
+
"check-node-version": "^4.2.1",
|
|
103
|
+
"dotenv-cli": "7.3.0",
|
|
104
|
+
"eslint": "8.57.0",
|
|
105
|
+
"eslint-config-prettier": "9.1.0",
|
|
106
|
+
"eslint-import-resolver-node": "0.3.9",
|
|
107
|
+
"eslint-import-resolver-typescript": "3.6.1",
|
|
108
|
+
"eslint-plugin-import": "2.29.1",
|
|
109
|
+
"eslint-plugin-jest": "27.9.0",
|
|
110
|
+
"eslint-plugin-jsdoc": "^48.2.0",
|
|
111
|
+
"eslint-plugin-json-files": "4.1.0",
|
|
112
|
+
"eslint-plugin-prefer-arrow-functions": "3.3.2",
|
|
113
|
+
"eslint-plugin-prettier": "5.1.3",
|
|
114
|
+
"eslint-plugin-tsdoc": "0.2.17",
|
|
115
|
+
"eslint-plugin-unicorn": "51.0.1",
|
|
116
|
+
"glob": "^10.3.10",
|
|
117
|
+
"globals": "^14.0.0",
|
|
118
|
+
"jest": "29.7.0",
|
|
119
|
+
"jsonc-eslint-parser": "^2.4.0",
|
|
120
|
+
"prettier": "3.2.5",
|
|
121
|
+
"prettier-plugin-organize-imports": "3.2.4",
|
|
122
|
+
"prettier-plugin-sh": "0.14.0",
|
|
123
|
+
"release-it": "17.1.1",
|
|
124
|
+
"terser": "^5.28.1",
|
|
125
|
+
"ts-jest": "29.1.2",
|
|
126
|
+
"ts-node": "10.9.2",
|
|
127
|
+
"typescript": "5.3.3"
|
|
128
|
+
},
|
|
129
|
+
"engines": {
|
|
130
|
+
"node": "*"
|
|
131
|
+
}
|
|
132
|
+
}
|
package/lib/editor/index.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertiesEditor=exports.DEFAULT_SEPARATOR=exports.DEFAULT_COMMENT_DELIMITER=void 0;var _escape=require("../escape"),_properties=require("../properties");/** The default separator between keys and values. */const DEFAULT_SEPARATOR=exports.DEFAULT_SEPARATOR="=",DEFAULT_COMMENT_DELIMITER=exports.DEFAULT_COMMENT_DELIMITER="#";/** The default character used as comment delimiter. */ /** Characters that can be used as key-value pair separators. */ /** Characters that can be used as comment delimiters. */ /** Options on the `Properties.insert` method. */ /** Options on the `Properties.insertComment` method. */ /** Options on the `Properties.update` method. */ /** Options on the `Properties.upsert` method. */ /**
|
|
2
|
-
* A .properties file editor.
|
|
3
|
-
*/class PropertiesEditor extends _properties.Properties{/** Is line parsing required to re-async the object's properties? */needsLineParsing=!1;/**
|
|
4
|
-
* Create `PropertiesEditor` object.
|
|
5
|
-
*
|
|
6
|
-
* @param content - The content of a `.properties` file.
|
|
7
|
-
*/constructor(a){super(a)}/**
|
|
8
|
-
* Parse the `.properties` content line by line only when needed.
|
|
9
|
-
*/parseLinesIfNeeded(){this.needsLineParsing&&(this.parseLines(),this.needsLineParsing=!1)}/**
|
|
10
|
-
* Insert a new property in the existing object (by default it will be at the end).
|
|
11
|
-
*
|
|
12
|
-
* @param key - A property key (unescaped).
|
|
13
|
-
* @param value - A property value (unescaped).
|
|
14
|
-
* @param options - Additional options.
|
|
15
|
-
*
|
|
16
|
-
* @returns True if the key was inserted, otherwise false.
|
|
17
|
-
*/insert(a,b,c){const d=c?.escapeUnicode||!1,e=c?.separator?" "===c.separator?" ":` ${c.separator} `:` ${DEFAULT_SEPARATOR} `.replace(" "," "),f=c?.referenceKey,g=c?.position||"after";f&&this.parseLinesIfNeeded();// Allow multiline keys.
|
|
18
|
-
const h=a.split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,d)).join("\\\n"),i=b.split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,d)).join("\\\n"),j=`${c?.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,k=c?.comment===void 0?"":`${`${j}${c.comment}`.split(/\r?\n/).join(`\n${j}`)}\n`,l=`${k}${h}${e}${i}`.split(/\n/);// Allow multiline values.
|
|
19
|
-
// Allow multiline comments.
|
|
20
|
-
if(void 0===f)return this.lines.push(...l),this.needsLineParsing=!0,!0;else{// Find the last occurrence of the reference key.
|
|
21
|
-
const a=[...this.collection].reverse().find(a=>a.key===f);// Insert the new property when a reference key defined only when found.
|
|
22
|
-
if(a){const b="after"===g?a.endingLineNumber:a.previousProperty?.endingLineNumber??0;return this.lines=[...this.lines.slice(0,b),...l,...this.lines.slice(b)],this.needsLineParsing=!0,!0}return!1}}/**
|
|
23
|
-
* Insert a new comment in the existing object (by default it will be at the end).
|
|
24
|
-
*
|
|
25
|
-
* @param comment - The comment to add.
|
|
26
|
-
* @param options - Additional options.
|
|
27
|
-
*
|
|
28
|
-
* @returns True if the comment was inserted, otherwise false.
|
|
29
|
-
*/insertComment(a,b){const c=b?.referenceKey,d=b?.position||"after";c&&this.parseLinesIfNeeded();// Allow multiline comments.
|
|
30
|
-
const e=`${b?.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,f=`${e}${a}`.replace(/\r?\n/g,`\n${e}`).split(/\n/);if(void 0===c)return this.lines.push(...f),this.needsLineParsing=!0,!0;else{// Find the last occurrence of the reference key.
|
|
31
|
-
const a=[...this.collection].reverse().find(a=>a.key===c);// Insert the new comment when a reference key defined only when found.
|
|
32
|
-
if(a){const b="after"===d?a.endingLineNumber:a.previousProperty?.endingLineNumber??0;return this.lines=[...this.lines.slice(0,b),...f,...this.lines.slice(b)],this.needsLineParsing=!0,!0}return!1}}/**
|
|
33
|
-
* Delete the last occurrence of a given key from the existing object.
|
|
34
|
-
*
|
|
35
|
-
* @param key - The name of the key to delete.
|
|
36
|
-
* @param deleteCommentsAndWhiteSpace - By default, comments and white-space characters before the key will be deleted.
|
|
37
|
-
*
|
|
38
|
-
* @returns True if the key was deleted, otherwise false.
|
|
39
|
-
*/delete(a){let b=!(1<arguments.length&&arguments[1]!==void 0)||arguments[1];this.parseLinesIfNeeded();// Find the last occurrence of the key.
|
|
40
|
-
const c=[...this.collection].reverse().find(b=>b.key===a);if(c){const a=b?c.previousProperty?.endingLineNumber??0:c.startingLineNumber-1,d=c.endingLineNumber;return this.lines=[...this.lines.slice(0,a),...this.lines.slice(d)],this.needsLineParsing=!0,!0}return!1}/**
|
|
41
|
-
* Restore the original newline characters of a key.
|
|
42
|
-
*
|
|
43
|
-
* @param property - A property object.
|
|
44
|
-
*
|
|
45
|
-
* @returns The key with its original newlines characters restored.
|
|
46
|
-
*/getKeyWithNewlines(a){return 0===a.newlinePositions.length?a.key:// eslint-disable-next-line unicorn/no-array-reduce
|
|
47
|
-
[...a.key].reduce((b,c,d)=>`${b}${a.newlinePositions.includes(d)?"\n":""}${c}`,"")}/**
|
|
48
|
-
* Restore the original newline characters of a value.
|
|
49
|
-
*
|
|
50
|
-
* @param property - A property object.
|
|
51
|
-
*
|
|
52
|
-
* @returns The value with its original newlines characters restored.
|
|
53
|
-
*/getValueWithNewlines(a){return 0===a.newlinePositions.length||a.valuePosition===void 0?a.value:// eslint-disable-next-line unicorn/no-array-reduce
|
|
54
|
-
[...a.value].reduce((b,c,d)=>`${b}${a.newlinePositions.includes(d+a.valuePosition)?"\n":""}${c}`,"")}/**
|
|
55
|
-
* Update the last occurrence of a given key from the existing object.
|
|
56
|
-
*
|
|
57
|
-
* @param key - The name of the key to update.
|
|
58
|
-
* @param options - Additional options.
|
|
59
|
-
*
|
|
60
|
-
* @returns True if the key was updated, otherwise false.
|
|
61
|
-
*/update(a,b){this.parseLinesIfNeeded();// Find the last occurrence of the key to update.
|
|
62
|
-
const c=[...this.collection].reverse().find(b=>b.key===a);if(!c||!b)return!1;const d=b.escapeUnicode||!1,e=b.separator?" "===b.separator?" ":` ${b.separator} `:c.separator||` ${DEFAULT_SEPARATOR} `.replace(" "," "),f=(b.newKey??this.getKeyWithNewlines(c)).split(/\r?\n/).map(a=>(0,_escape.escapeKey)(a,d)).join("\\\n"),g=(b.newValue??this.getValueWithNewlines(c)).split(/\r?\n/).map(a=>(0,_escape.escapeValue)(a,d)).join("\\\n"),h=`${b.commentDelimiter||DEFAULT_COMMENT_DELIMITER} `,i=void 0===b.newComment?"":`${`${h}${b.newComment}`.split(/\r?\n/).join(`\n${h}`)}\n`,j=`${i}${f}${e}${g}`.split(/\n/);// Allow multiline keys.
|
|
63
|
-
// Allow multiline values.
|
|
64
|
-
// Allow multiline comments.
|
|
65
|
-
// Replace the existing property with the new one.
|
|
66
|
-
return this.lines=[...this.lines.slice(0,void 0===b.newComment?c.startingLineNumber-1:c.previousProperty?.endingLineNumber??0),...j,...this.lines.slice(c.endingLineNumber)],this.needsLineParsing=!0,!0}/**
|
|
67
|
-
* Update a key if it exist, otherwise add it at the end.
|
|
68
|
-
*
|
|
69
|
-
* @param key - A property key (unescaped).
|
|
70
|
-
* @param value - A property value (unescaped).
|
|
71
|
-
* @param options - Additional options.
|
|
72
|
-
*
|
|
73
|
-
* @returns True if the key was updated or inserted, otherwise false.
|
|
74
|
-
*/upsert(a,b,c){return this.parseLinesIfNeeded(),this.keyLineNumbers[a]?this.update(a,{newValue:b,newComment:c?.comment,commentDelimiter:c?.commentDelimiter,separator:c?.separator,escapeUnicode:c?.escapeUnicode}):this.insert(a,b,c)}}exports.PropertiesEditor=PropertiesEditor;
|
package/lib/escape/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.escapeValue=exports.escapeKey=void 0;/**
|
|
2
|
-
* Escape a property key.
|
|
3
|
-
*
|
|
4
|
-
* @param unescapedKey - A property key to be escaped.
|
|
5
|
-
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
6
|
-
*
|
|
7
|
-
* @return The escaped key.
|
|
8
|
-
*/const escapeKey=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!0,b)};/**
|
|
9
|
-
* Escape property value.
|
|
10
|
-
*
|
|
11
|
-
* @param unescapedValue - Property value to be escaped.
|
|
12
|
-
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
13
|
-
*
|
|
14
|
-
* @return The escaped value.
|
|
15
|
-
*/exports.escapeKey=escapeKey;const escapeValue=function(a){let b=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return escapeContent(a,!1,b)};/**
|
|
16
|
-
* Escape the content from either key or value of a property.
|
|
17
|
-
*
|
|
18
|
-
* @param unescapedContent - The content to escape.
|
|
19
|
-
* @param escapeSpace - Escape spaces?
|
|
20
|
-
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
21
|
-
*
|
|
22
|
-
* @returns The escaped content.
|
|
23
|
-
*/exports.escapeValue=escapeValue;const escapeContent=(a,b,c)=>a.replace(new RegExp(`[\\s!#:=\\\\${c?"\\u0000-\\u001F\\u007F-\\uFFFF":""}]`,"g"),(a,c)=>" "===a?b||0===c?"\\ ":" ":"\\"===a?"\\\\":"\f"===a?"\\f":"\n"===a?"\\n":"\r"===a?"\\r":"\t"===a?"\\t":"="===a||":"===a||"#"===a||"!"===a?`\\${a}`:`\\u${a.codePointAt(0).toString(16).padStart(4,"0")}`);
|
package/lib/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";var _properties=require("./properties");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"Properties",{enumerable:!0,get:function(){return _properties.Properties}}),exports.getProperties=void 0;/**
|
|
2
|
-
* A key-value pair object.
|
|
3
|
-
*/ /**
|
|
4
|
-
* Converts the content of a `.properties` file to a key-value pair object.
|
|
5
|
-
*
|
|
6
|
-
* @param content - The content of a `.properties` file.
|
|
7
|
-
*
|
|
8
|
-
* @returns A key/value object representing the content of a `.properties` file.
|
|
9
|
-
*/const getProperties=a=>new _properties.Properties(a).toObject();exports.getProperties=getProperties;
|
package/lib/loader/webpack.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";var _=require("..");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;/**
|
|
2
|
-
* Webpack file loader for `.properties` files.
|
|
3
|
-
*
|
|
4
|
-
* @param content - the content of a `.properties` file.
|
|
5
|
-
*
|
|
6
|
-
* @returns A Webpack file loader string containing the content of a `.properties` file.
|
|
7
|
-
*/const webpackLoader=a=>`module.exports = ${JSON.stringify((0,_.getProperties)(a))};`;var _default=exports.default=webpackLoader;
|
package/lib/properties.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getFirstEolCharacter=exports.Properties=exports.KeyCollisions=exports.DEFAULT_END_OF_LINE_CHARACTER=exports.BOM_CODE_POINT=exports.BOM=void 0;var _property=require("./property"),_propertyLine=require("./property-line");/**
|
|
2
|
-
* Byte-order mark.
|
|
3
|
-
*/const BOM=exports.BOM="\uFEFF",BOM_CODE_POINT=exports.BOM_CODE_POINT=BOM.codePointAt(0),DEFAULT_END_OF_LINE_CHARACTER=exports.DEFAULT_END_OF_LINE_CHARACTER="\n",getFirstEolCharacter=a=>{const b=a.indexOf("\n");return 0>b?void 0:`${"\r"===a[b-1]?"\r":""}\n`};/** The default end of line character. */ /**
|
|
4
|
-
* Get the first end of line (EOL) character from multiline content.
|
|
5
|
-
*
|
|
6
|
-
* @param content - The content of a `.properties` file.
|
|
7
|
-
*
|
|
8
|
-
* @returns The multiline content's first end of line (EOL) character.
|
|
9
|
-
*/ /**
|
|
10
|
-
* A class representing the content of a .properties file.
|
|
11
|
-
*/exports.getFirstEolCharacter=getFirstEolCharacter;class Properties{/** Does the .properties content starts with a BOM character? */ /** The end of line character. */ /** `.properties` content split by line. */ /** The collection of property object. */collection=[];/** Object associating keys with their starting line numbers. */keyLineNumbers={};/**
|
|
12
|
-
* Create `Properties` object.
|
|
13
|
-
*
|
|
14
|
-
* @param content - The content of a `.properties` file.
|
|
15
|
-
*/constructor(a){const b="string"==typeof a?a:a.toString();this.hasBom=b.codePointAt(0)===BOM_CODE_POINT,this.eolCharacter=getFirstEolCharacter(b)??DEFAULT_END_OF_LINE_CHARACTER,this.lines=(this.hasBom?b.slice(1):b).split(/\r?\n/),this.parseLines()}/**
|
|
16
|
-
* Parse the `.properties` content line by line.
|
|
17
|
-
*/parseLines(){this.collection=[],this.keyLineNumbers={};/** Line number while parsing properties file content. */let a,b,c=0;/** The current property object being parsed. */ /** The previous property object that was parsed. */for(const d of this.lines){c++;const e=new _propertyLine.PropertyLine(d,!!a);if(!a){// Check if the line is a new property.
|
|
18
|
-
if(e.isComment||e.isBlank)continue;// Skip line if its a comment or blank.
|
|
19
|
-
// The line is a new property.
|
|
20
|
-
if(a=new _property.Property(e,c,b),e.isContinuing)continue;// Continue parsing the next line.
|
|
21
|
-
}else if(a.addLine(e),e.isContinuing)continue;// If the line does not continue, add the property to the collection.
|
|
22
|
-
this.addToCollection(a),b=a,a=void 0}}/**
|
|
23
|
-
* Add a property object into a properties object collection.
|
|
24
|
-
*
|
|
25
|
-
* @param property - A property object, or undefined.
|
|
26
|
-
*
|
|
27
|
-
* @returns Undefined so that we conveniently overwrite the property object.
|
|
28
|
-
*/addToCollection(a){// Add the property to the collection.
|
|
29
|
-
a.setKeyAndValue(),this.keyLineNumbers[a.key]?.length?(this.keyLineNumbers[a.key].push(a.startingLineNumber),a.hasKeyCollisions=!0,a.keyCollisionLines=this.keyLineNumbers[a.key],this.collection=this.collection.filter(b=>b.key!==a.key)):this.keyLineNumbers[a.key]=[a.startingLineNumber],this.collection.push(a)}/**
|
|
30
|
-
* Get keys that have collisions (more than one occurrence).
|
|
31
|
-
*/getKeyCollisions(){const a=[];for(const[b,c]of Object.entries(this.keyLineNumbers))1<c.length&&a.push(new KeyCollisions(b,c));return a}/**
|
|
32
|
-
* Get the key/value object representing the properties.
|
|
33
|
-
*
|
|
34
|
-
* @returns A key/value object representing the properties.
|
|
35
|
-
*/toObject(){const a={};return this.collection.forEach(b=>{a[b.key]=b.value}),a}/**
|
|
36
|
-
* Format the object in `.properties`.
|
|
37
|
-
*
|
|
38
|
-
* @param endOfLineCharacter - The character used for end of lines.
|
|
39
|
-
*
|
|
40
|
-
* @returns The object in `.properties` format.
|
|
41
|
-
*/format(a){return`${this.hasBom?BOM:""}${this.lines.join(a||this.eolCharacter)}`}}/**
|
|
42
|
-
* Object associating keys with their line numbers.
|
|
43
|
-
*/exports.Properties=Properties;/**
|
|
44
|
-
* A class representing key within a .properties file that had collisions (more than one occurrence).
|
|
45
|
-
*/class KeyCollisions{/** The key with collisions. */ /** The starting line numbers where collisions are found. */ /**
|
|
46
|
-
* Create a new key collision object.
|
|
47
|
-
*
|
|
48
|
-
* @param key - The key with collisions.
|
|
49
|
-
* @param startingLineNumbers - The starting line numbers where collisions are found.
|
|
50
|
-
*/constructor(a,b){this.key=a,this.startingLineNumbers=b}/**
|
|
51
|
-
* Get the number of the line from which the value will be used.
|
|
52
|
-
*/getApplicableLineNumber(){return this.startingLineNumbers.slice(-1)[0]}}exports.KeyCollisions=KeyCollisions;
|
package/lib/property-line.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PropertyLine=void 0;/**
|
|
2
|
-
* Object representing a line from the content of .properties file.
|
|
3
|
-
*/class PropertyLine{/** The line content, minus the trailing \ that identifies that the line is continuing. */ /** True if the line is continuing to the next line, otherwise false. */isContinuing=!1;/** True if the line is blank, otherwise false. */isBlank=!1;/** True if the line is a comment, otherwise false. */isComment=!1;/** Is the line object a continuation from a previous line? */ /**
|
|
4
|
-
* Create a new line object.
|
|
5
|
-
*
|
|
6
|
-
* @param line - The raw content of a line.
|
|
7
|
-
* @param isMultiline - Is the line spreading on multiple lines?
|
|
8
|
-
*/constructor(a,b){if(this.content=a.trimStart(),this.isMultiline=b,0===this.content.length)this.isBlank=!0;else if(this.isMultiline||(this.isComment=!!/^[!#]/.test(this.content)),!this.isComment){// Otherwise, check if the line is continuing on the next line.
|
|
9
|
-
const a=this.content.match(/(?<backslashes>\\+)$/);a?.groups&&(this.isContinuing=!!(a.groups.backslashes.length%2),this.isContinuing&&(this.content=this.content.slice(0,-1)))}}}exports.PropertyLine=PropertyLine;
|
package/lib/property.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";var _unescape=require("./unescape");Object.defineProperty(exports,"__esModule",{value:!0}),exports.Property=void 0;/**
|
|
2
|
-
* Object representing a property (key/value).
|
|
3
|
-
*/class Property{/** The content of one or multiple lines when applicable. */ /** The property key (unescaped). */key="";/** The property key, including its escaped characters. */escapedKey="";/** Is the key empty? */hasNoKey=!1;/** Does the key definition spread across multiple lines? */hasMultilineKey=!1;/** Starting line numbers of property objects with the same key. */keyCollisionLines=[];/** Was the property's key used more than once? */hasKeyCollisions=!1;/** The key/value pair separator */ /** The length of the key/value pair separator, including its whitespace characters. */ /** The starting position of the key/value pair separator. */ /** The property value (unescaped). */value="";/** The starting position of the value. */ /** The property value, including its escaped characters. */escapedValue="";/** Is the value empty? */hasNoValue=!1;/** Positions of the newline characters if any. */newlinePositions=[];/** The line number at which the property starts. */ /** The line number at which the property ends. */ /** The previous property object if it exists. */ /** The next property object if it exists. */ /**
|
|
4
|
-
* Create a new property object.
|
|
5
|
-
*
|
|
6
|
-
* @param propertyLine - A property line object.
|
|
7
|
-
* @param startingLineNumber - The line number at which the property starts.
|
|
8
|
-
*/constructor(a,b,c){this.linesContent=a.content,this.startingLineNumber=b,this.endingLineNumber=b,this.previousProperty=c,c?.setNextProperty(this)}/**
|
|
9
|
-
* Set the next property object.
|
|
10
|
-
*
|
|
11
|
-
* @param property - The next property object
|
|
12
|
-
*/setNextProperty(a){this.nextProperty=a}/**
|
|
13
|
-
* Add the a line to a multiline property object.
|
|
14
|
-
*
|
|
15
|
-
* @param propertyLine - A property line object.
|
|
16
|
-
*/addLine(a){0<this.linesContent.length&&(this.newlinePositions.push(this.linesContent.length),this.endingLineNumber++),this.linesContent+=a.content}/**
|
|
17
|
-
* Set the property's key and value.
|
|
18
|
-
*/setKeyAndValue(){this.findSeparator(),this.separatorPosition!==void 0&&this.separatorLength!==void 0?(!this.hasNoKey&&(this.escapedKey=this.linesContent.slice(0,this.separatorPosition),this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber)),!this.hasNoValue&&(this.escapedValue=this.linesContent.slice(this.separatorPosition+this.separatorLength),this.value=this.unescapeLine(this.escapedValue,this.startingLineNumber))):this.hasNoValue&&(this.escapedKey=this.linesContent,this.key=this.unescapeLine(this.escapedKey,this.startingLineNumber))}/**
|
|
19
|
-
* Unescape the content from either key or value of a property.
|
|
20
|
-
*
|
|
21
|
-
* @param escapedContent - The content to unescape.
|
|
22
|
-
* @param startingLineNumber - The starting line number of the content being unescaped.
|
|
23
|
-
*
|
|
24
|
-
* @returns The unescaped content.
|
|
25
|
-
*
|
|
26
|
-
* @throws {@link Error}
|
|
27
|
-
* This exception is thrown if malformed escaped unicode characters are present.
|
|
28
|
-
*/unescapeLine(a,b){try{return(0,_unescape.unescapeContent)(a)}catch(a){throw new Error(`${a.message} in property starting at line ${b}`)}}/**
|
|
29
|
-
* Find the character separating the key from the value.
|
|
30
|
-
*/findSeparator(){// If the separator was already found, skip.
|
|
31
|
-
if(!(this.hasNoKey||this.hasNoValue||this.separatorPosition)){// Only match separators to avoid iterating all characters.
|
|
32
|
-
for(const a of this.linesContent.matchAll(/[\t\f :=]/g)){const b=a.index,c=this.linesContent.slice(0,b),d=c.match(/(?<backslashes>\\+)$/);// Check if the separator might be escaped.
|
|
33
|
-
if(d?.groups){const a=!!(d.groups.backslashes.length%2);if(a)// If the separator is escaped, check the next character.
|
|
34
|
-
continue}let e="";this.separatorPosition=b;// Check if the separator starts with a whitespace.
|
|
35
|
-
let f=this.linesContent.slice(b);// All white-space characters, excluding non-breaking spaces.
|
|
36
|
-
const g=f.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),h=g?.groups?.whitespace||"";// If there is a whitespace, move to the next character.
|
|
37
|
-
// Check if there is an equal or colon character.
|
|
38
|
-
if(0<h.length&&(e+=h,f=f.slice(h.length)),/[:=]/.test(f[0])){e+=f[0],f=f.slice(1);// If an equal or colon character was found, try to get trailing whitespace.
|
|
39
|
-
const a=f.match(/^(?<whitespace>[\t\n\v\f\r ]+)/),b=a?.groups?.whitespace||"";e+=b}this.separatorLength=e.length,this.valuePosition=this.separatorPosition+this.separatorLength,this.separator=this.linesContent.slice(this.separatorPosition,this.separatorPosition+this.separatorLength),b||(this.hasNoKey=!0);break}void 0===this.separatorPosition?this.hasNoValue=!0:0<this.newlinePositions.length&&this.newlinePositions[0]<this.separatorPosition&&(this.hasMultilineKey=!0)}}}exports.Property=Property;
|
package/lib/unescape/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.unescapeContent=void 0;/**
|
|
2
|
-
* Unescape the content from either key or value of a property.
|
|
3
|
-
*
|
|
4
|
-
* @param escapedContent - The content to unescape.
|
|
5
|
-
*
|
|
6
|
-
* @returns The unescaped content.
|
|
7
|
-
*
|
|
8
|
-
* @throws {@link Error}
|
|
9
|
-
* This exception is thrown if malformed escaped unicode characters are present.
|
|
10
|
-
*/const unescapeContent=a=>// By using a regular expression we avoid iterating through all characters and improve performance.
|
|
11
|
-
a.replace(/\\[^u]|\\u.{4}/g,a=>{const b=a.charAt(1);switch(b){case"f":// Formfeed.
|
|
12
|
-
return"\f";case"n":// Newline.
|
|
13
|
-
return"\n";case"r":// Carriage return.
|
|
14
|
-
return"\r";case"t":// Tab.
|
|
15
|
-
return"\t";case"u":{// Unicode character.
|
|
16
|
-
const b=a.slice(2,6);if(!/[\da-f]{4}/i.test(b))// Code point can only be within Unicode's Multilingual Plane (BMP).
|
|
17
|
-
throw new Error(`malformed escaped unicode characters '\\u${b}'`);return String.fromCodePoint(Number.parseInt(b,16))}default:return b}});exports.unescapeContent=unescapeContent;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|