projen 0.103.4 → 0.103.6
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/.jsii +1565 -36
- package/lib/ai-instructions.js +2 -2
- package/lib/awscdk/auto-discover.js +6 -6
- package/lib/awscdk/awscdk-app-java.js +1 -1
- package/lib/awscdk/awscdk-app-py.js +1 -1
- package/lib/awscdk/awscdk-app-ts.js +1 -1
- package/lib/awscdk/awscdk-construct.js +1 -1
- package/lib/awscdk/awscdk-deps-java.js +1 -1
- package/lib/awscdk/awscdk-deps-js.js +1 -1
- package/lib/awscdk/awscdk-deps-py.js +1 -1
- package/lib/awscdk/awscdk-deps.js +1 -1
- package/lib/awscdk/cdk-config.js +3 -3
- package/lib/awscdk/cdk-tasks.js +1 -1
- package/lib/awscdk/integration-test.js +1 -1
- package/lib/awscdk/lambda-extension.js +1 -1
- package/lib/awscdk/lambda-function.js +2 -2
- package/lib/build/build-workflow.js +1 -1
- package/lib/cdk/auto-discover-base.js +2 -2
- package/lib/cdk/construct-lib.js +1 -1
- package/lib/cdk/integration-test-base.js +1 -1
- package/lib/cdk/jsii-build.js +1 -1
- package/lib/cdk/jsii-docgen.js +1 -1
- package/lib/cdk/jsii-project.js +1 -1
- package/lib/cdk8s/auto-discover.js +2 -2
- package/lib/cdk8s/cdk8s-app-py.js +1 -1
- package/lib/cdk8s/cdk8s-app-ts.js +1 -1
- package/lib/cdk8s/cdk8s-construct.js +1 -1
- package/lib/cdk8s/cdk8s-deps-py.js +1 -1
- package/lib/cdk8s/cdk8s-deps.js +1 -1
- package/lib/cdk8s/integration-test.js +1 -1
- package/lib/cdktf/cdktf-construct.js +1 -1
- package/lib/cdktn/cdktn-app-ts.js +1 -1
- package/lib/cdktn/cdktn-config.js +1 -1
- package/lib/cdktn/cdktn-construct.js +1 -1
- package/lib/cdktn/cdktn-deps.js +1 -1
- package/lib/cdktn/cdktn-tasks.js +1 -1
- package/lib/circleci/circleci.js +1 -1
- package/lib/component.js +2 -2
- package/lib/dependencies.js +1 -1
- package/lib/dev-env.js +1 -1
- package/lib/docker-compose/docker-compose-service.js +1 -1
- package/lib/docker-compose/docker-compose.js +1 -1
- package/lib/file.js +1 -1
- package/lib/gitattributes.js +1 -1
- package/lib/github/actions-provider.js +1 -1
- package/lib/github/auto-approve.js +1 -1
- package/lib/github/auto-merge.js +1 -1
- package/lib/github/auto-queue.js +1 -1
- package/lib/github/dependabot.js +1 -1
- package/lib/github/dependency-review.js +1 -1
- package/lib/github/github-credentials.js +1 -1
- package/lib/github/github-project.js +1 -1
- package/lib/github/github.js +1 -1
- package/lib/github/merge-queue.js +1 -1
- package/lib/github/mergify.js +1 -1
- package/lib/github/pr-template.js +1 -1
- package/lib/github/pull-request-backport.js +1 -1
- package/lib/github/pull-request-lint.js +1 -1
- package/lib/github/stale.js +1 -1
- package/lib/github/task-workflow-job.js +1 -1
- package/lib/github/task-workflow.js +1 -1
- package/lib/github/workflow-actions.js +1 -1
- package/lib/github/workflow-jobs.js +1 -1
- package/lib/github/workflow-steps.js +1 -1
- package/lib/github/workflows.js +1 -1
- package/lib/gitlab/configuration.js +1 -1
- package/lib/gitlab/gitlab-configuration.js +1 -1
- package/lib/gitlab/nested-configuration.js +1 -1
- package/lib/gitpod.js +1 -1
- package/lib/ignore-file.js +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +4 -2
- package/lib/ini.js +1 -1
- package/lib/java/java-project.js +1 -1
- package/lib/java/junit.js +1 -1
- package/lib/java/maven-compile.js +1 -1
- package/lib/java/maven-packaging.js +1 -1
- package/lib/java/maven-sample.js +1 -1
- package/lib/java/pom.js +2 -2
- package/lib/java/projenrc.js +1 -1
- package/lib/javascript/biome/biome.js +1 -1
- package/lib/javascript/bundler.js +1 -1
- package/lib/javascript/eslint.js +1 -1
- package/lib/javascript/jest.js +4 -4
- package/lib/javascript/license-checker.js +1 -1
- package/lib/javascript/node-config-file.js +1 -1
- package/lib/javascript/node-package.js +9 -2
- package/lib/javascript/node-project.js +1 -1
- package/lib/javascript/npm-config.js +1 -1
- package/lib/javascript/pnpm-workspace-config.js +2 -2
- package/lib/javascript/pnpm-workspace.js +1 -1
- package/lib/javascript/prettier.js +1 -1
- package/lib/javascript/projenrc.js +1 -1
- package/lib/javascript/typescript-config.js +2 -2
- package/lib/javascript/upgrade-dependencies.js +2 -2
- package/lib/javascript/yarnrc.js +1 -1
- package/lib/json-patch.js +1 -1
- package/lib/json.js +1 -1
- package/lib/license.js +1 -1
- package/lib/logger.js +1 -1
- package/lib/makefile.js +1 -1
- package/lib/object-file.js +1 -1
- package/lib/project-build.js +1 -1
- package/lib/project-tree.js +1 -1
- package/lib/project.js +1 -1
- package/lib/projects.js +1 -1
- package/lib/projenrc-json.js +1 -1
- package/lib/projenrc.js +1 -1
- package/lib/properties-file.d.ts +50 -0
- package/lib/properties-file.js +77 -0
- package/lib/python/pip.js +1 -1
- package/lib/python/poetry.js +2 -2
- package/lib/python/projenrc.js +1 -1
- package/lib/python/pyproject-toml-file.js +1 -1
- package/lib/python/pytest-sample.js +1 -1
- package/lib/python/pytest.js +1 -1
- package/lib/python/python-project.js +1 -1
- package/lib/python/python-sample.js +1 -1
- package/lib/python/requirements-file.js +1 -1
- package/lib/python/setuppy.js +1 -1
- package/lib/python/setuptools.js +1 -1
- package/lib/python/uv-config.js +1 -1
- package/lib/python/uv.js +1 -1
- package/lib/python/venv.js +1 -1
- package/lib/readme.js +1 -1
- package/lib/release/publisher.js +1 -1
- package/lib/release/release-trigger.js +1 -1
- package/lib/release/release.js +1 -1
- package/lib/renovatebot.js +1 -1
- package/lib/run-task.cjs +7 -5
- package/lib/sample-file.js +2 -2
- package/lib/script-runner.js +1 -1
- package/lib/sonarqube/index.d.ts +4 -0
- package/lib/sonarqube/index.js +21 -0
- package/lib/sonarqube/javascript.d.ts +35 -0
- package/lib/sonarqube/javascript.js +57 -0
- package/lib/sonarqube/rust.d.ts +37 -0
- package/lib/sonarqube/rust.js +58 -0
- package/lib/sonarqube/sonarqube.d.ts +439 -0
- package/lib/sonarqube/sonarqube.js +184 -0
- package/lib/sonarqube/typescript.d.ts +36 -0
- package/lib/sonarqube/typescript.js +61 -0
- package/lib/source-code.js +1 -1
- package/lib/task-shell.js +1 -1
- package/lib/task.js +1 -1
- package/lib/tasks.js +1 -1
- package/lib/testing.js +1 -1
- package/lib/textfile.js +1 -1
- package/lib/toml.js +1 -1
- package/lib/typescript/projenrc-ts.js +1 -1
- package/lib/typescript/projenrc.js +1 -1
- package/lib/typescript/typescript-runner.js +1 -1
- package/lib/typescript/typescript-typedoc.js +1 -1
- package/lib/typescript/typescript.js +5 -5
- package/lib/util.d.ts +9 -0
- package/lib/util.js +39 -1
- package/lib/version.js +2 -2
- package/lib/vscode/devcontainer.js +1 -1
- package/lib/vscode/extensions.js +1 -1
- package/lib/vscode/launch-config.js +1 -1
- package/lib/vscode/settings.js +1 -1
- package/lib/vscode/vscode.js +1 -1
- package/lib/web/next.js +3 -3
- package/lib/web/postcss.js +1 -1
- package/lib/web/react.js +3 -3
- package/lib/web/tailwind.js +1 -1
- package/lib/xmlfile.js +1 -1
- package/lib/yaml.js +1 -1
- package/node_modules/properties-file/LICENSE +21 -0
- package/node_modules/properties-file/README.md +253 -0
- package/node_modules/properties-file/dist/cjs/bundler/bun.d.ts +10 -0
- package/node_modules/properties-file/dist/cjs/bundler/bun.js +1 -0
- package/node_modules/properties-file/dist/cjs/bundler/esbuild.d.ts +11 -0
- package/node_modules/properties-file/dist/cjs/bundler/esbuild.js +1 -0
- package/node_modules/properties-file/dist/cjs/bundler/rollup.d.ts +11 -0
- package/node_modules/properties-file/dist/cjs/bundler/rollup.js +1 -0
- package/node_modules/properties-file/dist/cjs/bundler/webpack.d.ts +12 -0
- package/node_modules/properties-file/dist/cjs/bundler/webpack.js +1 -0
- package/node_modules/properties-file/dist/cjs/characters.d.ts +32 -0
- package/node_modules/properties-file/dist/cjs/characters.js +1 -0
- package/node_modules/properties-file/dist/cjs/editor/index.d.ts +181 -0
- package/node_modules/properties-file/dist/cjs/editor/index.js +1 -0
- package/node_modules/properties-file/dist/cjs/escape/index.d.ts +18 -0
- package/node_modules/properties-file/dist/cjs/escape/index.js +1 -0
- package/node_modules/properties-file/dist/cjs/index.d.ts +25 -0
- package/node_modules/properties-file/dist/cjs/index.js +1 -0
- package/node_modules/properties-file/dist/cjs/package.json +1 -0
- package/node_modules/properties-file/dist/cjs/parser/index.d.ts +3 -0
- package/node_modules/properties-file/dist/cjs/parser/index.js +1 -0
- package/node_modules/properties-file/dist/cjs/parser/nodes.d.ts +154 -0
- package/node_modules/properties-file/dist/cjs/parser/nodes.js +1 -0
- package/node_modules/properties-file/dist/cjs/parser/normalize.d.ts +12 -0
- package/node_modules/properties-file/dist/cjs/parser/normalize.js +1 -0
- package/node_modules/properties-file/dist/cjs/parser/parse.d.ts +23 -0
- package/node_modules/properties-file/dist/cjs/parser/parse.js +1 -0
- package/node_modules/properties-file/dist/cjs/parser/properties.d.ts +93 -0
- package/node_modules/properties-file/dist/cjs/parser/properties.js +1 -0
- package/node_modules/properties-file/dist/cjs/properties-file.d.ts +8 -0
- package/node_modules/properties-file/dist/cjs/unescape/index.d.ts +14 -0
- package/node_modules/properties-file/dist/cjs/unescape/index.js +1 -0
- package/node_modules/properties-file/dist/esm/bundler/bun.d.ts +10 -0
- package/node_modules/properties-file/dist/esm/bundler/bun.js +1 -0
- package/node_modules/properties-file/dist/esm/bundler/esbuild.d.ts +11 -0
- package/node_modules/properties-file/dist/esm/bundler/esbuild.js +1 -0
- package/node_modules/properties-file/dist/esm/bundler/rollup.d.ts +11 -0
- package/node_modules/properties-file/dist/esm/bundler/rollup.js +1 -0
- package/node_modules/properties-file/dist/esm/bundler/webpack.d.ts +12 -0
- package/node_modules/properties-file/dist/esm/bundler/webpack.js +1 -0
- package/node_modules/properties-file/dist/esm/characters.d.ts +32 -0
- package/node_modules/properties-file/dist/esm/characters.js +1 -0
- package/node_modules/properties-file/dist/esm/editor/index.d.ts +181 -0
- package/node_modules/properties-file/dist/esm/editor/index.js +1 -0
- package/node_modules/properties-file/dist/esm/escape/index.d.ts +18 -0
- package/node_modules/properties-file/dist/esm/escape/index.js +1 -0
- package/node_modules/properties-file/dist/esm/index.d.ts +25 -0
- package/node_modules/properties-file/dist/esm/index.js +1 -0
- package/node_modules/properties-file/dist/esm/parser/index.d.ts +3 -0
- package/node_modules/properties-file/dist/esm/parser/index.js +1 -0
- package/node_modules/properties-file/dist/esm/parser/nodes.d.ts +154 -0
- package/node_modules/properties-file/dist/esm/parser/nodes.js +1 -0
- package/node_modules/properties-file/dist/esm/parser/normalize.d.ts +12 -0
- package/node_modules/properties-file/dist/esm/parser/normalize.js +1 -0
- package/node_modules/properties-file/dist/esm/parser/parse.d.ts +23 -0
- package/node_modules/properties-file/dist/esm/parser/parse.js +1 -0
- package/node_modules/properties-file/dist/esm/parser/properties.d.ts +93 -0
- package/node_modules/properties-file/dist/esm/parser/properties.js +1 -0
- package/node_modules/properties-file/dist/esm/properties-file.d.ts +8 -0
- package/node_modules/properties-file/dist/esm/unescape/index.d.ts +14 -0
- package/node_modules/properties-file/dist/esm/unescape/index.js +1 -0
- package/node_modules/properties-file/package.json +190 -0
- package/package.json +7 -5
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Properties } from '../parser/properties.js';
|
|
2
|
+
import type { PropertyNode } from '../parser/nodes.js';
|
|
3
|
+
/** Characters that can be used as key-value pair separators. */
|
|
4
|
+
export type KeyValuePairSeparator = '=' | ':' | ' ';
|
|
5
|
+
/** Characters that can be used as comment delimiters. */
|
|
6
|
+
export type CommentDelimiter = '#' | '!';
|
|
7
|
+
/** Options for {@link PropertiesEditor.insert}. */
|
|
8
|
+
export type InsertOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* Insert relative to this key (last occurrence). If the key is not found,
|
|
11
|
+
* the property is appended at the end.
|
|
12
|
+
*/
|
|
13
|
+
referenceKey?: string;
|
|
14
|
+
/** Position relative to the reference key. Default: `'after'`. */
|
|
15
|
+
position?: 'before' | 'after';
|
|
16
|
+
/** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
|
|
17
|
+
escapeUnicode?: boolean;
|
|
18
|
+
/** Separator character to use between key and value. Default: `'='`. */
|
|
19
|
+
separator?: KeyValuePairSeparator;
|
|
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
|
+
*/
|
|
25
|
+
comment?: string;
|
|
26
|
+
/** Delimiter character for the comment. Default: `'#'`. */
|
|
27
|
+
commentDelimiter?: CommentDelimiter;
|
|
28
|
+
};
|
|
29
|
+
/** Options for {@link PropertiesEditor.insertComment}. */
|
|
30
|
+
export type InsertCommentOptions = {
|
|
31
|
+
/**
|
|
32
|
+
* Insert relative to this key (last occurrence). If the key is not found,
|
|
33
|
+
* the comment is appended at the end.
|
|
34
|
+
*/
|
|
35
|
+
referenceKey?: string;
|
|
36
|
+
/** Position relative to the reference key. Default: `'after'`. */
|
|
37
|
+
position?: 'before' | 'after';
|
|
38
|
+
/** Delimiter character for the comment. Default: `'#'`. */
|
|
39
|
+
commentDelimiter?: CommentDelimiter;
|
|
40
|
+
};
|
|
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}. */
|
|
52
|
+
export type UpdateOptions = {
|
|
53
|
+
/** Replacement value. When not set, the original value is preserved. */
|
|
54
|
+
newValue?: string;
|
|
55
|
+
/** Replacement key (rename). When not set, the original key is preserved. */
|
|
56
|
+
newKey?: string;
|
|
57
|
+
/** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
|
|
58
|
+
escapeUnicode?: boolean;
|
|
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
|
+
*/
|
|
66
|
+
newComment?: string;
|
|
67
|
+
/** Delimiter character for the new comment. Default: `'#'`. */
|
|
68
|
+
commentDelimiter?: CommentDelimiter;
|
|
69
|
+
};
|
|
70
|
+
/** Options for {@link PropertiesEditor.upsert}. */
|
|
71
|
+
export type UpsertOptions = {
|
|
72
|
+
/** If `true`, escape non-ASCII characters as `\\uXXXX` sequences. Default: `false`. */
|
|
73
|
+
escapeUnicode?: boolean;
|
|
74
|
+
/** Separator character. Default: `'='`. */
|
|
75
|
+
separator?: KeyValuePairSeparator;
|
|
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
|
+
*/
|
|
80
|
+
comment?: string;
|
|
81
|
+
/** Delimiter character for the comment. Default: `'#'`. */
|
|
82
|
+
commentDelimiter?: CommentDelimiter;
|
|
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
|
+
/**
|
|
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';
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* An editor for `.properties` files that extends the lossless {@link Properties}
|
|
103
|
+
* parser with insert, update, delete, and upsert operations.
|
|
104
|
+
*/
|
|
105
|
+
export declare class PropertiesEditor extends Properties {
|
|
106
|
+
/**
|
|
107
|
+
* Find the first property node with the given key.
|
|
108
|
+
*
|
|
109
|
+
* @param key - The unescaped key to search for.
|
|
110
|
+
*
|
|
111
|
+
* @returns The matching node and its index in `this.nodes`, or `undefined`.
|
|
112
|
+
*/
|
|
113
|
+
private findFirstProperty;
|
|
114
|
+
/**
|
|
115
|
+
* Find the last property node with the given key.
|
|
116
|
+
*
|
|
117
|
+
* @param key - The unescaped key to search for.
|
|
118
|
+
*
|
|
119
|
+
* @returns The matching node and its index in `this.nodes`, or `undefined`.
|
|
120
|
+
*/
|
|
121
|
+
private findLastProperty;
|
|
122
|
+
/**
|
|
123
|
+
* Insert a new property.
|
|
124
|
+
*
|
|
125
|
+
* @param key - The unescaped key.
|
|
126
|
+
* @param value - The unescaped value.
|
|
127
|
+
* @param options - Insert options.
|
|
128
|
+
*/
|
|
129
|
+
insert(key: string, value: string, options?: InsertOptions): void;
|
|
130
|
+
/**
|
|
131
|
+
* Insert a comment.
|
|
132
|
+
*
|
|
133
|
+
* @param comment - The comment text (may contain newlines).
|
|
134
|
+
* @param options - Insert comment options.
|
|
135
|
+
*/
|
|
136
|
+
insertComment(comment: string, options?: InsertCommentOptions): void;
|
|
137
|
+
/**
|
|
138
|
+
* Insert a blank line.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Insert blank line options.
|
|
141
|
+
*/
|
|
142
|
+
insertBlankLine(options?: InsertBlankLineOptions): void;
|
|
143
|
+
/**
|
|
144
|
+
* Update an existing property.
|
|
145
|
+
*
|
|
146
|
+
* @param key - The unescaped key to update (uses last occurrence).
|
|
147
|
+
* @param options - Update options.
|
|
148
|
+
*
|
|
149
|
+
* @returns `true` if the property was found and updated, `false` otherwise.
|
|
150
|
+
*/
|
|
151
|
+
update(key: string, options: UpdateOptions): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Update a property if it exists, or insert it if it doesn't.
|
|
154
|
+
*
|
|
155
|
+
* @param key - The unescaped key.
|
|
156
|
+
* @param value - The unescaped value.
|
|
157
|
+
* @param options - Upsert options.
|
|
158
|
+
*/
|
|
159
|
+
upsert(key: string, value: string, options?: UpsertOptions): void;
|
|
160
|
+
/**
|
|
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.
|
|
166
|
+
*
|
|
167
|
+
* @param key - The unescaped key to delete.
|
|
168
|
+
* @param options - Delete options.
|
|
169
|
+
*
|
|
170
|
+
* @returns The deleted {@link PropertyNode}, or `undefined` if the key was not found.
|
|
171
|
+
*/
|
|
172
|
+
delete(key: string, options?: DeleteOptions): PropertyNode | undefined;
|
|
173
|
+
/**
|
|
174
|
+
* Delete all occurrences of a key.
|
|
175
|
+
*
|
|
176
|
+
* @param key - The unescaped key to delete.
|
|
177
|
+
*
|
|
178
|
+
* @returns An array of the deleted {@link PropertyNode} instances.
|
|
179
|
+
*/
|
|
180
|
+
deleteAll(key: string): PropertyNode[];
|
|
181
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
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 _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})()}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}}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?" ":"",p=l?"".concat(" ").concat(l).concat(c):" ",u="".concat(i).concat(p).concat(s).split(REGEX_NEWLINE);return{type:"property",rawLines:u,leadingWhitespace:"",key:e,escapedKey:i,separatorLeading:" ",separatorChar:l,separatorTrailing:c,value:r,escapedValue:s,startingLineNumber:n,endingLineNumber:n+u.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){for(var r=1,t=0;t<e.length;t++){var n=e[t];if("property"===n.type){var o=n.rawLines.length;e[t]={type:"property",rawLines:n.rawLines,leadingWhitespace:n.leadingWhitespace,key:n.key,escapedKey:n.escapedKey,separatorLeading:n.separatorLeading,separatorChar:n.separatorChar,separatorTrailing:n.separatorTrailing,value:n.value,escapedValue:n.escapedValue,startingLineNumber:r,endingLineNumber:r+o-1},r+=o}else"comment"===n.type?(e[t]={type:"comment",rawLine:n.rawLine,leadingWhitespace:n.leadingWhitespace,delimiter:n.delimiter,body:n.body,lineNumber:r},r++):(e[t]={type:"blank",rawLine:n.rawLine,lineNumber:r},r++)}};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:"findFirstProperty",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{index:r,node:t}}}},{key:"findLastProperty",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{index:r,node:t}}}},{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.findLastProperty(t.referenceKey);if(void 0!==l){var c,p="before"===t.position?l.index:l.index+1;return(c=this.nodes).splice.apply(c,[p,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.findLastProperty(r.referenceKey);if(void 0!==i){var s,l="before"===r.position?i.index:i.index+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.findLastProperty(e.referenceKey);if(void 0!==t){var n="before"===e.position?t.index:t.index+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.findLastProperty(e);if(void 0===a)return!1;var i=a.index,s=a.node,l=null!==(t=r.newKey)&&void 0!==t?t:s.key,c=null!==(n=r.newValue)&&void 0!==n?n:s.value,p=!0===r.escapeUnicode,u=p?escapeKey(l,!0):void 0!==r.newKey?escapeKey(l):s.escapedKey,d=p?escapeValue(c,!0):void 0!==r.newValue?escapeValue(c):s.escapedValue,_=r.separator?" "===r.separator?void 0:r.separator:s.separatorChar,y=r.separator?" ":s.separatorLeading,f=r.separator?_?" ":"":s.separatorTrailing,m=_?"".concat(y).concat(_).concat(f):y,v="".concat(u).concat(m).concat(d).split(REGEX_NEWLINE),h={type:"property",rawLines:v,leadingWhitespace:s.leadingWhitespace,key:l,escapedKey:u,separatorLeading:y,separatorChar:_,separatorTrailing:f,value:c,escapedValue:d,startingLineNumber:s.startingLineNumber,endingLineNumber:s.startingLineNumber+v.length-1};if(void 0!==r.newComment){for(var b,L=i,g=i-1;g>=0&&"property"!==this.nodes[g].type;g--)L=g;var N=null!==(o=r.commentDelimiter)&&void 0!==o?o:DEFAULT_COMMENT_DELIMITER,E=buildCommentNodes(r.newComment,N,0);(b=this.nodes).splice.apply(b,[L,i-L+1].concat(_to_consumable_array(E),[h]))}else this.nodes[i]=h;return recalculateLineNumbers(this.nodes),!0}},{key:"upsert",value:function(e,r,t){void 0!==this.findLastProperty(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.findFirstProperty(e):this.findLastProperty(e);if(void 0!==t){var n=t.index,o=t.node;if(!1!==(null==r?void 0:r.deleteLeadingNodes)){for(var a=n,i=n-1;i>=0&&"property"!==this.nodes[i].type;i--)a=i;this.nodes.splice(a,n-a+1)}else this.nodes.splice(n,1);return recalculateLineNumbers(this.nodes),o}}},{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);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape a property key.
|
|
3
|
+
*
|
|
4
|
+
* @param unescapedKey - A property key to be escaped.
|
|
5
|
+
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
6
|
+
*
|
|
7
|
+
* @returns The escaped key.
|
|
8
|
+
*/
|
|
9
|
+
export declare const escapeKey: (unescapedKey: string, escapeUnicode?: boolean) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Escape property value.
|
|
12
|
+
*
|
|
13
|
+
* @param unescapedValue - Property value to be escaped.
|
|
14
|
+
* @param escapeUnicode - Escape unicode characters into ISO-8859-1 compatible encoding?
|
|
15
|
+
*
|
|
16
|
+
* @returns The escaped value.
|
|
17
|
+
*/
|
|
18
|
+
export declare const escapeValue: (unescapedValue: string, escapeUnicode?: boolean) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export var escapeKey=function(e){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,t,r){var n=r?REGEX_ESCAPE_UNICODE:REGEX_ESCAPE_NO_UNICODE;return n.lastIndex=0,e.replace(n,function(e,r){switch(e){case" ":return t||0===r?"\\ ":" ";case"\\":return"\\\\";case"\f":return"\\f";case"\n":return"\\n";case"\r":return"\\r";case"\t":return"\\t";case"=":case":":case"#":case"!":return"\\".concat(e);default:return"\\u"+("0000"+e.charCodeAt(0).toString(16)).slice(-4)}})};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A key-value pair object.
|
|
3
|
+
*/
|
|
4
|
+
export type KeyValuePairObject = Record<string, string>;
|
|
5
|
+
/**
|
|
6
|
+
* Converts the content of a `.properties` file to a key-value pair object.
|
|
7
|
+
*
|
|
8
|
+
* This is a self-contained, zero-dependency parser optimized for minimal
|
|
9
|
+
* bundle size. It implements the Java `java.util.Properties` specification:
|
|
10
|
+
*
|
|
11
|
+
* - BOM detection and skipping
|
|
12
|
+
* - Comment lines (`#` or `!`)
|
|
13
|
+
* - Line continuations (trailing odd backslash)
|
|
14
|
+
* - Key-value separator detection (`=`, `:`, or whitespace)
|
|
15
|
+
* - Escape sequence processing (`\\n`, `\\t`, `\\r`, `\\f`, `\\\\`, `\\uXXXX`)
|
|
16
|
+
* - Last-value-wins semantics for duplicate keys
|
|
17
|
+
*
|
|
18
|
+
* @param content - The content of a `.properties` file.
|
|
19
|
+
*
|
|
20
|
+
* @returns A key/value object representing the content of a `.properties` file.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getProperties: (content: string | Buffer) => KeyValuePairObject;
|
|
23
|
+
|
|
24
|
+
// Enables type recognition for direct `.properties` file imports.
|
|
25
|
+
import './properties-file.d.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _=function(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:-1},S=function(e){if(-1===e.indexOf("\\"))return e;for(var r=e.length,a="",c=0,t=0;t<r;)if(92===e.charCodeAt(t)){if(t>c&&(a+=e.slice(c,t)),++t>=r){a+="\\",c=t;break}switch(e.charCodeAt(t)){case 110:a+="\n",t++;break;case 116:a+="\t",t++;break;case 114:a+="\r",t++;break;case 102:a+="\f",t++;break;case 117:if(t+4>=r)throw new Error("malformed escaped unicode characters '".concat(e.slice(t-1,t+5),"'"));var o=_(e.charCodeAt(t+1)),i=_(e.charCodeAt(t+2)),n=_(e.charCodeAt(t+3)),f=_(e.charCodeAt(t+4));if(o<0||i<0||n<0||f<0)throw new Error("malformed escaped unicode characters '".concat(e.slice(t-1,t+5),"'"));a+=String.fromCharCode(o<<12|i<<8|n<<4|f),t+=5;break;default:a+=e.charAt(t),t++}c=t}else t++;return c<r&&(a+=e.slice(c,r)),a},H=function(e,r,a){for(;r<a;){var c=e.charCodeAt(r);if(32!==c&&9!==c&&12!==c)break;r++}return r},q=function(e){for(var r="string"==typeof e?e:e.toString(),a={},c=(r.length>0&&65279===r.charCodeAt(0)?r.slice(1):r).split(/\r\n|\r|\n/),t=c.length,o=0;o<t;){var i=c[o],n=i.length,f=H(i,0,n);if(f>=n)o++;else{var s=i.charCodeAt(f);if(35!==s&&33!==s){for(var d=0,h=n-1;h>=0&&92===i.charCodeAt(h);h--)d++;var l=d%2==1,v=void 0,C=void 0;if(l){var A=(f>0?i.slice(f):i).slice(0,-1),u=[A];for(C=-1!==A.indexOf("\\");l&&o+1<t;){var g=c[++o],b=g.length,k=H(g,0,b);d=0;for(var p=b-1;p>=k&&92===g.charCodeAt(p);p--)d++;var m=(l=d%2==1)?g.slice(k,b-1):g.slice(k);!C&&-1!==m.indexOf("\\")&&(C=!0),u.push(m)}v=u.join("")}else C=-1!==(v=f>0?i.slice(f):i).indexOf("\\");for(var w=v.length,x=0,_=!1;x<w;){var O=v.charCodeAt(x);if(92!==O){if(!_&&(61===O||58===O||32===O||9===O||12===O))break;_=!1,x++}else _=!_,x++}var q=x;if(q<w){var E=v.charCodeAt(q);(32===E||9===E||12===E)&&((q=H(v,q,w))<w&&(E=v.charCodeAt(q))),q<w&&(61===E||58===E)&&(q++,q=H(v,q,w))}var j=v.slice(0,x),y=v.slice(q);a[C?S(j):j]=C?S(y):y,o++}else o++}}return a};export{q as getProperties};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{Properties}from"./properties.js";export{PropertiesNodeType}from"./nodes.js";
|
|
@@ -0,0 +1,154 @@
|
|
|
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 = Record<string, string>;
|
|
78
|
+
/** Information about a key that appears more than once. */
|
|
79
|
+
export type KeyCollisions = {
|
|
80
|
+
/** The duplicate key. */
|
|
81
|
+
key: string;
|
|
82
|
+
/** All property nodes with this key, in file order. */
|
|
83
|
+
nodes: PropertyNode[];
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Options for {@link Properties.format} when producing normalized output.
|
|
87
|
+
*
|
|
88
|
+
* When no options are passed to `format()`, the output is a lossless reconstruction
|
|
89
|
+
* of the original content. Passing any option triggers normalization, rebuilding
|
|
90
|
+
* property lines from their parsed fields.
|
|
91
|
+
*/
|
|
92
|
+
export type NormalizeOptions = {
|
|
93
|
+
/** Override the end-of-line character. Defaults to the EOL detected from the source. */
|
|
94
|
+
endOfLineCharacter?: '\n' | '\r\n';
|
|
95
|
+
/** If `true`, remove all comment lines from the output. Default: `false`. */
|
|
96
|
+
removeComments?: boolean;
|
|
97
|
+
/** If `true`, remove all blank lines from the output. Default: `false`. */
|
|
98
|
+
removeBlankLines?: boolean;
|
|
99
|
+
/** If `true`, strip leading whitespace from all property and comment lines. Default: `false`. */
|
|
100
|
+
removeLeadingWhitespace?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* If `true`, keep only the last occurrence of each duplicate key (Java's last-wins
|
|
103
|
+
* semantics). Earlier occurrences and their leading comment/blank line nodes are
|
|
104
|
+
* removed from the output. Set `deduplicateKeysKeepLeadingNodes` to `true` to
|
|
105
|
+
* preserve the leading nodes. Default: `false`.
|
|
106
|
+
*/
|
|
107
|
+
deduplicateKeys?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* When `deduplicateKeys` is `true`, controls whether comment and blank line nodes
|
|
110
|
+
* preceding removed duplicates are preserved (`true`) or also removed (`false`).
|
|
111
|
+
* Default: `false` (leading nodes are removed along with the duplicate).
|
|
112
|
+
*/
|
|
113
|
+
deduplicateKeysKeepLeadingNodes?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Standardize the separator character across all properties. When set, every
|
|
116
|
+
* property is rewritten to use this separator. Original separators are preserved
|
|
117
|
+
* if not set. Use `' '` for whitespace-only separators (no `=` or `:`).
|
|
118
|
+
*/
|
|
119
|
+
separatorChar?: '=' | ':' | ' ';
|
|
120
|
+
/**
|
|
121
|
+
* Whitespace to place before the separator character (e.g. `' '` for `key = value`,
|
|
122
|
+
* `''` for `key=value`). When not set, each property's original leading whitespace
|
|
123
|
+
* is preserved.
|
|
124
|
+
*/
|
|
125
|
+
separatorLeading?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Whitespace to place after the separator character (e.g. `' '` for `key = value`,
|
|
128
|
+
* `''` for `key=value`). When not set, each property's original trailing whitespace
|
|
129
|
+
* is preserved.
|
|
130
|
+
*/
|
|
131
|
+
separatorTrailing?: string;
|
|
132
|
+
/**
|
|
133
|
+
* If `true`, re-escape all non-ASCII characters as `\\uXXXX` sequences. Useful for
|
|
134
|
+
* producing ISO-8859-1 compatible output. Default: `false` (preserves original encoding).
|
|
135
|
+
*/
|
|
136
|
+
escapeUnicode?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* If `true`, collapse multiline keys and values (joined via `\\` line continuations)
|
|
139
|
+
* into single lines. Default: `false` (preserves original line structure).
|
|
140
|
+
*/
|
|
141
|
+
collapseMultiline?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Wrap keys at this character width using `\\` line continuations. Only applies to
|
|
144
|
+
* keys longer than the specified width. `\\uXXXX` sequences are never split across
|
|
145
|
+
* lines. `undefined` = no wrapping.
|
|
146
|
+
*/
|
|
147
|
+
wrapKeysAt?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Wrap values at this character width using `\\` line continuations. Only applies to
|
|
150
|
+
* values longer than the specified width. `\\uXXXX` sequences are never split across
|
|
151
|
+
* lines. `undefined` = no wrapping.
|
|
152
|
+
*/
|
|
153
|
+
wrapValuesAt?: number;
|
|
154
|
+
};
|
|
@@ -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,p=!0===a.escapeUnicode,s=a.removeLeadingWhitespace?"":e.leadingWhitespace,c=p?escapeKey(e.key,!0):e.escapedKey,d=null!==(r=a.separatorLeading)&&void 0!==r?r:e.separatorLeading,l=null!==(i=a.separatorTrailing)&&void 0!==i?i:e.separatorTrailing;void 0!==a.separatorChar?(n=" "===a.separatorChar?"":a.separatorChar," "===a.separatorChar&&(d=null!==(t=a.separatorLeading)&&void 0!==t?t:" ")):n=null!==(o=e.separatorChar)&&void 0!==o?o:"";var u=p?escapeValue(e.value,!0):e.escapedValue;return void 0!==a.wrapKeysAt&&a.wrapKeysAt>0&&(c=wrapAtWidth(c,a.wrapKeysAt)),void 0!==a.wrapValuesAt&&a.wrapValuesAt>0&&(u=wrapAtWidth(u,a.wrapValuesAt)),"".concat(s).concat(c).concat(d).concat(n).concat(l).concat(u)};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={},c=[],d=e.length-1;d>=0;d--){var l=e[d];"property"===l.type&&(s[l.key]?c.push(d):s[l.key]=!0)}o={};for(var u=0;u<c.length;u++){var v=c[u];if(o[v]=!0,!i.deduplicateKeysKeepLeadingNodes)for(var h=v-1;h>=0&&"property"!==e[h].type;h--)o[h]=!0}}for(var f=[],y=0;y<e.length;y++)if(!(null==o?void 0:o[y])){var g=e[y];switch(g.type){case"comment":if(i.removeComments)continue;f.push(i.removeLeadingWhitespace?"".concat(g.delimiter).concat(g.body):g.rawLine);break;case"blank":if(i.removeBlankLines)continue;f.push(g.rawLine);break;case"property":p?f.push(rebuildPropertyLine(g,i)):f.push(g.rawLines.join(n))}}return(a?BOM:"")+f.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{CH_BACKSLASH,CH_BANG,CH_BOM,CH_COLON,CH_CR,CH_EQUALS,CH_FF,CH_HASH,CH_LF,CH_SPACE,CH_TAB}from"../characters.js";import{unescapeContent}from"../unescape/index.js";var 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 t="\n",n=i;n<a;n++){var C=r.charCodeAt(n);if(C===CH_CR){t=n+1<a&&r.charCodeAt(n+1)===CH_LF?"\r\n":"\r";break}if(C===CH_LF){t="\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 m=c[++l];d.push(m);var B=m.length;S=(L=countTrailingBackslashes(m,B))%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 j=N.charCodeAt(Q);if(j!==CH_BACKSLASH){if(!U&&(j===CH_EQUALS||j===CH_COLON||isWhitespace(j)))break;U=!1,Q++}else U=!U,Q++}var w=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!==w.indexOf("\\")?unescapeContent(w):w,escapedKey:w,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:t,nodes:o}};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { BlankLineNode, CommentNode, KeyCollisions, KeyValuePairObject, NormalizeOptions, PropertiesNode, PropertyNode } from './nodes.js';
|
|
2
|
+
/**
|
|
3
|
+
* A lossless, ordered representation of a `.properties` file.
|
|
4
|
+
*
|
|
5
|
+
* Every element in the file — properties, comments, and blank lines — is
|
|
6
|
+
* preserved in order. Duplicate keys are all retained. The original content
|
|
7
|
+
* can be reconstructed exactly via {@link format}.
|
|
8
|
+
*/
|
|
9
|
+
export declare class Properties {
|
|
10
|
+
/** Whether the content started with a BOM character. */
|
|
11
|
+
readonly hasBom: boolean;
|
|
12
|
+
/** The end-of-line character detected from the content. */
|
|
13
|
+
readonly eolCharacter: string;
|
|
14
|
+
/** All nodes in file order. */
|
|
15
|
+
readonly nodes: PropertiesNode[];
|
|
16
|
+
/**
|
|
17
|
+
* Parse a `.properties` file into a lossless node structure.
|
|
18
|
+
*
|
|
19
|
+
* @param content - The content of a `.properties` file (string or Buffer).
|
|
20
|
+
*/
|
|
21
|
+
constructor(content: string | Buffer);
|
|
22
|
+
/**
|
|
23
|
+
* Get all property nodes in file order (including duplicates).
|
|
24
|
+
*
|
|
25
|
+
* @returns An array of all {@link PropertyNode} instances.
|
|
26
|
+
*/
|
|
27
|
+
getProperties(): PropertyNode[];
|
|
28
|
+
/**
|
|
29
|
+
* Get all comment nodes in file order.
|
|
30
|
+
*
|
|
31
|
+
* @returns An array of all {@link CommentNode} instances.
|
|
32
|
+
*/
|
|
33
|
+
getComments(): CommentNode[];
|
|
34
|
+
/**
|
|
35
|
+
* Get all blank line nodes in file order.
|
|
36
|
+
*
|
|
37
|
+
* @returns An array of all {@link BlankLineNode} instances.
|
|
38
|
+
*/
|
|
39
|
+
getBlankLines(): BlankLineNode[];
|
|
40
|
+
/**
|
|
41
|
+
* Get the effective key-value map (last-wins semantics for duplicate keys).
|
|
42
|
+
*
|
|
43
|
+
* @returns A plain object where each key maps to its last-occurring value.
|
|
44
|
+
*/
|
|
45
|
+
toObject(): KeyValuePairObject;
|
|
46
|
+
/**
|
|
47
|
+
* Get all property nodes for a given key (all occurrences, in file order).
|
|
48
|
+
*
|
|
49
|
+
* @param key - The unescaped key to search for.
|
|
50
|
+
*
|
|
51
|
+
* @returns An array of matching {@link PropertyNode} instances (empty if not found).
|
|
52
|
+
*/
|
|
53
|
+
getPropertyNodes(key: string): PropertyNode[];
|
|
54
|
+
/**
|
|
55
|
+
* Get the effective property node for a given key (last occurrence).
|
|
56
|
+
*
|
|
57
|
+
* @param key - The unescaped key to search for.
|
|
58
|
+
*
|
|
59
|
+
* @returns The last {@link PropertyNode} with this key, or `undefined`.
|
|
60
|
+
*/
|
|
61
|
+
getEffectiveProperty(key: string): PropertyNode | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* Get keys that appear more than once, with all their property nodes.
|
|
64
|
+
*
|
|
65
|
+
* @returns An array of {@link KeyCollisions} for duplicate keys.
|
|
66
|
+
*/
|
|
67
|
+
getKeyCollisions(): KeyCollisions[];
|
|
68
|
+
/**
|
|
69
|
+
* Get comment and blank line nodes immediately preceding a property.
|
|
70
|
+
*
|
|
71
|
+
* Walks backward from the last occurrence of the given key, collecting
|
|
72
|
+
* comment and blank line nodes until reaching another property or the
|
|
73
|
+
* start of the file.
|
|
74
|
+
*
|
|
75
|
+
* @param key - The unescaped key to find leading nodes for.
|
|
76
|
+
*
|
|
77
|
+
* @returns An array of preceding {@link CommentNode} and {@link BlankLineNode} instances.
|
|
78
|
+
*/
|
|
79
|
+
getLeadingNodes(key: string): (CommentNode | BlankLineNode)[];
|
|
80
|
+
/**
|
|
81
|
+
* Format the `.properties` content as a string.
|
|
82
|
+
*
|
|
83
|
+
* Without options, produces an exact lossless reconstruction of the original
|
|
84
|
+
* content. With options, produces normalized output — standardize separators,
|
|
85
|
+
* remove comments, deduplicate keys, and more.
|
|
86
|
+
*
|
|
87
|
+
* @param options - Optional normalization options. When omitted, the output
|
|
88
|
+
* is a lossless round-trip of the original content.
|
|
89
|
+
*
|
|
90
|
+
* @returns The formatted `.properties` file content.
|
|
91
|
+
*/
|
|
92
|
+
format(options?: NormalizeOptions): string;
|
|
93
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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}import{formatNormalized as formatNormalizedImpl}from"./normalize.js";import{parseDocument}from"./parse.js";var BOM="\ufeff";export var Properties=function(){"use strict";function e(r){_class_call_check(this,e);var t=parseDocument(r);this.hasBom=t.hasBom,this.eolCharacter=t.eolCharacter,this.nodes=t.nodes}return _create_class(e,[{key:"getProperties",value:function(){return this.nodes.filter(function(e){return"property"===e.type})}},{key:"getComments",value:function(){return this.nodes.filter(function(e){return"comment"===e.type})}},{key:"getBlankLines",value:function(){return this.nodes.filter(function(e){return"blank"===e.type})}},{key:"toObject",value:function(){for(var e={},r=0,t=this.nodes;r<t.length;r++){var n=t[r];"property"===n.type&&(e[n.key]=n.value)}return e}},{key:"getPropertyNodes",value:function(e){return this.nodes.filter(function(r){return"property"===r.type&&r.key===e})}},{key:"getEffectiveProperty",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 t}}},{key:"getKeyCollisions",value:function(){for(var e={},r=0,t=this.nodes;r<t.length;r++){var n=t[r];if("property"===n.type){var o=e[n.key];void 0===o?e[n.key]=[n]:o.push(n)}}for(var i=[],a=0,s=Object.keys(e);a<s.length;a++){var u=s[a],f=e[u];void 0!==f&&f.length>1&&i.push({key:u,nodes:f})}return i}},{key:"getLeadingNodes",value:function(e){for(var r=-1,t=this.nodes.length-1;t>=0;t--){var n=this.nodes[t];if("property"===n.type&&n.key===e){r=t;break}}if(r<=0)return[];for(var o=[],i=r-1;i>=0;i--){var a=this.nodes[i];if("property"===a.type)break;o.unshift(a)}return o}},{key:"format",value:function(e){if(!e){for(var r=this.eolCharacter,t=[],n=0,o=this.nodes;n<o.length;n++){var i=o[n];"property"===i.type?t.push(i.rawLines.join(r)):t.push(i.rawLine)}return(this.hasBom?BOM:"")+t.join(r)}return formatNormalizedImpl(this.nodes,this.hasBom,this.eolCharacter,e)}}]),e}();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tries to unescape the content from either key or value of a property.
|
|
3
|
+
*
|
|
4
|
+
* Uses a single-pass, segment-based approach with `charCodeAt()` instead of
|
|
5
|
+
* regex. Scans for backslashes, flushes literal text in bulk via `slice()`,
|
|
6
|
+
* and only builds new characters for actual escape sequences.
|
|
7
|
+
*
|
|
8
|
+
* @param content - The content to unescape.
|
|
9
|
+
*
|
|
10
|
+
* @returns The unescaped content.
|
|
11
|
+
*
|
|
12
|
+
* @throws Error if malformed escaped unicode characters are present.
|
|
13
|
+
*/
|
|
14
|
+
export declare const unescapeContent: (content: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{CH_BACKSLASH,CH_LOWER_F,CH_LOWER_N,CH_LOWER_R,CH_LOWER_T,CH_LOWER_U}from"../characters.js";var hexValue=function(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:-1};export var unescapeContent=function(e){if(-1===e.indexOf("\\"))return e;for(var r=e.length,a="",c=0,t=0;t<r;)if(e.charCodeAt(t)===CH_BACKSLASH){if(t>c&&(a+=e.slice(c,t)),++t>=r){a+="\\",c=t;break}switch(e.charCodeAt(t)){case CH_LOWER_N:a+="\n",t++;break;case CH_LOWER_T:a+="\t",t++;break;case CH_LOWER_R:a+="\r",t++;break;case CH_LOWER_F:a+="\f",t++;break;case CH_LOWER_U:if(t+4>=r)throw new Error("malformed escaped unicode characters '".concat(e.slice(t-1,t+5),"'"));var o=hexValue(e.charCodeAt(t+1)),C=hexValue(e.charCodeAt(t+2)),_=hexValue(e.charCodeAt(t+3)),h=hexValue(e.charCodeAt(t+4));if(o<0||C<0||_<0||h<0)throw new Error("malformed escaped unicode characters '".concat(e.slice(t-1,t+5),"'"));a+=String.fromCharCode(o<<12|C<<8|_<<4|h),t+=5;break;default:a+=e.charAt(t),t++}c=t}else t++;return c<r&&(a+=e.slice(c,r)),a};
|