@goast/core 0.3.8 → 0.4.0-beta1
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 -0
- package/README.md +2 -4
- package/esm/_dnt.shims.d.ts +11 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +66 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/lib/ast/index.d.ts +2 -0
- package/esm/lib/ast/index.d.ts.map +1 -0
- package/{types → esm}/lib/ast/node.d.ts +2 -1
- package/esm/lib/ast/node.d.ts.map +1 -0
- package/esm/lib/ast/node.js +6 -0
- package/{types → esm}/lib/codegen/config.d.ts +3 -2
- package/esm/lib/codegen/config.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/endpoints-generator.d.ts +4 -3
- package/esm/lib/codegen/endpoints-generator.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/generator.d.ts +8 -8
- package/esm/lib/codegen/generator.d.ts.map +1 -0
- package/esm/lib/codegen/generator.js +20 -6
- package/esm/lib/codegen/index.d.ts +7 -0
- package/esm/lib/codegen/index.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/internal-utils.d.ts +1 -0
- package/esm/lib/codegen/internal-utils.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/schemas-generator.d.ts +4 -3
- package/esm/lib/codegen/schemas-generator.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/services-generator.d.ts +4 -3
- package/esm/lib/codegen/services-generator.d.ts.map +1 -0
- package/{types → esm}/lib/codegen/types.d.ts +3 -2
- package/esm/lib/codegen/types.d.ts.map +1 -0
- package/esm/lib/collect/collector.d.ts +4 -0
- package/esm/lib/collect/collector.d.ts.map +1 -0
- package/{types → esm}/lib/collect/helpers.d.ts +3 -2
- package/esm/lib/collect/helpers.d.ts.map +1 -0
- package/esm/lib/collect/index.d.ts +4 -0
- package/esm/lib/collect/index.d.ts.map +1 -0
- package/{types → esm}/lib/collect/types.d.ts +2 -1
- package/esm/lib/collect/types.d.ts.map +1 -0
- package/{types → esm}/lib/internal-utils.d.ts +1 -0
- package/esm/lib/internal-utils.d.ts.map +1 -0
- package/esm/lib/parse/deref-proxy.d.ts +4 -0
- package/esm/lib/parse/deref-proxy.d.ts.map +1 -0
- package/esm/lib/parse/deref-proxy.js +18 -3
- package/esm/lib/parse/index.d.ts +4 -0
- package/esm/lib/parse/index.d.ts.map +1 -0
- package/{types → esm}/lib/parse/openapi-types.d.ts +1 -0
- package/esm/lib/parse/openapi-types.d.ts.map +1 -0
- package/{types → esm}/lib/parse/parser.d.ts +4 -3
- package/esm/lib/parse/parser.d.ts.map +1 -0
- package/esm/lib/parse/parser.js +17 -6
- package/{types → esm}/lib/parse/types.d.ts +3 -2
- package/esm/lib/parse/types.d.ts.map +1 -0
- package/{types → esm}/lib/transform/api-types.d.ts +3 -2
- package/esm/lib/transform/api-types.d.ts.map +1 -0
- package/{types → esm}/lib/transform/helpers.d.ts +4 -3
- package/esm/lib/transform/helpers.d.ts.map +1 -0
- package/esm/lib/transform/helpers.js +9 -3
- package/esm/lib/transform/index.d.ts +3 -0
- package/esm/lib/transform/index.d.ts.map +1 -0
- package/esm/lib/transform/transform-document.d.ts +4 -0
- package/esm/lib/transform/transform-document.d.ts.map +1 -0
- package/esm/lib/transform/transform-endpoint.d.ts +5 -0
- package/esm/lib/transform/transform-endpoint.d.ts.map +1 -0
- package/esm/lib/transform/transform-schema.d.ts +5 -0
- package/esm/lib/transform/transform-schema.d.ts.map +1 -0
- package/esm/lib/transform/transform-schema.js +3 -1
- package/esm/lib/transform/transformer.d.ts +5 -0
- package/esm/lib/transform/transformer.d.ts.map +1 -0
- package/esm/lib/transform/transformer.js +1 -1
- package/{types → esm}/lib/transform/types.d.ts +5 -4
- package/esm/lib/transform/types.d.ts.map +1 -0
- package/{types → esm}/lib/utils/action-provider.d.ts +2 -1
- package/esm/lib/utils/action-provider.d.ts.map +1 -0
- package/esm/lib/utils/action-provider.js +6 -1
- package/{types → esm}/lib/utils/array.utils.d.ts +1 -0
- package/esm/lib/utils/array.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/class.utils.d.ts +1 -0
- package/esm/lib/utils/class.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/common.utils.d.ts +2 -1
- package/esm/lib/utils/common.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/condition.d.ts +1 -0
- package/esm/lib/utils/condition.d.ts.map +1 -0
- package/esm/lib/utils/endpoint.utils.d.ts +3 -0
- package/esm/lib/utils/endpoint.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/error.utils.d.ts +1 -0
- package/esm/lib/utils/error.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/factory.d.ts +2 -1
- package/esm/lib/utils/factory.d.ts.map +1 -0
- package/esm/lib/utils/factory.js +6 -1
- package/{types → esm}/lib/utils/file-system.utils.d.ts +2 -1
- package/esm/lib/utils/file-system.utils.d.ts.map +1 -0
- package/esm/lib/utils/file-system.utils.js +1 -1
- package/{types → esm}/lib/utils/generator.utils.d.ts +1 -0
- package/esm/lib/utils/generator.utils.d.ts.map +1 -0
- package/esm/lib/utils/index.d.ts +15 -0
- package/esm/lib/utils/index.d.ts.map +1 -0
- package/{types → esm}/lib/utils/object.utils.d.ts +1 -0
- package/esm/lib/utils/object.utils.d.ts.map +1 -0
- package/esm/lib/utils/object.utils.js +6 -1
- package/{types → esm}/lib/utils/schema.utils.d.ts +3 -2
- package/esm/lib/utils/schema.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/source-builder.d.ts +8 -6
- package/esm/lib/utils/source-builder.d.ts.map +1 -0
- package/esm/lib/utils/source-builder.js +39 -6
- package/esm/lib/utils/string-builder/index.d.ts +4 -0
- package/esm/lib/utils/string-builder/index.d.ts.map +1 -0
- package/{types → esm}/lib/utils/string-builder/options.d.ts +1 -0
- package/esm/lib/utils/string-builder/options.d.ts.map +1 -0
- package/esm/lib/utils/string-builder/options.js +1 -1
- package/{types → esm}/lib/utils/string-builder/string-builder.d.ts +3 -2
- package/esm/lib/utils/string-builder/string-builder.d.ts.map +1 -0
- package/esm/lib/utils/string-builder/string-builder.js +12 -1
- package/{types → esm}/lib/utils/string-builder/utils.d.ts +3 -2
- package/esm/lib/utils/string-builder/utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/string.utils.d.ts +3 -2
- package/esm/lib/utils/string.utils.d.ts.map +1 -0
- package/{types → esm}/lib/utils/string.utils.types.d.ts +1 -0
- package/esm/lib/utils/string.utils.types.d.ts.map +1 -0
- package/{types → esm}/lib/utils/type.utils.d.ts +1 -0
- package/esm/lib/utils/type.utils.d.ts.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +24 -32
- package/script/_dnt.shims.d.ts +11 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +75 -0
- package/script/index.d.ts +6 -0
- package/script/index.d.ts.map +1 -0
- package/script/index.js +8 -0
- package/script/lib/ast/index.d.ts +2 -0
- package/script/lib/ast/index.d.ts.map +1 -0
- package/{cjs → script}/lib/ast/index.js +1 -1
- package/script/lib/ast/node.d.ts +15 -0
- package/script/lib/ast/node.d.ts.map +1 -0
- package/{cjs → script}/lib/ast/node.js +6 -0
- package/script/lib/codegen/config.d.ts +16 -0
- package/script/lib/codegen/config.d.ts.map +1 -0
- package/script/lib/codegen/config.js +11 -0
- package/script/lib/codegen/endpoints-generator.d.ts +16 -0
- package/script/lib/codegen/endpoints-generator.d.ts.map +1 -0
- package/{cjs → script}/lib/codegen/endpoints-generator.js +4 -4
- package/script/lib/codegen/generator.d.ts +39 -0
- package/script/lib/codegen/generator.d.ts.map +1 -0
- package/{cjs → script}/lib/codegen/generator.js +29 -15
- package/script/lib/codegen/index.d.ts +7 -0
- package/script/lib/codegen/index.d.ts.map +1 -0
- package/script/lib/codegen/index.js +9 -0
- package/script/lib/codegen/internal-utils.d.ts +2 -0
- package/script/lib/codegen/internal-utils.d.ts.map +1 -0
- package/script/lib/codegen/schemas-generator.d.ts +17 -0
- package/script/lib/codegen/schemas-generator.d.ts.map +1 -0
- package/{cjs → script}/lib/codegen/schemas-generator.js +6 -6
- package/script/lib/codegen/services-generator.d.ts +16 -0
- package/script/lib/codegen/services-generator.d.ts.map +1 -0
- package/{cjs → script}/lib/codegen/services-generator.js +4 -4
- package/script/lib/codegen/types.d.ts +18 -0
- package/script/lib/codegen/types.d.ts.map +1 -0
- package/script/lib/collect/collector.d.ts +4 -0
- package/script/lib/collect/collector.d.ts.map +1 -0
- package/{cjs → script}/lib/collect/collector.js +28 -28
- package/script/lib/collect/helpers.d.ts +5 -0
- package/script/lib/collect/helpers.d.ts.map +1 -0
- package/{cjs → script}/lib/collect/helpers.js +2 -2
- package/script/lib/collect/index.d.ts +4 -0
- package/script/lib/collect/index.d.ts.map +1 -0
- package/script/lib/collect/index.js +6 -0
- package/script/lib/collect/types.d.ts +13 -0
- package/script/lib/collect/types.d.ts.map +1 -0
- package/script/lib/internal-utils.d.ts +2 -0
- package/script/lib/internal-utils.d.ts.map +1 -0
- package/script/lib/parse/deref-proxy.d.ts +4 -0
- package/script/lib/parse/deref-proxy.d.ts.map +1 -0
- package/{cjs → script}/lib/parse/deref-proxy.js +21 -6
- package/script/lib/parse/index.d.ts +4 -0
- package/script/lib/parse/index.d.ts.map +1 -0
- package/script/lib/parse/index.js +6 -0
- package/script/lib/parse/openapi-types.d.ts +898 -0
- package/script/lib/parse/openapi-types.d.ts.map +1 -0
- package/script/lib/parse/parser.d.ts +19 -0
- package/script/lib/parse/parser.d.ts.map +1 -0
- package/{cjs → script}/lib/parse/parser.js +32 -21
- package/script/lib/parse/types.d.ts +24 -0
- package/script/lib/parse/types.d.ts.map +1 -0
- package/script/lib/parse/types.js +5 -0
- package/script/lib/transform/api-types.d.ts +195 -0
- package/script/lib/transform/api-types.d.ts.map +1 -0
- package/script/lib/transform/helpers.d.ts +51 -0
- package/script/lib/transform/helpers.d.ts.map +1 -0
- package/{cjs → script}/lib/transform/helpers.js +16 -10
- package/script/lib/transform/index.d.ts +3 -0
- package/script/lib/transform/index.d.ts.map +1 -0
- package/script/lib/transform/index.js +5 -0
- package/script/lib/transform/transform-document.d.ts +4 -0
- package/script/lib/transform/transform-document.d.ts.map +1 -0
- package/{cjs → script}/lib/transform/transform-document.js +2 -2
- package/script/lib/transform/transform-endpoint.d.ts +5 -0
- package/script/lib/transform/transform-endpoint.d.ts.map +1 -0
- package/{cjs → script}/lib/transform/transform-endpoint.js +18 -18
- package/script/lib/transform/transform-schema.d.ts +5 -0
- package/script/lib/transform/transform-schema.d.ts.map +1 -0
- package/{cjs → script}/lib/transform/transform-schema.js +14 -12
- package/script/lib/transform/transformer.d.ts +5 -0
- package/script/lib/transform/transformer.d.ts.map +1 -0
- package/{cjs → script}/lib/transform/transformer.js +10 -10
- package/script/lib/transform/types.d.ts +36 -0
- package/script/lib/transform/types.d.ts.map +1 -0
- package/script/lib/utils/action-provider.d.ts +29 -0
- package/script/lib/utils/action-provider.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/action-provider.js +6 -1
- package/script/lib/utils/array.utils.d.ts +2 -0
- package/script/lib/utils/array.utils.d.ts.map +1 -0
- package/script/lib/utils/class.utils.d.ts +8 -0
- package/script/lib/utils/class.utils.d.ts.map +1 -0
- package/script/lib/utils/common.utils.d.ts +16 -0
- package/script/lib/utils/common.utils.d.ts.map +1 -0
- package/script/lib/utils/condition.d.ts +4 -0
- package/script/lib/utils/condition.d.ts.map +1 -0
- package/script/lib/utils/endpoint.utils.d.ts +3 -0
- package/script/lib/utils/endpoint.utils.d.ts.map +1 -0
- package/script/lib/utils/error.utils.d.ts +2 -0
- package/script/lib/utils/error.utils.d.ts.map +1 -0
- package/script/lib/utils/factory.d.ts +21 -0
- package/script/lib/utils/factory.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/factory.js +6 -1
- package/script/lib/utils/file-system.utils.d.ts +9 -0
- package/script/lib/utils/file-system.utils.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/file-system.utils.js +2 -2
- package/script/lib/utils/generator.utils.d.ts +2 -0
- package/script/lib/utils/generator.utils.d.ts.map +1 -0
- package/script/lib/utils/index.d.ts +15 -0
- package/script/lib/utils/index.d.ts.map +1 -0
- package/script/lib/utils/index.js +17 -0
- package/script/lib/utils/object.utils.d.ts +3 -0
- package/script/lib/utils/object.utils.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/object.utils.js +6 -1
- package/script/lib/utils/schema.utils.d.ts +11 -0
- package/script/lib/utils/schema.utils.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/schema.utils.js +2 -2
- package/script/lib/utils/source-builder.d.ts +233 -0
- package/script/lib/utils/source-builder.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/source-builder.js +59 -26
- package/script/lib/utils/string-builder/index.d.ts +4 -0
- package/script/lib/utils/string-builder/index.d.ts.map +1 -0
- package/script/lib/utils/string-builder/index.js +8 -0
- package/script/lib/utils/string-builder/options.d.ts +15 -0
- package/script/lib/utils/string-builder/options.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/string-builder/options.js +2 -2
- package/script/lib/utils/string-builder/string-builder.d.ts +73 -0
- package/script/lib/utils/string-builder/string-builder.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/string-builder/string-builder.js +17 -6
- package/script/lib/utils/string-builder/utils.d.ts +22 -0
- package/script/lib/utils/string-builder/utils.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/string-builder/utils.js +4 -4
- package/script/lib/utils/string.utils.d.ts +130 -0
- package/script/lib/utils/string.utils.d.ts.map +1 -0
- package/{cjs → script}/lib/utils/string.utils.js +2 -2
- package/script/lib/utils/string.utils.types.d.ts +150 -0
- package/script/lib/utils/string.utils.types.d.ts.map +1 -0
- package/script/lib/utils/type.utils.d.ts +56 -0
- package/script/lib/utils/type.utils.d.ts.map +1 -0
- package/script/package.json +3 -0
- package/cjs/index.js +0 -8
- package/cjs/lib/codegen/config.js +0 -11
- package/cjs/lib/codegen/index.js +0 -9
- package/cjs/lib/collect/index.js +0 -6
- package/cjs/lib/parse/index.js +0 -6
- package/cjs/lib/parse/types.js +0 -5
- package/cjs/lib/transform/index.js +0 -5
- package/cjs/lib/utils/index.js +0 -17
- package/cjs/lib/utils/string-builder/index.js +0 -8
- package/cjs/package.json +0 -1
- package/types/index.d.ts +0 -5
- package/types/lib/ast/index.d.ts +0 -1
- package/types/lib/codegen/index.d.ts +0 -6
- package/types/lib/collect/collector.d.ts +0 -3
- package/types/lib/collect/index.d.ts +0 -3
- package/types/lib/parse/deref-proxy.d.ts +0 -3
- package/types/lib/parse/index.d.ts +0 -3
- package/types/lib/transform/index.d.ts +0 -2
- package/types/lib/transform/transform-document.d.ts +0 -3
- package/types/lib/transform/transform-endpoint.d.ts +0 -4
- package/types/lib/transform/transform-schema.d.ts +0 -4
- package/types/lib/transform/transformer.d.ts +0 -4
- package/types/lib/utils/endpoint.utils.d.ts +0 -2
- package/types/lib/utils/index.d.ts +0 -14
- package/types/lib/utils/string-builder/index.d.ts +0 -3
- /package/{cjs → script}/lib/codegen/internal-utils.js +0 -0
- /package/{cjs → script}/lib/codegen/types.js +0 -0
- /package/{cjs → script}/lib/collect/types.js +0 -0
- /package/{cjs → script}/lib/internal-utils.js +0 -0
- /package/{cjs → script}/lib/parse/openapi-types.js +0 -0
- /package/{cjs → script}/lib/transform/api-types.js +0 -0
- /package/{cjs → script}/lib/transform/types.js +0 -0
- /package/{cjs → script}/lib/utils/array.utils.js +0 -0
- /package/{cjs → script}/lib/utils/class.utils.js +0 -0
- /package/{cjs → script}/lib/utils/common.utils.js +0 -0
- /package/{cjs → script}/lib/utils/condition.js +0 -0
- /package/{cjs → script}/lib/utils/endpoint.utils.js +0 -0
- /package/{cjs → script}/lib/utils/error.utils.js +0 -0
- /package/{cjs → script}/lib/utils/generator.utils.js +0 -0
- /package/{cjs → script}/lib/utils/string.utils.types.js +0 -0
- /package/{cjs → script}/lib/utils/type.utils.js +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveAnyOfAndAllOf = resolveAnyOfAndAllOf;
|
|
4
4
|
exports.getSchemaReference = getSchemaReference;
|
|
5
|
-
const
|
|
5
|
+
const internal_utils_js_1 = require("../internal-utils.js");
|
|
6
6
|
function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
7
7
|
if (!ignoreNonObjectParts && (hasInvalidSubSchema(schema.anyOf) || hasInvalidSubSchema(schema.allOf))) {
|
|
8
8
|
return undefined;
|
|
@@ -115,6 +115,6 @@ function hasInvalidSubSchema(subSchemas) {
|
|
|
115
115
|
function getSchemaReference(schema, propertiesToIgnore) {
|
|
116
116
|
if (!schema.$ref)
|
|
117
117
|
return schema;
|
|
118
|
-
const hasPropertiesDefined = Object.keys(schema.$src.originalComponent).some((key) => (0,
|
|
118
|
+
const hasPropertiesDefined = Object.keys(schema.$src.originalComponent).some((key) => (0, internal_utils_js_1.isOpenApiObjectProperty)(key) && !propertiesToIgnore.includes(key));
|
|
119
119
|
return hasPropertiesDefined ? schema : getSchemaReference(schema.$ref, propertiesToIgnore);
|
|
120
120
|
}
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { type Condition } from './condition.js';
|
|
2
|
+
import { type AppendParam, type AppendValue, StringBuilder, type StringBuilderOptions } from './string-builder/index.js';
|
|
3
|
+
import type { BuilderFn } from './string-builder/string-builder.js';
|
|
4
|
+
import type { Nullable } from './type.utils.js';
|
|
5
|
+
export type IndentOptions = {
|
|
6
|
+
readonly type: 'tabs';
|
|
7
|
+
} | {
|
|
8
|
+
readonly type: 'spaces';
|
|
9
|
+
readonly count: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Options for the `SourceBuilder` class.
|
|
13
|
+
*/
|
|
14
|
+
export type SourceBuilderOptions = StringBuilderOptions & {
|
|
15
|
+
/**
|
|
16
|
+
* The type of indentation to use.
|
|
17
|
+
* @default { type: 'spaces', count: 2 }
|
|
18
|
+
*/
|
|
19
|
+
indent: IndentOptions;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Default options for the `SourceBuilder` class.
|
|
23
|
+
*/
|
|
24
|
+
export declare const defaultSourceBuilderOptions: SourceBuilderOptions;
|
|
25
|
+
type KnownParatheses = '()' | '[]' | '{}' | '<>';
|
|
26
|
+
export type Paratheses<TBuilder extends StringBuilder> = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<AppendValue<TBuilder>>, close: Nullable<AppendValue<TBuilder>>];
|
|
27
|
+
export type SeparatorBuidlerFn<TBuilder, TItem> = (builder: TBuilder, previousItem: TItem, nextItem: TItem, previousItemIndex: number, nextItemIndex: number) => void;
|
|
28
|
+
export type Separator<TBuilder, TItem> = string | SeparatorBuidlerFn<TBuilder, TItem>;
|
|
29
|
+
/**
|
|
30
|
+
* Options for the `parenthesize` methods of the `SourceBuilder`.
|
|
31
|
+
* @see SourceBuilder.parenthesize
|
|
32
|
+
* @see SourceBuilder.parenthesizeIf
|
|
33
|
+
*/
|
|
34
|
+
export type ParenthesizeOptions = {
|
|
35
|
+
/**
|
|
36
|
+
* Whether to add line breaks after start and before end of the parentheses.
|
|
37
|
+
* @default false
|
|
38
|
+
*/
|
|
39
|
+
readonly multiline?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Whether to indent the content inside parentheses.
|
|
42
|
+
* @default true
|
|
43
|
+
*/
|
|
44
|
+
readonly indent?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Whether to pretend that the current line and the one before is empty or consists only of whitespace characters.
|
|
47
|
+
* This is useful when the parentheses are used as a block and `ensurePreviousLineEmpty` is used.
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
readonly pretendEmpty?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Options for the `forEach` methods of the `SourceBuilder`.
|
|
54
|
+
* @see SourceBuilder.forEach
|
|
55
|
+
* @see SourceBuilder.forEachIf
|
|
56
|
+
*/
|
|
57
|
+
export type ForEachOptions<TBuilder, TItem> = {
|
|
58
|
+
/**
|
|
59
|
+
* The condition to check before adding content for each item. Defaults to `true`.
|
|
60
|
+
*/
|
|
61
|
+
readonly condition?: Condition<TItem>;
|
|
62
|
+
/**
|
|
63
|
+
* The seperator to add between items. Default to `undefined`.
|
|
64
|
+
*/
|
|
65
|
+
readonly separator?: Separator<TBuilder, TItem>;
|
|
66
|
+
};
|
|
67
|
+
type SwitchCase<TValue, TBuilder extends StringBuilder> = {
|
|
68
|
+
case: TValue;
|
|
69
|
+
value: AppendValue<TBuilder>;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Represents an in-memory source file.
|
|
73
|
+
*/
|
|
74
|
+
export declare class SourceBuilder<TAdditionalAppends = never> extends StringBuilder<TAdditionalAppends> {
|
|
75
|
+
private readonly __options;
|
|
76
|
+
private readonly _indentString;
|
|
77
|
+
private _isLineIndented;
|
|
78
|
+
private _isLastLineEmpty;
|
|
79
|
+
private _isCurrentLineEmpty;
|
|
80
|
+
private _linePrefixNodes;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the options used by this instance.
|
|
83
|
+
*/
|
|
84
|
+
get options(): SourceBuilderOptions;
|
|
85
|
+
/**
|
|
86
|
+
* Initializes a new instance of the SourceBuilder class.
|
|
87
|
+
* @param options The options to use for this instance.
|
|
88
|
+
*/
|
|
89
|
+
constructor(options?: Partial<SourceBuilderOptions>);
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new instance of the SourceBuilder class from a string.
|
|
92
|
+
* @param str The string to use as the initial content of the builder.
|
|
93
|
+
* @param options The options to use for this instance.
|
|
94
|
+
* @returns A new instance of the SourceBuilder class.
|
|
95
|
+
*/
|
|
96
|
+
static fromString(str: string, options?: Partial<SourceBuilderOptions>): SourceBuilder;
|
|
97
|
+
/**
|
|
98
|
+
* Builds a string using a callback function that receives a `SourceBuilder` instance.
|
|
99
|
+
* @param buildAction The callback function that receives a `SourceBuilder` instance to build the string.
|
|
100
|
+
* @param options The options to use for the `SourceBuilder` instance.
|
|
101
|
+
* @returns The string built by the `SourceBuilder` instance.
|
|
102
|
+
*/
|
|
103
|
+
static build(buildAction: AppendParam<SourceBuilder, never>, options?: Partial<SourceBuilderOptions>): string;
|
|
104
|
+
protected appendSingle(value: AppendParam<this, TAdditionalAppends>): void;
|
|
105
|
+
/**
|
|
106
|
+
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
107
|
+
* @param condition The condition to check before appending the specified value.
|
|
108
|
+
* @param value The string(s) to append.
|
|
109
|
+
* @returns The current SourceBuilder.
|
|
110
|
+
*/
|
|
111
|
+
appendIf(condition: Condition, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
112
|
+
/**
|
|
113
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
114
|
+
* @param value The string(s) to append.
|
|
115
|
+
* @returns The current SourceBuilder.
|
|
116
|
+
*/
|
|
117
|
+
appendLine(...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
118
|
+
/**
|
|
119
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
120
|
+
* @param condition The condition to check before appending the specified value.
|
|
121
|
+
* @param value The string(s) to append.
|
|
122
|
+
* @returns The current SourceBuilder.
|
|
123
|
+
*/
|
|
124
|
+
appendLineIf(condition: Condition, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
125
|
+
/**
|
|
126
|
+
* Appends the specified values to this source builder with the specified line prefix.
|
|
127
|
+
* @param {string} prefix - The line prefix to use.
|
|
128
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
129
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
130
|
+
*/
|
|
131
|
+
appendWithLinePrefix(prefix: string, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
132
|
+
/**
|
|
133
|
+
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
134
|
+
* @param {string} prefix - The line prefix to use.
|
|
135
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
136
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
137
|
+
*/
|
|
138
|
+
appendLineWithLinePrefix(prefix: string, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
139
|
+
/**
|
|
140
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
141
|
+
* @param condition The condition to check before prepending the specified value.
|
|
142
|
+
* @param value The string(s) to prepend.
|
|
143
|
+
* @returns The current SourceBuilder.
|
|
144
|
+
*/
|
|
145
|
+
prependIf(condition: Condition, ...value: AppendParam<StringBuilder, never>[]): this;
|
|
146
|
+
/**
|
|
147
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
148
|
+
* @param condition The condition to check before appending the specified value.
|
|
149
|
+
* @param value The string(s) to prepend.
|
|
150
|
+
* @returns The current SourceBuilder.
|
|
151
|
+
*/
|
|
152
|
+
prependLineIf(condition: Condition, ...value: AppendParam<StringBuilder, never>[]): this;
|
|
153
|
+
/**
|
|
154
|
+
* Ensures that the current line and the one before is empty or consists only of whitespace characters.
|
|
155
|
+
* @returns A reference to this instance.
|
|
156
|
+
*/
|
|
157
|
+
ensurePreviousLineEmpty(): this;
|
|
158
|
+
/**
|
|
159
|
+
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
160
|
+
* @returns A reference to this instance.
|
|
161
|
+
*/
|
|
162
|
+
ensureCurrentLineEmpty(): this;
|
|
163
|
+
/**
|
|
164
|
+
* Pretends that the current line and the one before is empty or consists only of whitespace characters.
|
|
165
|
+
* @returns A reference to this instance.
|
|
166
|
+
*/
|
|
167
|
+
pretendPreviousLineEmpty(): this;
|
|
168
|
+
/**
|
|
169
|
+
* Pretends that the current line is empty or consists only of whitespace characters.
|
|
170
|
+
* @returns A reference to this instance.
|
|
171
|
+
*/
|
|
172
|
+
pretendCurrentLineEmpty(): this;
|
|
173
|
+
/**
|
|
174
|
+
* Inserts specified content if the specified condition is true.
|
|
175
|
+
* @param condition The condition to check before inserting content.
|
|
176
|
+
* @param builderFn The function to add content if the condition is true.
|
|
177
|
+
* @param elseBuilderFn The function to add content if the condition is false.
|
|
178
|
+
* @returns A reference to this instance.
|
|
179
|
+
*/
|
|
180
|
+
if(condition: Condition, builderFn: AppendParam<this, TAdditionalAppends>, elseBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
|
|
181
|
+
switch<T extends string | number>(value: T, cases: Record<T, AppendParam<this, TAdditionalAppends>>, defaultBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
|
|
182
|
+
switch<T>(value: T, cases: SwitchCase<T, this>[], defaultBuilderFn?: AppendParam<this, TAdditionalAppends>, equals?: (a: T, b: T) => boolean): this;
|
|
183
|
+
/**
|
|
184
|
+
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
185
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
186
|
+
* @param condition The condition to check before adding indentation.
|
|
187
|
+
* @returns A reference to this instance.
|
|
188
|
+
*/
|
|
189
|
+
indent(value: AppendParam<this, TAdditionalAppends>): this;
|
|
190
|
+
/**
|
|
191
|
+
* Adds one indentation level if the specified condition is true. If the current line already contains characters, only subsequent lines are affected.
|
|
192
|
+
* @param builderFn The function to add indented content or the content itself.
|
|
193
|
+
* @param condition The condition to check before adding indentation.
|
|
194
|
+
* @returns A reference to this instance.
|
|
195
|
+
*/
|
|
196
|
+
indentIf(condition: Condition, value: AppendParam<this, TAdditionalAppends>): this;
|
|
197
|
+
/**
|
|
198
|
+
* Adds parentheses around the specified content.
|
|
199
|
+
* @param brackets The brackets to use.
|
|
200
|
+
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
201
|
+
* @param options Options for the parentheses.
|
|
202
|
+
* @returns A reference to this instance.
|
|
203
|
+
*/
|
|
204
|
+
parenthesize(brackets: Paratheses<this>, value: AppendParam<this, TAdditionalAppends>, options?: ParenthesizeOptions): this;
|
|
205
|
+
/**
|
|
206
|
+
* Adds parentheses around the specified content if the specified condition is true.
|
|
207
|
+
* @param condition The condition to check before adding parentheses.
|
|
208
|
+
* @param brackets The brackets to use.
|
|
209
|
+
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
210
|
+
* @param options Options for the parentheses.
|
|
211
|
+
* @returns A reference to this instance.
|
|
212
|
+
*/
|
|
213
|
+
parenthesizeIf(condition: Condition, brackets: Paratheses<this>, value: AppendParam<this, TAdditionalAppends>, options?: ParenthesizeOptions): this;
|
|
214
|
+
/**
|
|
215
|
+
* Adds content for each item in the specified array.
|
|
216
|
+
* @param items The items to add content for.
|
|
217
|
+
* @param builderFn The function to add content for each item.
|
|
218
|
+
* @param options The options for the loop.
|
|
219
|
+
* @returns A reference to this instance.
|
|
220
|
+
*/
|
|
221
|
+
forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
222
|
+
forEachIf<T>(condition: Condition, items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
223
|
+
appendSeparated(items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
|
|
224
|
+
appendSeparatedIf(condition: Condition, items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
|
|
225
|
+
private appendIndent;
|
|
226
|
+
}
|
|
227
|
+
declare function _builderTemplate<T extends SourceBuilder>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]): BuilderFn<T>;
|
|
228
|
+
declare const _builderTemplateExtensions: {
|
|
229
|
+
readonly indent: <T extends SourceBuilder>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]) => BuilderFn<T>;
|
|
230
|
+
};
|
|
231
|
+
export declare const builderTemplate: typeof _builderTemplate & typeof _builderTemplateExtensions;
|
|
232
|
+
export {};
|
|
233
|
+
//# sourceMappingURL=source-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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AAS,CAAC,CAAC,CAAC,CAiBd;AAED,QAAA,MAAM,0BAA0B;sBACrB,CAAC,SAAS,aAAa,YACpB,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,MAAM,CAAC,oBAC7B,WAAW,CAAC,CAAC,CAAC,EAAE,KACjC,SAAS,CAAC,CAAC,CAAC;CAGP,CAAC;AAEX,eAAO,MAAM,eAAe,EAAE,OAAO,gBAAgB,GAAG,OAAO,0BAG9D,CAAC"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.builderTemplate = exports.SourceBuilder = exports.defaultSourceBuilderOptions = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const common_utils_js_1 = require("./common.utils.js");
|
|
5
|
+
const condition_js_1 = require("./condition.js");
|
|
6
|
+
const index_js_1 = require("./string-builder/index.js");
|
|
7
|
+
const string_utils_js_1 = require("./string.utils.js");
|
|
8
8
|
/**
|
|
9
9
|
* Default options for the `SourceBuilder` class.
|
|
10
10
|
*/
|
|
11
11
|
exports.defaultSourceBuilderOptions = {
|
|
12
|
-
...
|
|
12
|
+
...index_js_1.defaultStringBuilderOptions,
|
|
13
13
|
indent: { type: 'spaces', count: 2 },
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Represents an in-memory source file.
|
|
17
17
|
*/
|
|
18
|
-
class SourceBuilder extends
|
|
18
|
+
class SourceBuilder extends index_js_1.StringBuilder {
|
|
19
19
|
/**
|
|
20
20
|
* Gets the options used by this instance.
|
|
21
21
|
*/
|
|
@@ -28,10 +28,42 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
28
28
|
*/
|
|
29
29
|
constructor(options) {
|
|
30
30
|
super(options);
|
|
31
|
-
this
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
Object.defineProperty(this, "__options", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(this, "_indentString", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: void 0
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(this, "_isLineIndented", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
configurable: true,
|
|
46
|
+
writable: true,
|
|
47
|
+
value: false
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(this, "_isLastLineEmpty", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
writable: true,
|
|
53
|
+
value: true
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(this, "_isCurrentLineEmpty", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
configurable: true,
|
|
58
|
+
writable: true,
|
|
59
|
+
value: true
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(this, "_linePrefixNodes", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: []
|
|
66
|
+
});
|
|
35
67
|
this.__options = { ...exports.defaultSourceBuilderOptions, ...options };
|
|
36
68
|
this._indentString = this.__options.indent.type === 'tabs' ? '\t' : ' '.repeat(this.__options.indent.count);
|
|
37
69
|
}
|
|
@@ -59,7 +91,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
59
91
|
}
|
|
60
92
|
appendSingle(value) {
|
|
61
93
|
var _a;
|
|
62
|
-
if ((0,
|
|
94
|
+
if ((0, common_utils_js_1.isNullish)(value))
|
|
63
95
|
return;
|
|
64
96
|
if (Array.isArray(value)) {
|
|
65
97
|
for (const part of value) {
|
|
@@ -94,13 +126,13 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
94
126
|
if (!this._isLineIndented) {
|
|
95
127
|
this.appendIndent();
|
|
96
128
|
}
|
|
97
|
-
this.str += (0,
|
|
129
|
+
this.str += (0, string_utils_js_1.removeStr)(value.substring(lineStartIndex, i), '\r');
|
|
98
130
|
}
|
|
99
131
|
this._isLastLineEmpty = this._isCurrentLineEmpty;
|
|
100
132
|
if (this._isCurrentLineEmpty && this._linePrefixNodes.some((x) => x.kind !== 'indent')) {
|
|
101
133
|
this.appendIndent();
|
|
102
134
|
}
|
|
103
|
-
this.str = (0,
|
|
135
|
+
this.str = (0, string_utils_js_1.trimEnd)(this.str, false) + '\n';
|
|
104
136
|
this._isLineIndented = false;
|
|
105
137
|
this._isCurrentLineEmpty = true;
|
|
106
138
|
lineStartIndex = i + 1;
|
|
@@ -113,7 +145,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
113
145
|
this.appendIndent();
|
|
114
146
|
this._isLineIndented = true;
|
|
115
147
|
}
|
|
116
|
-
this.str += (0,
|
|
148
|
+
this.str += (0, string_utils_js_1.removeStr)(value.substring(lineStartIndex), '\r');
|
|
117
149
|
}
|
|
118
150
|
/**
|
|
119
151
|
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
@@ -122,7 +154,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
122
154
|
* @returns The current SourceBuilder.
|
|
123
155
|
*/
|
|
124
156
|
appendIf(condition, ...value) {
|
|
125
|
-
if ((0,
|
|
157
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
126
158
|
return this.append(...value);
|
|
127
159
|
}
|
|
128
160
|
return this;
|
|
@@ -142,7 +174,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
142
174
|
* @returns The current SourceBuilder.
|
|
143
175
|
*/
|
|
144
176
|
appendLineIf(condition, ...value) {
|
|
145
|
-
if ((0,
|
|
177
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
146
178
|
return this.appendLine(...value);
|
|
147
179
|
}
|
|
148
180
|
return this;
|
|
@@ -179,7 +211,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
179
211
|
* @returns The current SourceBuilder.
|
|
180
212
|
*/
|
|
181
213
|
prependIf(condition, ...value) {
|
|
182
|
-
if ((0,
|
|
214
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
183
215
|
this.prepend(...value);
|
|
184
216
|
}
|
|
185
217
|
return this;
|
|
@@ -191,7 +223,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
191
223
|
* @returns The current SourceBuilder.
|
|
192
224
|
*/
|
|
193
225
|
prependLineIf(condition, ...value) {
|
|
194
|
-
if ((0,
|
|
226
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
195
227
|
this.prependLine(...value);
|
|
196
228
|
}
|
|
197
229
|
return this;
|
|
@@ -244,7 +276,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
244
276
|
* @returns A reference to this instance.
|
|
245
277
|
*/
|
|
246
278
|
if(condition, builderFn, elseBuilderFn) {
|
|
247
|
-
return (0,
|
|
279
|
+
return (0, condition_js_1.evalCondition)(condition) ? this.append(builderFn) : this.append(elseBuilderFn);
|
|
248
280
|
}
|
|
249
281
|
switch(value, cases, defaultBuilderFn, equals) {
|
|
250
282
|
var _a;
|
|
@@ -284,7 +316,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
284
316
|
* @returns A reference to this instance.
|
|
285
317
|
*/
|
|
286
318
|
indentIf(condition, value) {
|
|
287
|
-
return (0,
|
|
319
|
+
return (0, condition_js_1.evalCondition)(condition) ? this.indent(value) : this.append(value);
|
|
288
320
|
}
|
|
289
321
|
/**
|
|
290
322
|
* Adds parentheses around the specified content.
|
|
@@ -326,7 +358,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
326
358
|
* @returns A reference to this instance.
|
|
327
359
|
*/
|
|
328
360
|
parenthesizeIf(condition, brackets, value, options) {
|
|
329
|
-
if ((0,
|
|
361
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
330
362
|
return this.parenthesize(brackets, value, options);
|
|
331
363
|
}
|
|
332
364
|
else if (options === null || options === void 0 ? void 0 : options.indent) {
|
|
@@ -354,7 +386,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
354
386
|
let previousItem = undefined;
|
|
355
387
|
let index = 0;
|
|
356
388
|
for (const item of items) {
|
|
357
|
-
if ((0,
|
|
389
|
+
if ((0, condition_js_1.evalCondition)(condition, item)) {
|
|
358
390
|
if (previousIndex >= 0 && seperator) {
|
|
359
391
|
if (typeof seperator === 'string') {
|
|
360
392
|
this.append(seperator);
|
|
@@ -372,7 +404,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
372
404
|
return this;
|
|
373
405
|
}
|
|
374
406
|
forEachIf(condition, items, builderFn, options) {
|
|
375
|
-
if ((0,
|
|
407
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
376
408
|
return this.forEach(items, builderFn, options);
|
|
377
409
|
}
|
|
378
410
|
return this;
|
|
@@ -381,7 +413,7 @@ class SourceBuilder extends string_builder_1.StringBuilder {
|
|
|
381
413
|
return this.forEach(items, (builder, item) => builder.append(item), { separator });
|
|
382
414
|
}
|
|
383
415
|
appendSeparatedIf(condition, items, separator) {
|
|
384
|
-
if ((0,
|
|
416
|
+
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
385
417
|
return this.appendSeparated(items, separator);
|
|
386
418
|
}
|
|
387
419
|
return this;
|
|
@@ -410,8 +442,9 @@ function _builderTemplate(template, ...substitutions) {
|
|
|
410
442
|
}
|
|
411
443
|
};
|
|
412
444
|
}
|
|
413
|
-
|
|
445
|
+
const _builderTemplateExtensions = {
|
|
414
446
|
indent: (template, ...substitutions) => {
|
|
415
447
|
return (b) => b.indent(_builderTemplate(template, ...substitutions));
|
|
416
448
|
},
|
|
417
|
-
}
|
|
449
|
+
};
|
|
450
|
+
exports.builderTemplate = Object.assign(_builderTemplate, _builderTemplateExtensions);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/string-builder/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EAAE,KAAK,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACtE,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StringBuilder = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
tslib_1.__exportStar(require("./options.js"), exports);
|
|
6
|
+
var string_builder_js_1 = require("./string-builder.js");
|
|
7
|
+
Object.defineProperty(exports, "StringBuilder", { enumerable: true, get: function () { return string_builder_js_1.StringBuilder; } });
|
|
8
|
+
tslib_1.__exportStar(require("./utils.js"), exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for the `StringBuilder` class.
|
|
3
|
+
*/
|
|
4
|
+
export type StringBuilderOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The string to use for new lines.
|
|
7
|
+
* @default os.EOL
|
|
8
|
+
*/
|
|
9
|
+
readonly newLine: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Default options for the `StringBuilder` class.
|
|
13
|
+
*/
|
|
14
|
+
export declare const defaultStringBuilderOptions: StringBuilderOptions;
|
|
15
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/string-builder/options.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,EAAE,oBAEzC,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.defaultStringBuilderOptions = void 0;
|
|
4
|
-
const
|
|
4
|
+
const node_os_1 = require("node:os");
|
|
5
5
|
/**
|
|
6
6
|
* Default options for the `StringBuilder` class.
|
|
7
7
|
*/
|
|
8
8
|
exports.defaultStringBuilderOptions = {
|
|
9
|
-
newLine:
|
|
9
|
+
newLine: node_os_1.EOL,
|
|
10
10
|
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type StringBuilderOptions } from './options.js';
|
|
2
|
+
import type { Nullable, SingleOrMultiple } from '../type.utils.js';
|
|
3
|
+
export type BuilderFn<TBuilder extends StringBuilder> = (builder: TBuilder) => void;
|
|
4
|
+
export type Primitive = string | number | boolean;
|
|
5
|
+
export type AppendParam<TBuilder extends StringBuilder, TAdditionalAppends> = SingleOrMultiple<Primitive | null | undefined | BuilderFn<TBuilder> | TAdditionalAppends | {
|
|
6
|
+
__type: 'append-value-group';
|
|
7
|
+
values: AppendParam<TBuilder, TAdditionalAppends>[];
|
|
8
|
+
separator: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const AdditionalAppendsSymbol: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a mutable string of characters.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StringBuilder<TAdditionalAppends = never> {
|
|
15
|
+
private readonly _options;
|
|
16
|
+
protected str: string;
|
|
17
|
+
[AdditionalAppendsSymbol](_: TAdditionalAppends): void;
|
|
18
|
+
get options(): StringBuilderOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Initializes a new instance of the StringBuilder class.
|
|
21
|
+
* @param options The options.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: Partial<StringBuilderOptions>);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
26
|
+
* @param str The string to append.
|
|
27
|
+
* @param options The options.
|
|
28
|
+
* @returns A new StringBuilder instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromString(str: string, options?: Partial<StringBuilderOptions>): StringBuilder;
|
|
31
|
+
/**
|
|
32
|
+
* Builds a string using a StringBuilder build action.
|
|
33
|
+
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
34
|
+
* @param options The options for the StringBuilder instance.
|
|
35
|
+
* @returns The built string.
|
|
36
|
+
*/
|
|
37
|
+
static build(buildAction: AppendParam<StringBuilder, never>, options?: Partial<StringBuilderOptions>): string;
|
|
38
|
+
protected appendSingle(value: AppendParam<this, TAdditionalAppends>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Appends one or more strings to the end of the current StringBuilder.
|
|
41
|
+
* @param value The string(s) to append.
|
|
42
|
+
* @returns The current StringBuilder.
|
|
43
|
+
*/
|
|
44
|
+
append(...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
45
|
+
/**
|
|
46
|
+
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
47
|
+
* @param value
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
appendLine(...value: Nullable<AppendParam<this, TAdditionalAppends>>[]): this;
|
|
51
|
+
/**
|
|
52
|
+
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
53
|
+
* @param value The string(s) to prepend.
|
|
54
|
+
* @returns The current StringBuilder.
|
|
55
|
+
*/
|
|
56
|
+
prepend(...value: AppendParam<StringBuilder, never>[]): this;
|
|
57
|
+
/**
|
|
58
|
+
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
59
|
+
* @param value The string(s) to prepend.
|
|
60
|
+
* @returns The current StringBuilder.
|
|
61
|
+
*/
|
|
62
|
+
prependLine(...value: AppendParam<StringBuilder, never>[]): this;
|
|
63
|
+
/**
|
|
64
|
+
* Converts the value of this instance to a string.
|
|
65
|
+
* @returns A string whose value is the same as this instance.
|
|
66
|
+
*/
|
|
67
|
+
toString(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Removes all characters from the current StringBuilder.
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=string-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/string-builder/string-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEtF,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEnE,MAAM,MAAM,SAAS,CAAC,QAAQ,SAAS,aAAa,IAAI,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC;AACpF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAElD,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,aAAa,EAAE,kBAAkB,IAAI,gBAAgB,CAC1F,SAAS,GACT,IAAI,GACJ,SAAS,GACT,SAAS,CAAC,QAAQ,CAAC,GAEnB,kBAAkB,GAClB;IACA,MAAM,EAAE,oBAAoB,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE,CAAC;IACpD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CACF,CAAC;AAEF,eAAO,MAAM,uBAAuB,eAA8B,CAAC;AAEnE;;GAEG;AACH,qBAAa,aAAa,CAAC,kBAAkB,GAAG,KAAK;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;IAChD,SAAS,CAAC,GAAG,EAAE,MAAM,CAAM;IAE3B,CAAC,uBAAuB,CAAC,CAAC,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAItD,IAAW,OAAO,IAAI,oBAAoB,CAEzC;IAED;;;OAGG;gBACS,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC;IAInD;;;;;OAKG;WACW,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,aAAa;IAM7F;;;;;OAKG;WACW,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,MAAM;IAMpH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,kBAAkB,CAAC;IA6BnE;;;;OAIG;IACI,MAAM,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAOtE;;;;OAIG;IACI,UAAU,CAAC,GAAG,KAAK,EAAE,QAAQ,CAAC,WAAW,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC,EAAE,GAAG,IAAI;IAIpF;;;;OAIG;IACI,OAAO,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI;IAgBnE;;;;OAIG;IACI,WAAW,CAAC,GAAG,KAAK,EAAE,WAAW,CAAC,aAAa,EAAE,KAAK,CAAC,EAAE,GAAG,IAAI;IAIvE;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;OAEG;IACI,KAAK,IAAI,IAAI;CAGrB"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringBuilder = exports.AdditionalAppendsSymbol = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const options_js_1 = require("./options.js");
|
|
5
|
+
const common_utils_js_1 = require("../common.utils.js");
|
|
6
6
|
exports.AdditionalAppendsSymbol = Symbol('AdditionalAppends');
|
|
7
7
|
/**
|
|
8
8
|
* Represents a mutable string of characters.
|
|
@@ -19,8 +19,19 @@ class StringBuilder {
|
|
|
19
19
|
* @param options The options.
|
|
20
20
|
*/
|
|
21
21
|
constructor(options) {
|
|
22
|
-
this
|
|
23
|
-
|
|
22
|
+
Object.defineProperty(this, "_options", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "str", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: ''
|
|
33
|
+
});
|
|
34
|
+
this._options = { ...options_js_1.defaultStringBuilderOptions, ...options };
|
|
24
35
|
}
|
|
25
36
|
/**
|
|
26
37
|
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
@@ -45,7 +56,7 @@ class StringBuilder {
|
|
|
45
56
|
return builder.toString();
|
|
46
57
|
}
|
|
47
58
|
appendSingle(value) {
|
|
48
|
-
if ((0,
|
|
59
|
+
if ((0, common_utils_js_1.isNullish)(value))
|
|
49
60
|
return;
|
|
50
61
|
if (Array.isArray(value)) {
|
|
51
62
|
for (const part of value) {
|
|
@@ -101,7 +112,7 @@ class StringBuilder {
|
|
|
101
112
|
*/
|
|
102
113
|
prepend(...value) {
|
|
103
114
|
for (const part of value.reverse()) {
|
|
104
|
-
if ((0,
|
|
115
|
+
if ((0, common_utils_js_1.isNullish)(part))
|
|
105
116
|
continue;
|
|
106
117
|
if (typeof part === 'function') {
|
|
107
118
|
const builder = new StringBuilder(this.options);
|