@goast/core 0.6.0 → 0.7.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -4
- package/dist/mod.d.ts +31 -0
- package/{script → dist}/src/ast/node.d.ts +3 -4
- package/{esm → dist}/src/ast/node.js +3 -9
- package/{esm → dist}/src/codegen/config.d.ts +2 -3
- package/{script → dist}/src/codegen/endpoints-generator.d.ts +4 -5
- package/{esm → dist}/src/codegen/endpoints-generator.js +1 -1
- package/{script → dist}/src/codegen/generator.d.ts +7 -8
- package/{esm → dist}/src/codegen/generator.js +4 -21
- package/{esm → dist}/src/codegen/internal-utils.d.ts +0 -1
- package/{esm → dist}/src/codegen/internal-utils.js +0 -1
- package/{script → dist}/src/codegen/schemas-generator.d.ts +4 -5
- package/{esm → dist}/src/codegen/schemas-generator.js +1 -2
- package/{esm → dist}/src/codegen/services-generator.d.ts +4 -5
- package/{esm → dist}/src/codegen/services-generator.js +1 -1
- package/{script → dist}/src/codegen/types.d.ts +3 -4
- package/dist/src/collect/collector.d.ts +4 -0
- package/{esm → dist}/src/collect/collector.js +6 -8
- package/{esm → dist}/src/collect/helpers.d.ts +2 -3
- package/{script → dist}/src/collect/types.d.ts +2 -3
- package/{esm → dist}/src/internal-utils.d.ts +0 -1
- package/dist/src/parse/deref-proxy.d.ts +3 -0
- package/{esm → dist}/src/parse/deref-proxy.js +7 -21
- package/{esm → dist}/src/parse/openapi-types.d.ts +0 -1
- package/{esm → dist}/src/parse/parser.d.ts +3 -4
- package/{esm → dist}/src/parse/parser.js +7 -20
- package/{script → dist}/src/parse/types.d.ts +3 -4
- package/{script → dist}/src/transform/api-types.d.ts +3 -4
- package/{esm → dist}/src/transform/helpers.d.ts +4 -5
- package/{esm → dist}/src/transform/helpers.js +5 -15
- package/dist/src/transform/transform-document.d.ts +4 -0
- package/{esm → dist}/src/transform/transform-document.js +2 -4
- package/{esm → dist}/src/transform/transform-endpoint.d.ts +3 -4
- package/{esm → dist}/src/transform/transform-endpoint.js +10 -17
- package/dist/src/transform/transform-schema.d.ts +5 -0
- package/{esm → dist}/src/transform/transform-schema.js +8 -12
- package/dist/src/transform/transformer.d.ts +4 -0
- package/{esm → dist}/src/transform/types.d.ts +4 -5
- package/{script → dist}/src/utils/action-provider.d.ts +2 -3
- package/{esm → dist}/src/utils/action-provider.js +3 -7
- package/{esm → dist}/src/utils/api-data.utils.d.ts +1 -2
- package/{esm → dist}/src/utils/array.utils.d.ts +0 -1
- package/{script → dist}/src/utils/asset-manager.d.ts +0 -1
- package/{esm → dist}/src/utils/asset-manager.js +2 -8
- package/{esm → dist}/src/utils/class.utils.d.ts +0 -1
- package/{esm → dist}/src/utils/class.utils.js +0 -1
- package/{script → dist}/src/utils/common.utils.d.ts +1 -2
- package/{esm → dist}/src/utils/condition.d.ts +0 -1
- package/dist/src/utils/endpoint.utils.d.ts +2 -0
- package/{esm → dist}/src/utils/error.utils.d.ts +0 -1
- package/{esm → dist}/src/utils/factory.d.ts +2 -3
- package/{esm → dist}/src/utils/factory.js +3 -7
- package/{esm → dist}/src/utils/file-system.utils.d.ts +2 -3
- package/{esm → dist}/src/utils/generator.utils.d.ts +0 -1
- package/{esm → dist}/src/utils/object.utils.d.ts +0 -1
- package/{esm → dist}/src/utils/object.utils.js +2 -11
- package/dist/src/utils/schema-factory.d.ts +41 -0
- package/dist/src/utils/schema-factory.js +132 -0
- package/{esm → dist}/src/utils/schema.utils.d.ts +2 -3
- package/{esm → dist}/src/utils/schema.utils.js +1 -5
- package/{esm → dist}/src/utils/source-builder.d.ts +5 -6
- package/{esm → dist}/src/utils/source-builder.js +19 -54
- package/{script → dist}/src/utils/string-builder/options.d.ts +0 -1
- package/{script → dist}/src/utils/string-builder/string-builder.d.ts +2 -3
- package/{esm → dist}/src/utils/string-builder/string-builder.js +2 -12
- package/{esm → dist}/src/utils/string-builder/utils.d.ts +2 -3
- package/{esm → dist}/src/utils/string-builder/utils.js +4 -6
- package/{script → dist}/src/utils/string.utils.d.ts +2 -3
- package/{esm → dist}/src/utils/string.utils.js +9 -15
- package/{esm → dist}/src/utils/string.utils.types.d.ts +0 -1
- package/{esm → dist}/src/utils/type.utils.d.ts +0 -1
- package/{script → dist}/src/utils/yaml-info.d.ts +0 -1
- package/{esm → dist}/src/utils/yaml-info.js +9 -6
- package/package.json +23 -16
- package/esm/_dnt.shims.d.ts +0 -11
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -66
- package/esm/mod.d.ts +0 -32
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/src/ast/node.d.ts +0 -17
- package/esm/src/ast/node.d.ts.map +0 -1
- package/esm/src/codegen/config.d.ts.map +0 -1
- package/esm/src/codegen/endpoints-generator.d.ts +0 -18
- package/esm/src/codegen/endpoints-generator.d.ts.map +0 -1
- package/esm/src/codegen/generator.d.ts +0 -39
- package/esm/src/codegen/generator.d.ts.map +0 -1
- package/esm/src/codegen/internal-utils.d.ts.map +0 -1
- package/esm/src/codegen/schemas-generator.d.ts +0 -19
- package/esm/src/codegen/schemas-generator.d.ts.map +0 -1
- package/esm/src/codegen/services-generator.d.ts.map +0 -1
- package/esm/src/codegen/types.d.ts +0 -19
- package/esm/src/codegen/types.d.ts.map +0 -1
- package/esm/src/collect/collector.d.ts +0 -5
- package/esm/src/collect/collector.d.ts.map +0 -1
- package/esm/src/collect/helpers.d.ts.map +0 -1
- package/esm/src/collect/types.d.ts +0 -14
- package/esm/src/collect/types.d.ts.map +0 -1
- package/esm/src/internal-utils.d.ts.map +0 -1
- package/esm/src/parse/deref-proxy.d.ts +0 -4
- package/esm/src/parse/deref-proxy.d.ts.map +0 -1
- package/esm/src/parse/openapi-types.d.ts.map +0 -1
- package/esm/src/parse/parser.d.ts.map +0 -1
- package/esm/src/parse/types.d.ts +0 -28
- package/esm/src/parse/types.d.ts.map +0 -1
- package/esm/src/transform/api-types.d.ts +0 -211
- package/esm/src/transform/api-types.d.ts.map +0 -1
- package/esm/src/transform/helpers.d.ts.map +0 -1
- package/esm/src/transform/transform-document.d.ts +0 -5
- package/esm/src/transform/transform-document.d.ts.map +0 -1
- package/esm/src/transform/transform-endpoint.d.ts.map +0 -1
- package/esm/src/transform/transform-schema.d.ts +0 -6
- package/esm/src/transform/transform-schema.d.ts.map +0 -1
- package/esm/src/transform/transformer.d.ts +0 -5
- package/esm/src/transform/transformer.d.ts.map +0 -1
- package/esm/src/transform/types.d.ts.map +0 -1
- package/esm/src/utils/action-provider.d.ts +0 -29
- package/esm/src/utils/action-provider.d.ts.map +0 -1
- package/esm/src/utils/api-data.utils.d.ts.map +0 -1
- package/esm/src/utils/array.utils.d.ts.map +0 -1
- package/esm/src/utils/asset-manager.d.ts +0 -9
- package/esm/src/utils/asset-manager.d.ts.map +0 -1
- package/esm/src/utils/class.utils.d.ts.map +0 -1
- package/esm/src/utils/common.utils.d.ts +0 -16
- package/esm/src/utils/common.utils.d.ts.map +0 -1
- package/esm/src/utils/condition.d.ts.map +0 -1
- package/esm/src/utils/endpoint.utils.d.ts +0 -3
- package/esm/src/utils/endpoint.utils.d.ts.map +0 -1
- package/esm/src/utils/error.utils.d.ts.map +0 -1
- package/esm/src/utils/factory.d.ts.map +0 -1
- package/esm/src/utils/file-system.utils.d.ts.map +0 -1
- package/esm/src/utils/generator.utils.d.ts.map +0 -1
- package/esm/src/utils/object.utils.d.ts.map +0 -1
- package/esm/src/utils/schema.utils.d.ts.map +0 -1
- package/esm/src/utils/source-builder.d.ts.map +0 -1
- package/esm/src/utils/string-builder/options.d.ts +0 -15
- package/esm/src/utils/string-builder/options.d.ts.map +0 -1
- package/esm/src/utils/string-builder/string-builder.d.ts +0 -73
- package/esm/src/utils/string-builder/string-builder.d.ts.map +0 -1
- package/esm/src/utils/string-builder/utils.d.ts.map +0 -1
- package/esm/src/utils/string.utils.d.ts +0 -149
- package/esm/src/utils/string.utils.d.ts.map +0 -1
- package/esm/src/utils/string.utils.types.d.ts.map +0 -1
- package/esm/src/utils/type.utils.d.ts.map +0 -1
- package/esm/src/utils/yaml-info.d.ts +0 -13
- package/esm/src/utils/yaml-info.d.ts.map +0 -1
- package/script/_dnt.shims.d.ts +0 -11
- package/script/_dnt.shims.d.ts.map +0 -1
- package/script/_dnt.shims.js +0 -75
- package/script/mod.d.ts +0 -32
- package/script/mod.d.ts.map +0 -1
- package/script/mod.js +0 -36
- package/script/package.json +0 -3
- package/script/src/ast/node.d.ts.map +0 -1
- package/script/src/ast/node.js +0 -33
- package/script/src/codegen/config.d.ts +0 -36
- package/script/src/codegen/config.d.ts.map +0 -1
- package/script/src/codegen/config.js +0 -12
- package/script/src/codegen/endpoints-generator.d.ts.map +0 -1
- package/script/src/codegen/endpoints-generator.js +0 -35
- package/script/src/codegen/generator.d.ts.map +0 -1
- package/script/src/codegen/generator.js +0 -134
- package/script/src/codegen/internal-utils.d.ts +0 -2
- package/script/src/codegen/internal-utils.d.ts.map +0 -1
- package/script/src/codegen/internal-utils.js +0 -9
- package/script/src/codegen/schemas-generator.d.ts.map +0 -1
- package/script/src/codegen/schemas-generator.js +0 -49
- package/script/src/codegen/services-generator.d.ts +0 -18
- package/script/src/codegen/services-generator.d.ts.map +0 -1
- package/script/src/codegen/services-generator.js +0 -35
- package/script/src/codegen/types.d.ts.map +0 -1
- package/script/src/codegen/types.js +0 -2
- package/script/src/collect/collector.d.ts +0 -5
- package/script/src/collect/collector.d.ts.map +0 -1
- package/script/src/collect/collector.js +0 -122
- package/script/src/collect/helpers.d.ts +0 -5
- package/script/src/collect/helpers.d.ts.map +0 -1
- package/script/src/collect/helpers.js +0 -37
- package/script/src/collect/types.d.ts.map +0 -1
- package/script/src/collect/types.js +0 -2
- package/script/src/internal-utils.d.ts +0 -2
- package/script/src/internal-utils.d.ts.map +0 -1
- package/script/src/internal-utils.js +0 -6
- package/script/src/parse/deref-proxy.d.ts +0 -4
- package/script/src/parse/deref-proxy.d.ts.map +0 -1
- package/script/src/parse/deref-proxy.js +0 -71
- package/script/src/parse/openapi-types.d.ts +0 -902
- package/script/src/parse/openapi-types.d.ts.map +0 -1
- package/script/src/parse/openapi-types.js +0 -2
- package/script/src/parse/parser.d.ts +0 -18
- package/script/src/parse/parser.d.ts.map +0 -1
- package/script/src/parse/parser.js +0 -183
- package/script/src/parse/types.d.ts.map +0 -1
- package/script/src/parse/types.js +0 -5
- package/script/src/transform/api-types.d.ts.map +0 -1
- package/script/src/transform/api-types.js +0 -2
- package/script/src/transform/helpers.d.ts +0 -58
- package/script/src/transform/helpers.d.ts.map +0 -1
- package/script/src/transform/helpers.js +0 -211
- package/script/src/transform/transform-document.d.ts +0 -5
- package/script/src/transform/transform-document.d.ts.map +0 -1
- package/script/src/transform/transform-document.js +0 -34
- package/script/src/transform/transform-endpoint.d.ts +0 -5
- package/script/src/transform/transform-endpoint.d.ts.map +0 -1
- package/script/src/transform/transform-endpoint.js +0 -273
- package/script/src/transform/transform-schema.d.ts +0 -6
- package/script/src/transform/transform-schema.d.ts.map +0 -1
- package/script/src/transform/transform-schema.js +0 -196
- package/script/src/transform/transformer.d.ts +0 -5
- package/script/src/transform/transformer.d.ts.map +0 -1
- package/script/src/transform/transformer.js +0 -45
- package/script/src/transform/types.d.ts +0 -36
- package/script/src/transform/types.d.ts.map +0 -1
- package/script/src/transform/types.js +0 -6
- package/script/src/utils/action-provider.d.ts.map +0 -1
- package/script/src/utils/action-provider.js +0 -33
- package/script/src/utils/api-data.utils.d.ts +0 -3
- package/script/src/utils/api-data.utils.d.ts.map +0 -1
- package/script/src/utils/api-data.utils.js +0 -42
- package/script/src/utils/array.utils.d.ts +0 -2
- package/script/src/utils/array.utils.d.ts.map +0 -1
- package/script/src/utils/array.utils.js +0 -10
- package/script/src/utils/asset-manager.d.ts.map +0 -1
- package/script/src/utils/asset-manager.js +0 -55
- package/script/src/utils/class.utils.d.ts +0 -8
- package/script/src/utils/class.utils.d.ts.map +0 -1
- package/script/src/utils/class.utils.js +0 -33
- package/script/src/utils/common.utils.d.ts.map +0 -1
- package/script/src/utils/common.utils.js +0 -84
- package/script/src/utils/condition.d.ts +0 -4
- package/script/src/utils/condition.d.ts.map +0 -1
- package/script/src/utils/condition.js +0 -7
- package/script/src/utils/endpoint.utils.d.ts +0 -3
- package/script/src/utils/endpoint.utils.d.ts.map +0 -1
- package/script/src/utils/endpoint.utils.js +0 -11
- package/script/src/utils/error.utils.d.ts +0 -2
- package/script/src/utils/error.utils.d.ts.map +0 -1
- package/script/src/utils/error.utils.js +0 -6
- package/script/src/utils/factory.d.ts +0 -21
- package/script/src/utils/factory.d.ts.map +0 -1
- package/script/src/utils/factory.js +0 -33
- package/script/src/utils/file-system.utils.d.ts +0 -11
- package/script/src/utils/file-system.utils.d.ts.map +0 -1
- package/script/src/utils/file-system.utils.js +0 -79
- package/script/src/utils/generator.utils.d.ts +0 -2
- package/script/src/utils/generator.utils.d.ts.map +0 -1
- package/script/src/utils/generator.utils.js +0 -9
- package/script/src/utils/object.utils.d.ts +0 -3
- package/script/src/utils/object.utils.d.ts.map +0 -1
- package/script/src/utils/object.utils.js +0 -40
- package/script/src/utils/schema.utils.d.ts +0 -12
- package/script/src/utils/schema.utils.d.ts.map +0 -1
- package/script/src/utils/schema.utils.js +0 -206
- package/script/src/utils/source-builder.d.ts +0 -236
- package/script/src/utils/source-builder.d.ts.map +0 -1
- package/script/src/utils/source-builder.js +0 -458
- package/script/src/utils/string-builder/options.d.ts.map +0 -1
- package/script/src/utils/string-builder/options.js +0 -10
- package/script/src/utils/string-builder/string-builder.d.ts.map +0 -1
- package/script/src/utils/string-builder/string-builder.js +0 -153
- package/script/src/utils/string-builder/utils.d.ts +0 -22
- package/script/src/utils/string-builder/utils.d.ts.map +0 -1
- package/script/src/utils/string-builder/utils.js +0 -37
- package/script/src/utils/string.utils.d.ts.map +0 -1
- package/script/src/utils/string.utils.js +0 -382
- package/script/src/utils/string.utils.types.d.ts +0 -150
- package/script/src/utils/string.utils.types.d.ts.map +0 -1
- package/script/src/utils/string.utils.types.js +0 -2
- package/script/src/utils/type.utils.d.ts +0 -57
- package/script/src/utils/type.utils.d.ts.map +0 -1
- package/script/src/utils/type.utils.js +0 -10
- package/script/src/utils/yaml-info.d.ts.map +0 -1
- package/script/src/utils/yaml-info.js +0 -38
- package/src/_dnt.shims.ts +0 -69
- package/src/mod.ts +0 -35
- package/src/src/ast/node.ts +0 -46
- package/src/src/codegen/config.ts +0 -50
- package/src/src/codegen/endpoints-generator.ts +0 -72
- package/src/src/codegen/generator.ts +0 -192
- package/src/src/codegen/internal-utils.ts +0 -6
- package/src/src/codegen/schemas-generator.ts +0 -87
- package/src/src/codegen/services-generator.ts +0 -77
- package/src/src/codegen/types.ts +0 -37
- package/src/src/collect/collector.ts +0 -142
- package/src/src/collect/helpers.ts +0 -36
- package/src/src/collect/types.ts +0 -21
- package/src/src/internal-utils.ts +0 -5
- package/src/src/parse/deref-proxy.ts +0 -70
- package/src/src/parse/openapi-types.ts +0 -953
- package/src/src/parse/parser.ts +0 -206
- package/src/src/parse/types.ts +0 -28
- package/src/src/transform/api-types.ts +0 -259
- package/src/src/transform/helpers.ts +0 -251
- package/src/src/transform/transform-document.ts +0 -35
- package/src/src/transform/transform-endpoint.ts +0 -332
- package/src/src/transform/transform-schema.ts +0 -232
- package/src/src/transform/transformer.ts +0 -53
- package/src/src/transform/types.ts +0 -52
- package/src/src/utils/action-provider.ts +0 -58
- package/src/src/utils/api-data.utils.ts +0 -48
- package/src/src/utils/array.utils.ts +0 -7
- package/src/src/utils/asset-manager.ts +0 -51
- package/src/src/utils/class.utils.ts +0 -40
- package/src/src/utils/common.utils.ts +0 -86
- package/src/src/utils/condition.ts +0 -7
- package/src/src/utils/endpoint.utils.ts +0 -10
- package/src/src/utils/error.utils.ts +0 -3
- package/src/src/utils/factory.ts +0 -42
- package/src/src/utils/file-system.utils.ts +0 -97
- package/src/src/utils/generator.utils.ts +0 -6
- package/src/src/utils/object.utils.ts +0 -32
- package/src/src/utils/schema.utils.ts +0 -240
- package/src/src/utils/source-builder.ts +0 -597
- package/src/src/utils/string-builder/options.ts +0 -19
- package/src/src/utils/string-builder/string-builder.ts +0 -165
- package/src/src/utils/string-builder/utils.ts +0 -69
- package/src/src/utils/string.utils.ts +0 -394
- package/src/src/utils/string.utils.types.ts +0 -179
- package/src/src/utils/type.utils.ts +0 -93
- package/src/src/utils/yaml-info.ts +0 -48
- /package/{esm → dist}/mod.js +0 -0
- /package/{esm → dist}/src/codegen/config.js +0 -0
- /package/{esm → dist}/src/codegen/types.js +0 -0
- /package/{esm → dist}/src/collect/helpers.js +0 -0
- /package/{esm → dist}/src/collect/types.js +0 -0
- /package/{esm → dist}/src/internal-utils.js +0 -0
- /package/{esm → dist}/src/parse/openapi-types.js +0 -0
- /package/{esm → dist}/src/parse/types.js +0 -0
- /package/{esm → dist}/src/transform/api-types.js +0 -0
- /package/{esm → dist}/src/transform/transformer.js +0 -0
- /package/{esm → dist}/src/transform/types.js +0 -0
- /package/{esm → dist}/src/utils/api-data.utils.js +0 -0
- /package/{esm → dist}/src/utils/array.utils.js +0 -0
- /package/{esm → dist}/src/utils/common.utils.js +0 -0
- /package/{esm → dist}/src/utils/condition.js +0 -0
- /package/{esm → dist}/src/utils/endpoint.utils.js +0 -0
- /package/{esm → dist}/src/utils/error.utils.js +0 -0
- /package/{esm → dist}/src/utils/file-system.utils.js +0 -0
- /package/{esm → dist}/src/utils/generator.utils.js +0 -0
- /package/{esm → dist}/src/utils/string-builder/options.js +0 -0
- /package/{esm → dist}/src/utils/string.utils.types.js +0 -0
- /package/{esm → dist}/src/utils/type.utils.js +0 -0
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.builderTemplate = exports.SourceBuilder = exports.defaultSourceBuilderOptions = void 0;
|
|
4
|
-
exports.getIndentString = getIndentString;
|
|
5
|
-
const common_utils_js_1 = require("./common.utils.js");
|
|
6
|
-
const condition_js_1 = require("./condition.js");
|
|
7
|
-
const options_js_1 = require("./string-builder/options.js");
|
|
8
|
-
const string_builder_js_1 = require("./string-builder/string-builder.js");
|
|
9
|
-
const string_utils_js_1 = require("./string.utils.js");
|
|
10
|
-
/**
|
|
11
|
-
* Default options for the `SourceBuilder` class.
|
|
12
|
-
*/
|
|
13
|
-
exports.defaultSourceBuilderOptions = {
|
|
14
|
-
...options_js_1.defaultStringBuilderOptions,
|
|
15
|
-
indent: { type: 'spaces', count: 2 },
|
|
16
|
-
};
|
|
17
|
-
function getIndentString(options) {
|
|
18
|
-
return options.type === 'tabs' ? '\t' : ' '.repeat(options.count);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Represents an in-memory source file.
|
|
22
|
-
*/
|
|
23
|
-
class SourceBuilder extends string_builder_js_1.StringBuilder {
|
|
24
|
-
/**
|
|
25
|
-
* Gets the options used by this instance.
|
|
26
|
-
*/
|
|
27
|
-
get options() {
|
|
28
|
-
return this.__options;
|
|
29
|
-
}
|
|
30
|
-
get isCurrentLineEmpty() {
|
|
31
|
-
return this._isCurrentLineEmpty;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Initializes a new instance of the SourceBuilder class.
|
|
35
|
-
* @param options The options to use for this instance.
|
|
36
|
-
*/
|
|
37
|
-
constructor(options) {
|
|
38
|
-
super(options);
|
|
39
|
-
Object.defineProperty(this, "__options", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "_indentString", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
|
-
Object.defineProperty(this, "_isLineIndented", {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: false
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(this, "_isLastLineEmpty", {
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
writable: true,
|
|
61
|
-
value: true
|
|
62
|
-
});
|
|
63
|
-
Object.defineProperty(this, "_isCurrentLineEmpty", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: true
|
|
68
|
-
});
|
|
69
|
-
Object.defineProperty(this, "_linePrefixNodes", {
|
|
70
|
-
enumerable: true,
|
|
71
|
-
configurable: true,
|
|
72
|
-
writable: true,
|
|
73
|
-
value: []
|
|
74
|
-
});
|
|
75
|
-
this.__options = { ...exports.defaultSourceBuilderOptions, ...options };
|
|
76
|
-
this._indentString = getIndentString(this.__options.indent);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Creates a new instance of the SourceBuilder class from a string.
|
|
80
|
-
* @param str The string to use as the initial content of the builder.
|
|
81
|
-
* @param options The options to use for this instance.
|
|
82
|
-
* @returns A new instance of the SourceBuilder class.
|
|
83
|
-
*/
|
|
84
|
-
static fromString(str, options) {
|
|
85
|
-
const builder = new SourceBuilder(options);
|
|
86
|
-
builder.append(str);
|
|
87
|
-
return builder;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Builds a string using a callback function that receives a `SourceBuilder` instance.
|
|
91
|
-
* @param buildAction The callback function that receives a `SourceBuilder` instance to build the string.
|
|
92
|
-
* @param options The options to use for the `SourceBuilder` instance.
|
|
93
|
-
* @returns The string built by the `SourceBuilder` instance.
|
|
94
|
-
*/
|
|
95
|
-
static build(buildAction, options) {
|
|
96
|
-
const builder = new SourceBuilder(options);
|
|
97
|
-
builder.append(buildAction);
|
|
98
|
-
return builder.toString();
|
|
99
|
-
}
|
|
100
|
-
appendSingle(value) {
|
|
101
|
-
var _a;
|
|
102
|
-
if ((0, common_utils_js_1.isNullish)(value))
|
|
103
|
-
return;
|
|
104
|
-
if (Array.isArray(value)) {
|
|
105
|
-
for (const part of value) {
|
|
106
|
-
this.appendSingle(part);
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (typeof value === 'function') {
|
|
111
|
-
value(this);
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
115
|
-
value = value.toString();
|
|
116
|
-
}
|
|
117
|
-
if (typeof value === 'object' && value !== null && '__type' in value && value.__type === 'append-value-group') {
|
|
118
|
-
this.forEach(value.values, (builder, part) => builder.append(part), { separator: (_a = value.separator) !== null && _a !== void 0 ? _a : undefined });
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (typeof value !== 'string') {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
let lineStartIndex = 0;
|
|
125
|
-
for (let i = 0; i < value.length; i++) {
|
|
126
|
-
if (value[i] === '\r')
|
|
127
|
-
continue;
|
|
128
|
-
if (value[i] === '\n') {
|
|
129
|
-
let lineLength = i - lineStartIndex;
|
|
130
|
-
for (let j = i; j > 0 && value[j - 1] === '\r'; j--) {
|
|
131
|
-
lineLength--;
|
|
132
|
-
}
|
|
133
|
-
if (lineLength > 0) {
|
|
134
|
-
if (!this._isLineIndented) {
|
|
135
|
-
this.appendIndent();
|
|
136
|
-
}
|
|
137
|
-
this.str += (0, string_utils_js_1.removeStr)(value.substring(lineStartIndex, i), '\r');
|
|
138
|
-
}
|
|
139
|
-
this._isLastLineEmpty = this._isCurrentLineEmpty;
|
|
140
|
-
if (this._isCurrentLineEmpty && this._linePrefixNodes.some((x) => x.kind !== 'indent')) {
|
|
141
|
-
this.appendIndent();
|
|
142
|
-
}
|
|
143
|
-
this.str = (0, string_utils_js_1.trimEnd)(this.str, false) + '\n';
|
|
144
|
-
this._isLineIndented = false;
|
|
145
|
-
this._isCurrentLineEmpty = true;
|
|
146
|
-
lineStartIndex = i + 1;
|
|
147
|
-
}
|
|
148
|
-
if (value[i] !== '\r' && value[i] !== '\n' && value[i] !== ' ' && value[i] !== '\t') {
|
|
149
|
-
this._isCurrentLineEmpty = false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (!this._isLineIndented && lineStartIndex < value.length) {
|
|
153
|
-
this.appendIndent();
|
|
154
|
-
this._isLineIndented = true;
|
|
155
|
-
}
|
|
156
|
-
this.str += (0, string_utils_js_1.removeStr)(value.substring(lineStartIndex), '\r');
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
160
|
-
* @param condition The condition to check before appending the specified value.
|
|
161
|
-
* @param value The string(s) to append.
|
|
162
|
-
* @returns The current SourceBuilder.
|
|
163
|
-
*/
|
|
164
|
-
appendIf(condition, ...value) {
|
|
165
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
166
|
-
return this.append(...value);
|
|
167
|
-
}
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
172
|
-
* @param value The string(s) to append.
|
|
173
|
-
* @returns The current SourceBuilder.
|
|
174
|
-
*/
|
|
175
|
-
appendLine(...value) {
|
|
176
|
-
return this.append(...value, '\n');
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
180
|
-
* @param condition The condition to check before appending the specified value.
|
|
181
|
-
* @param value The string(s) to append.
|
|
182
|
-
* @returns The current SourceBuilder.
|
|
183
|
-
*/
|
|
184
|
-
appendLineIf(condition, ...value) {
|
|
185
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
186
|
-
return this.appendLine(...value);
|
|
187
|
-
}
|
|
188
|
-
return this;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Appends the specified values to this source builder with the specified line prefix.
|
|
192
|
-
* @param {string} prefix - The line prefix to use.
|
|
193
|
-
* @param {...(string|null|undefined)} value - The values to append.
|
|
194
|
-
* @returns {SourceBuilder} This source builder instance.
|
|
195
|
-
*/
|
|
196
|
-
appendWithLinePrefix(prefix, ...value) {
|
|
197
|
-
this._linePrefixNodes.push({ chars: prefix, kind: 'prefix' });
|
|
198
|
-
try {
|
|
199
|
-
this.append(...value);
|
|
200
|
-
}
|
|
201
|
-
finally {
|
|
202
|
-
this._linePrefixNodes.pop();
|
|
203
|
-
}
|
|
204
|
-
return this;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
208
|
-
* @param {string} prefix - The line prefix to use.
|
|
209
|
-
* @param {...(string|null|undefined)} value - The values to append.
|
|
210
|
-
* @returns {SourceBuilder} This source builder instance.
|
|
211
|
-
*/
|
|
212
|
-
appendLineWithLinePrefix(prefix, ...value) {
|
|
213
|
-
return this.appendWithLinePrefix(prefix, ...value, '\n');
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
217
|
-
* @param condition The condition to check before prepending the specified value.
|
|
218
|
-
* @param value The string(s) to prepend.
|
|
219
|
-
* @returns The current SourceBuilder.
|
|
220
|
-
*/
|
|
221
|
-
prependIf(condition, ...value) {
|
|
222
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
223
|
-
this.prepend(...value);
|
|
224
|
-
}
|
|
225
|
-
return this;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
229
|
-
* @param condition The condition to check before appending the specified value.
|
|
230
|
-
* @param value The string(s) to prepend.
|
|
231
|
-
* @returns The current SourceBuilder.
|
|
232
|
-
*/
|
|
233
|
-
prependLineIf(condition, ...value) {
|
|
234
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
235
|
-
this.prependLine(...value);
|
|
236
|
-
}
|
|
237
|
-
return this;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Ensures that the current line and the one before is empty or consists only of whitespace characters.
|
|
241
|
-
* @returns A reference to this instance.
|
|
242
|
-
*/
|
|
243
|
-
ensurePreviousLineEmpty() {
|
|
244
|
-
if (!this._isCurrentLineEmpty) {
|
|
245
|
-
this.appendLine();
|
|
246
|
-
}
|
|
247
|
-
if (!this._isLastLineEmpty) {
|
|
248
|
-
this.appendLine();
|
|
249
|
-
}
|
|
250
|
-
return this;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
254
|
-
* @returns A reference to this instance.
|
|
255
|
-
*/
|
|
256
|
-
ensureCurrentLineEmpty() {
|
|
257
|
-
if (!this._isCurrentLineEmpty) {
|
|
258
|
-
this.appendLine();
|
|
259
|
-
}
|
|
260
|
-
return this;
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Pretends that the current line and the one before is empty or consists only of whitespace characters.
|
|
264
|
-
* @returns A reference to this instance.
|
|
265
|
-
*/
|
|
266
|
-
pretendPreviousLineEmpty() {
|
|
267
|
-
this._isLastLineEmpty = true;
|
|
268
|
-
this._isCurrentLineEmpty = true;
|
|
269
|
-
return this;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Pretends that the current line is empty or consists only of whitespace characters.
|
|
273
|
-
* @returns A reference to this instance.
|
|
274
|
-
*/
|
|
275
|
-
pretendCurrentLineEmpty() {
|
|
276
|
-
this._isCurrentLineEmpty = true;
|
|
277
|
-
return this;
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Inserts specified content if the specified condition is true.
|
|
281
|
-
* @param condition The condition to check before inserting content.
|
|
282
|
-
* @param builderFn The function to add content if the condition is true.
|
|
283
|
-
* @param elseBuilderFn The function to add content if the condition is false.
|
|
284
|
-
* @returns A reference to this instance.
|
|
285
|
-
*/
|
|
286
|
-
if(condition, builderFn, elseBuilderFn) {
|
|
287
|
-
return (0, condition_js_1.evalCondition)(condition) ? this.append(builderFn) : this.append(elseBuilderFn);
|
|
288
|
-
}
|
|
289
|
-
switch(value, cases, defaultBuilderFn, equals) {
|
|
290
|
-
var _a;
|
|
291
|
-
if ((typeof value === 'string' || typeof value === 'number') && !Array.isArray(cases)) {
|
|
292
|
-
return this.append((_a = cases[value]) !== null && _a !== void 0 ? _a : defaultBuilderFn);
|
|
293
|
-
}
|
|
294
|
-
else if (Array.isArray(cases)) {
|
|
295
|
-
for (const c of cases) {
|
|
296
|
-
if (equals ? equals(value, c.case) : value === c.case) {
|
|
297
|
-
return this.append(c.value);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
return this.append(defaultBuilderFn);
|
|
301
|
-
}
|
|
302
|
-
return this;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
306
|
-
* @param builderFn The function to add indented content or the content itself.
|
|
307
|
-
* @param condition The condition to check before adding indentation.
|
|
308
|
-
* @returns A reference to this instance.
|
|
309
|
-
*/
|
|
310
|
-
indent(value) {
|
|
311
|
-
this._linePrefixNodes.push({ chars: this._indentString, kind: 'indent' });
|
|
312
|
-
try {
|
|
313
|
-
this.append(value);
|
|
314
|
-
}
|
|
315
|
-
finally {
|
|
316
|
-
this._linePrefixNodes.pop();
|
|
317
|
-
}
|
|
318
|
-
return this;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Adds one indentation level if the specified condition is true. If the current line already contains characters, only subsequent lines are affected.
|
|
322
|
-
* @param builderFn The function to add indented content or the content itself.
|
|
323
|
-
* @param condition The condition to check before adding indentation.
|
|
324
|
-
* @returns A reference to this instance.
|
|
325
|
-
*/
|
|
326
|
-
indentIf(condition, value) {
|
|
327
|
-
return (0, condition_js_1.evalCondition)(condition) ? this.indent(value) : this.append(value);
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Adds parentheses around the specified content.
|
|
331
|
-
* @param brackets The brackets to use.
|
|
332
|
-
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
333
|
-
* @param options Options for the parentheses.
|
|
334
|
-
* @returns A reference to this instance.
|
|
335
|
-
*/
|
|
336
|
-
parenthesize(brackets, value, options) {
|
|
337
|
-
var _a, _b, _c, _d, _e, _f;
|
|
338
|
-
const multiline = (_a = options === null || options === void 0 ? void 0 : options.multiline) !== null && _a !== void 0 ? _a : false;
|
|
339
|
-
const indent = (_b = options === null || options === void 0 ? void 0 : options.indent) !== null && _b !== void 0 ? _b : true;
|
|
340
|
-
const pretendEmpty = (_c = options === null || options === void 0 ? void 0 : options.pretendEmpty) !== null && _c !== void 0 ? _c : true;
|
|
341
|
-
if (multiline) {
|
|
342
|
-
this.appendLine((_d = brackets[0]) !== null && _d !== void 0 ? _d : '');
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
this.append((_e = brackets[0]) !== null && _e !== void 0 ? _e : '');
|
|
346
|
-
}
|
|
347
|
-
if (pretendEmpty)
|
|
348
|
-
this.pretendPreviousLineEmpty();
|
|
349
|
-
if (indent !== false) {
|
|
350
|
-
this.indent(value);
|
|
351
|
-
}
|
|
352
|
-
else {
|
|
353
|
-
this.append(value);
|
|
354
|
-
}
|
|
355
|
-
if (multiline)
|
|
356
|
-
this.ensureCurrentLineEmpty();
|
|
357
|
-
this.append((_f = brackets[1]) !== null && _f !== void 0 ? _f : '');
|
|
358
|
-
return this;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Adds parentheses around the specified content if the specified condition is true.
|
|
362
|
-
* @param condition The condition to check before adding parentheses.
|
|
363
|
-
* @param brackets The brackets to use.
|
|
364
|
-
* @param value The function to add content inside parentheses or one string that should be parenthesized.
|
|
365
|
-
* @param options Options for the parentheses.
|
|
366
|
-
* @returns A reference to this instance.
|
|
367
|
-
*/
|
|
368
|
-
parenthesizeIf(condition, brackets, value, options) {
|
|
369
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
370
|
-
return this.parenthesize(brackets, value, options);
|
|
371
|
-
}
|
|
372
|
-
else if (options === null || options === void 0 ? void 0 : options.indent) {
|
|
373
|
-
return this.indent(value);
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
return this.append(value);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Adds content for each item in the specified array.
|
|
381
|
-
* @param items The items to add content for.
|
|
382
|
-
* @param builderFn The function to add content for each item.
|
|
383
|
-
* @param options The options for the loop.
|
|
384
|
-
* @returns A reference to this instance.
|
|
385
|
-
*/
|
|
386
|
-
forEach(items, builderFn, options) {
|
|
387
|
-
var _a;
|
|
388
|
-
const condition = (_a = options === null || options === void 0 ? void 0 : options.condition) !== null && _a !== void 0 ? _a : true;
|
|
389
|
-
if ((options === null || options === void 0 ? void 0 : options.condition) === false)
|
|
390
|
-
return this;
|
|
391
|
-
const seperator = options === null || options === void 0 ? void 0 : options.separator;
|
|
392
|
-
let previousIndex = -1;
|
|
393
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
394
|
-
let previousItem = undefined;
|
|
395
|
-
let index = 0;
|
|
396
|
-
for (const item of items) {
|
|
397
|
-
if ((0, condition_js_1.evalCondition)(condition, item)) {
|
|
398
|
-
if (previousIndex >= 0 && seperator) {
|
|
399
|
-
if (typeof seperator === 'string') {
|
|
400
|
-
this.append(seperator);
|
|
401
|
-
}
|
|
402
|
-
else {
|
|
403
|
-
seperator(this, previousItem, item, previousIndex, index);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
builderFn(this, item, index);
|
|
407
|
-
previousIndex = index;
|
|
408
|
-
previousItem = item;
|
|
409
|
-
}
|
|
410
|
-
index++;
|
|
411
|
-
}
|
|
412
|
-
return this;
|
|
413
|
-
}
|
|
414
|
-
forEachIf(condition, items, builderFn, options) {
|
|
415
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
416
|
-
return this.forEach(items, builderFn, options);
|
|
417
|
-
}
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
appendSeparated(items, separator) {
|
|
421
|
-
return this.forEach(items, (builder, item) => builder.append(item), { separator });
|
|
422
|
-
}
|
|
423
|
-
appendSeparatedIf(condition, items, separator) {
|
|
424
|
-
if ((0, condition_js_1.evalCondition)(condition)) {
|
|
425
|
-
return this.appendSeparated(items, separator);
|
|
426
|
-
}
|
|
427
|
-
return this;
|
|
428
|
-
}
|
|
429
|
-
appendIndent() {
|
|
430
|
-
this.str += this._linePrefixNodes.map((n) => n.chars).join('');
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
exports.SourceBuilder = SourceBuilder;
|
|
434
|
-
function _builderTemplate(template, ...substitutions) {
|
|
435
|
-
return (b) => {
|
|
436
|
-
var _a, _b;
|
|
437
|
-
let lastLine = undefined;
|
|
438
|
-
for (let i = template.length - 1; i >= 0; i--) {
|
|
439
|
-
if (template[i].includes('\n')) {
|
|
440
|
-
lastLine = template[i];
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
const indent = (_b = (_a = lastLine === null || lastLine === void 0 ? void 0 : lastLine.match(/\n( *).*$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
|
|
445
|
-
const regex = new RegExp(`\\n {0,${indent.length}}`, 'g');
|
|
446
|
-
for (let i = 0; i < template.length; i++) {
|
|
447
|
-
b.append(template[i].replace(regex, '\n'));
|
|
448
|
-
if (i < substitutions.length)
|
|
449
|
-
b.append(substitutions[i]);
|
|
450
|
-
}
|
|
451
|
-
};
|
|
452
|
-
}
|
|
453
|
-
const _builderTemplateExtensions = {
|
|
454
|
-
indent: (template, ...substitutions) => {
|
|
455
|
-
return (b) => b.indent(_builderTemplate(template, ...substitutions));
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
exports.builderTemplate = Object.assign(_builderTemplate, _builderTemplateExtensions);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/src/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 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultStringBuilderOptions = void 0;
|
|
4
|
-
const node_os_1 = require("node:os");
|
|
5
|
-
/**
|
|
6
|
-
* Default options for the `StringBuilder` class.
|
|
7
|
-
*/
|
|
8
|
-
exports.defaultStringBuilderOptions = {
|
|
9
|
-
newLine: node_os_1.EOL,
|
|
10
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"string-builder.d.ts","sourceRoot":"","sources":["../../../../src/src/utils/string-builder/string-builder.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAA+B,KAAK,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEtF,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,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StringBuilder = exports.AdditionalAppendsSymbol = void 0;
|
|
4
|
-
const common_utils_js_1 = require("../common.utils.js");
|
|
5
|
-
const options_js_1 = require("./options.js");
|
|
6
|
-
exports.AdditionalAppendsSymbol = Symbol('AdditionalAppends');
|
|
7
|
-
/**
|
|
8
|
-
* Represents a mutable string of characters.
|
|
9
|
-
*/
|
|
10
|
-
class StringBuilder {
|
|
11
|
-
[exports.AdditionalAppendsSymbol](_) {
|
|
12
|
-
throw new Error('This method should never be called.');
|
|
13
|
-
}
|
|
14
|
-
get options() {
|
|
15
|
-
return this._options;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* Initializes a new instance of the StringBuilder class.
|
|
19
|
-
* @param options The options.
|
|
20
|
-
*/
|
|
21
|
-
constructor(options) {
|
|
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 };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
38
|
-
* @param str The string to append.
|
|
39
|
-
* @param options The options.
|
|
40
|
-
* @returns A new StringBuilder instance.
|
|
41
|
-
*/
|
|
42
|
-
static fromString(str, options) {
|
|
43
|
-
const builder = new StringBuilder(options);
|
|
44
|
-
builder.append(str);
|
|
45
|
-
return builder;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Builds a string using a StringBuilder build action.
|
|
49
|
-
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
50
|
-
* @param options The options for the StringBuilder instance.
|
|
51
|
-
* @returns The built string.
|
|
52
|
-
*/
|
|
53
|
-
static build(buildAction, options) {
|
|
54
|
-
const builder = new StringBuilder(options);
|
|
55
|
-
builder.append(buildAction);
|
|
56
|
-
return builder.toString();
|
|
57
|
-
}
|
|
58
|
-
appendSingle(value) {
|
|
59
|
-
if ((0, common_utils_js_1.isNullish)(value))
|
|
60
|
-
return;
|
|
61
|
-
if (Array.isArray(value)) {
|
|
62
|
-
for (const part of value) {
|
|
63
|
-
this.appendSingle(part);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (typeof value === 'string') {
|
|
67
|
-
this.str += value;
|
|
68
|
-
}
|
|
69
|
-
else if (typeof value === 'number' || typeof value === 'boolean') {
|
|
70
|
-
this.str += value.toString();
|
|
71
|
-
}
|
|
72
|
-
else if (typeof value === 'function') {
|
|
73
|
-
value(this);
|
|
74
|
-
}
|
|
75
|
-
else if (typeof value === 'object' &&
|
|
76
|
-
value !== null &&
|
|
77
|
-
'__type' in value &&
|
|
78
|
-
value.__type === 'append-value-group') {
|
|
79
|
-
let isFirst = true;
|
|
80
|
-
for (const part of value.values) {
|
|
81
|
-
if (!isFirst && value.separator) {
|
|
82
|
-
this.append(value.separator);
|
|
83
|
-
}
|
|
84
|
-
this.appendSingle(part);
|
|
85
|
-
isFirst = false;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Appends one or more strings to the end of the current StringBuilder.
|
|
91
|
-
* @param value The string(s) to append.
|
|
92
|
-
* @returns The current StringBuilder.
|
|
93
|
-
*/
|
|
94
|
-
append(...value) {
|
|
95
|
-
for (const part of value) {
|
|
96
|
-
this.appendSingle(part);
|
|
97
|
-
}
|
|
98
|
-
return this;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
102
|
-
* @param value
|
|
103
|
-
* @returns
|
|
104
|
-
*/
|
|
105
|
-
appendLine(...value) {
|
|
106
|
-
return this.append(...value, '\n');
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
110
|
-
* @param value The string(s) to prepend.
|
|
111
|
-
* @returns The current StringBuilder.
|
|
112
|
-
*/
|
|
113
|
-
prepend(...value) {
|
|
114
|
-
for (const part of value.reverse()) {
|
|
115
|
-
if ((0, common_utils_js_1.isNullish)(part))
|
|
116
|
-
continue;
|
|
117
|
-
if (typeof part === 'function') {
|
|
118
|
-
const builder = new StringBuilder(this.options);
|
|
119
|
-
part(builder);
|
|
120
|
-
this.str = builder.str + this.str;
|
|
121
|
-
}
|
|
122
|
-
else if (typeof part === 'string') {
|
|
123
|
-
this.str = part + this.str;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
this.str = part.toString() + this.str;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
133
|
-
* @param value The string(s) to prepend.
|
|
134
|
-
* @returns The current StringBuilder.
|
|
135
|
-
*/
|
|
136
|
-
prependLine(...value) {
|
|
137
|
-
return this.prepend(...value, '\n');
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Converts the value of this instance to a string.
|
|
141
|
-
* @returns A string whose value is the same as this instance.
|
|
142
|
-
*/
|
|
143
|
-
toString() {
|
|
144
|
-
return this.str.replace(/\r?\n/g, this._options.newLine);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Removes all characters from the current StringBuilder.
|
|
148
|
-
*/
|
|
149
|
-
clear() {
|
|
150
|
-
this.str = '';
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
exports.StringBuilder = StringBuilder;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import type { Nullable } from '../type.utils.js';
|
|
2
|
-
import type { AdditionalAppendsSymbol, AppendParam, BuilderFn, Primitive, StringBuilder } from './string-builder.js';
|
|
3
|
-
export type BasicAppendValue<TBuilder extends StringBuilder = StringBuilder> = Primitive | BuilderFn<TBuilder> | BasicAppendValueGroup<TBuilder>;
|
|
4
|
-
export type BasicAppendValueGroup<TBuilder extends StringBuilder = StringBuilder> = {
|
|
5
|
-
__type: 'append-value-group';
|
|
6
|
-
values: BasicAppendValue<TBuilder>[];
|
|
7
|
-
separator: string | null;
|
|
8
|
-
};
|
|
9
|
-
export type AppendValue<TBuilder extends StringBuilder = StringBuilder> = NonNullable<AppendParam<TBuilder, Parameters<TBuilder[typeof AdditionalAppendsSymbol]>[0]>>;
|
|
10
|
-
export type AppendValueGroup<TBuilder extends StringBuilder = StringBuilder> = {
|
|
11
|
-
__type: 'append-value-group';
|
|
12
|
-
values: AppendValue<TBuilder>[];
|
|
13
|
-
separator: string | null;
|
|
14
|
-
};
|
|
15
|
-
/** @deprecated Use AppendValue<TBuilder> instead */
|
|
16
|
-
export type TextOrBuilderFn<TBuilder> = string | ((builder: TBuilder) => void);
|
|
17
|
-
export declare function basicAppendValueGroup<TBuilder extends StringBuilder = StringBuilder>(values: Nullable<Nullable<BasicAppendValue<TBuilder>>[]>, separator?: Nullable<string>): BasicAppendValueGroup<TBuilder>;
|
|
18
|
-
export declare function appendValueGroup<TBuilder extends StringBuilder = StringBuilder>(values: Nullable<Nullable<AppendValue<TBuilder>>[]>, separator?: Nullable<string>): AppendValueGroup<TBuilder>;
|
|
19
|
-
export declare function isAppendValue(value: unknown): value is AppendValue<never>;
|
|
20
|
-
export declare function isAppendValueGroup<TBuilder extends StringBuilder = StringBuilder>(value: unknown): value is AppendValueGroup<TBuilder>;
|
|
21
|
-
export declare function concatAppendValues<TBuilder extends StringBuilder = StringBuilder>(...values: AppendValue<TBuilder>[]): AppendValue<TBuilder>;
|
|
22
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/src/utils/string-builder/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAErH,MAAM,MAAM,gBAAgB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,IACvE,SAAS,GACT,SAAS,CAAC,QAAQ,CAAC,GACnB,qBAAqB,CAAC,QAAQ,CAAC,CAAC;AACpC,MAAM,MAAM,qBAAqB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI;IAClF,MAAM,EAAE,oBAAoB,CAAC;IAC7B,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,EAAE,CAAC;IACrC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI,WAAW,CACnF,WAAW,CAAC,QAAQ,EAAE,UAAU,CAAC,QAAQ,CAAC,OAAO,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAC/E,CAAC;AACF,MAAM,MAAM,gBAAgB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,IAAI;IAC7E,MAAM,EAAE,oBAAoB,CAAC;IAC7B,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;IAChC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,oDAAoD;AACpD,MAAM,MAAM,eAAe,CAAC,QAAQ,IAAI,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,IAAI,CAAC,CAAC;AAE/E,wBAAgB,qBAAqB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,EAClF,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EACxD,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC3B,qBAAqB,CAAC,QAAQ,CAAC,CAMjC;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,EAC7E,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EACnD,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC3B,gBAAgB,CAAC,QAAQ,CAAC,CAM5B;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAAC,KAAK,CAAC,CAQzE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,EAC/E,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,gBAAgB,CAAC,QAAQ,CAAC,CAErC;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,SAAS,aAAa,GAAG,aAAa,EAC/E,GAAG,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,EAAE,GACjC,WAAW,CAAC,QAAQ,CAAC,CAEvB"}
|