@goast/core 0.0.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 +11 -0
- package/dist/index.cjs +7 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/codegen/config.cjs +6 -0
- package/dist/lib/codegen/config.cjs.map +1 -0
- package/dist/lib/codegen/config.d.ts +6 -0
- package/dist/lib/codegen/config.js +3 -0
- package/dist/lib/codegen/config.js.map +1 -0
- package/dist/lib/codegen/endpoints-generator.cjs +31 -0
- package/dist/lib/codegen/endpoints-generator.cjs.map +1 -0
- package/dist/lib/codegen/endpoints-generator.d.ts +15 -0
- package/dist/lib/codegen/endpoints-generator.js +27 -0
- package/dist/lib/codegen/endpoints-generator.js.map +1 -0
- package/dist/lib/codegen/generator.cjs +103 -0
- package/dist/lib/codegen/generator.cjs.map +1 -0
- package/dist/lib/codegen/generator.d.ts +36 -0
- package/dist/lib/codegen/generator.js +98 -0
- package/dist/lib/codegen/generator.js.map +1 -0
- package/dist/lib/codegen/index.cjs +10 -0
- package/dist/lib/codegen/index.cjs.map +1 -0
- package/dist/lib/codegen/index.d.ts +6 -0
- package/dist/lib/codegen/index.js +7 -0
- package/dist/lib/codegen/index.js.map +1 -0
- package/dist/lib/codegen/internal-utils.cjs +10 -0
- package/dist/lib/codegen/internal-utils.cjs.map +1 -0
- package/dist/lib/codegen/internal-utils.d.ts +1 -0
- package/dist/lib/codegen/internal-utils.js +6 -0
- package/dist/lib/codegen/internal-utils.js.map +1 -0
- package/dist/lib/codegen/schemas-generator.cjs +43 -0
- package/dist/lib/codegen/schemas-generator.cjs.map +1 -0
- package/dist/lib/codegen/schemas-generator.d.ts +16 -0
- package/dist/lib/codegen/schemas-generator.js +39 -0
- package/dist/lib/codegen/schemas-generator.js.map +1 -0
- package/dist/lib/codegen/services-generator.cjs +31 -0
- package/dist/lib/codegen/services-generator.cjs.map +1 -0
- package/dist/lib/codegen/services-generator.d.ts +15 -0
- package/dist/lib/codegen/services-generator.js +27 -0
- package/dist/lib/codegen/services-generator.js.map +1 -0
- package/dist/lib/codegen/types.cjs +3 -0
- package/dist/lib/codegen/types.cjs.map +1 -0
- package/dist/lib/codegen/types.d.ts +17 -0
- package/dist/lib/codegen/types.js +2 -0
- package/dist/lib/codegen/types.js.map +1 -0
- package/dist/lib/collect/collector.cjs +116 -0
- package/dist/lib/collect/collector.cjs.map +1 -0
- package/dist/lib/collect/collector.d.ts +3 -0
- package/dist/lib/collect/collector.js +112 -0
- package/dist/lib/collect/collector.js.map +1 -0
- package/dist/lib/collect/helpers.cjs +33 -0
- package/dist/lib/collect/helpers.cjs.map +1 -0
- package/dist/lib/collect/helpers.d.ts +3 -0
- package/dist/lib/collect/helpers.js +28 -0
- package/dist/lib/collect/helpers.js.map +1 -0
- package/dist/lib/collect/index.cjs +7 -0
- package/dist/lib/collect/index.cjs.map +1 -0
- package/dist/lib/collect/index.d.ts +3 -0
- package/dist/lib/collect/index.js +4 -0
- package/dist/lib/collect/index.js.map +1 -0
- package/dist/lib/collect/types.cjs +3 -0
- package/dist/lib/collect/types.cjs.map +1 -0
- package/dist/lib/collect/types.d.ts +12 -0
- package/dist/lib/collect/types.js +2 -0
- package/dist/lib/collect/types.js.map +1 -0
- package/dist/lib/internal-utils.cjs +8 -0
- package/dist/lib/internal-utils.cjs.map +1 -0
- package/dist/lib/internal-utils.d.ts +1 -0
- package/dist/lib/internal-utils.js +4 -0
- package/dist/lib/internal-utils.js.map +1 -0
- package/dist/lib/parse/deref-proxy.cjs +46 -0
- package/dist/lib/parse/deref-proxy.cjs.map +1 -0
- package/dist/lib/parse/deref-proxy.d.ts +3 -0
- package/dist/lib/parse/deref-proxy.js +42 -0
- package/dist/lib/parse/deref-proxy.js.map +1 -0
- package/dist/lib/parse/index.cjs +7 -0
- package/dist/lib/parse/index.cjs.map +1 -0
- package/dist/lib/parse/index.d.ts +3 -0
- package/dist/lib/parse/index.js +4 -0
- package/dist/lib/parse/index.js.map +1 -0
- package/dist/lib/parse/openapi-types.cjs +3 -0
- package/dist/lib/parse/openapi-types.cjs.map +1 -0
- package/dist/lib/parse/openapi-types.d.ts +897 -0
- package/dist/lib/parse/openapi-types.js +2 -0
- package/dist/lib/parse/openapi-types.js.map +1 -0
- package/dist/lib/parse/parser.cjs +189 -0
- package/dist/lib/parse/parser.cjs.map +1 -0
- package/dist/lib/parse/parser.d.ts +16 -0
- package/dist/lib/parse/parser.js +185 -0
- package/dist/lib/parse/parser.js.map +1 -0
- package/dist/lib/parse/types.cjs +3 -0
- package/dist/lib/parse/types.cjs.map +1 -0
- package/dist/lib/parse/types.d.ts +15 -0
- package/dist/lib/parse/types.js +2 -0
- package/dist/lib/parse/types.js.map +1 -0
- package/dist/lib/transform/api-types.cjs +3 -0
- package/dist/lib/transform/api-types.cjs.map +1 -0
- package/dist/lib/transform/api-types.d.ts +186 -0
- package/dist/lib/transform/api-types.js +2 -0
- package/dist/lib/transform/api-types.js.map +1 -0
- package/dist/lib/transform/helpers.cjs +121 -0
- package/dist/lib/transform/helpers.cjs.map +1 -0
- package/dist/lib/transform/helpers.d.ts +50 -0
- package/dist/lib/transform/helpers.js +108 -0
- package/dist/lib/transform/helpers.js.map +1 -0
- package/dist/lib/transform/index.cjs +6 -0
- package/dist/lib/transform/index.cjs.map +1 -0
- package/dist/lib/transform/index.d.ts +2 -0
- package/dist/lib/transform/index.js +3 -0
- package/dist/lib/transform/index.js.map +1 -0
- package/dist/lib/transform/transform-document.cjs +33 -0
- package/dist/lib/transform/transform-document.cjs.map +1 -0
- package/dist/lib/transform/transform-document.d.ts +3 -0
- package/dist/lib/transform/transform-document.js +29 -0
- package/dist/lib/transform/transform-document.js.map +1 -0
- package/dist/lib/transform/transform-endpoint.cjs +254 -0
- package/dist/lib/transform/transform-endpoint.cjs.map +1 -0
- package/dist/lib/transform/transform-endpoint.d.ts +4 -0
- package/dist/lib/transform/transform-endpoint.js +250 -0
- package/dist/lib/transform/transform-endpoint.js.map +1 -0
- package/dist/lib/transform/transform-schema.cjs +142 -0
- package/dist/lib/transform/transform-schema.cjs.map +1 -0
- package/dist/lib/transform/transform-schema.d.ts +4 -0
- package/dist/lib/transform/transform-schema.js +138 -0
- package/dist/lib/transform/transform-schema.js.map +1 -0
- package/dist/lib/transform/transformer.cjs +44 -0
- package/dist/lib/transform/transformer.cjs.map +1 -0
- package/dist/lib/transform/transformer.d.ts +3 -0
- package/dist/lib/transform/transformer.js +40 -0
- package/dist/lib/transform/transformer.js.map +1 -0
- package/dist/lib/transform/types.cjs +3 -0
- package/dist/lib/transform/types.cjs.map +1 -0
- package/dist/lib/transform/types.d.ts +23 -0
- package/dist/lib/transform/types.js +2 -0
- package/dist/lib/transform/types.js.map +1 -0
- package/dist/lib/utils/action-provider.cjs +35 -0
- package/dist/lib/utils/action-provider.cjs.map +1 -0
- package/dist/lib/utils/action-provider.d.ts +28 -0
- package/dist/lib/utils/action-provider.js +31 -0
- package/dist/lib/utils/action-provider.js.map +1 -0
- package/dist/lib/utils/common.utils.cjs +12 -0
- package/dist/lib/utils/common.utils.cjs.map +1 -0
- package/dist/lib/utils/common.utils.d.ts +3 -0
- package/dist/lib/utils/common.utils.js +7 -0
- package/dist/lib/utils/common.utils.js.map +1 -0
- package/dist/lib/utils/condition.cjs +9 -0
- package/dist/lib/utils/condition.cjs.map +1 -0
- package/dist/lib/utils/condition.d.ts +3 -0
- package/dist/lib/utils/condition.js +5 -0
- package/dist/lib/utils/condition.js.map +1 -0
- package/dist/lib/utils/endpoint.utils.cjs +13 -0
- package/dist/lib/utils/endpoint.utils.cjs.map +1 -0
- package/dist/lib/utils/endpoint.utils.d.ts +2 -0
- package/dist/lib/utils/endpoint.utils.js +9 -0
- package/dist/lib/utils/endpoint.utils.js.map +1 -0
- package/dist/lib/utils/factory.cjs +29 -0
- package/dist/lib/utils/factory.cjs.map +1 -0
- package/dist/lib/utils/factory.d.ts +20 -0
- package/dist/lib/utils/factory.js +25 -0
- package/dist/lib/utils/factory.js.map +1 -0
- package/dist/lib/utils/generator.utils.cjs +11 -0
- package/dist/lib/utils/generator.utils.cjs.map +1 -0
- package/dist/lib/utils/generator.utils.d.ts +1 -0
- package/dist/lib/utils/generator.utils.js +7 -0
- package/dist/lib/utils/generator.utils.js.map +1 -0
- package/dist/lib/utils/index.cjs +14 -0
- package/dist/lib/utils/index.cjs.map +1 -0
- package/dist/lib/utils/index.d.ts +10 -0
- package/dist/lib/utils/index.js +11 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/utils/object.utils.cjs +21 -0
- package/dist/lib/utils/object.utils.cjs.map +1 -0
- package/dist/lib/utils/object.utils.d.ts +1 -0
- package/dist/lib/utils/object.utils.js +17 -0
- package/dist/lib/utils/object.utils.js.map +1 -0
- package/dist/lib/utils/schema.utils.cjs +55 -0
- package/dist/lib/utils/schema.utils.cjs.map +1 -0
- package/dist/lib/utils/schema.utils.d.ts +10 -0
- package/dist/lib/utils/schema.utils.js +50 -0
- package/dist/lib/utils/schema.utils.js.map +1 -0
- package/dist/lib/utils/source-builder.cjs +378 -0
- package/dist/lib/utils/source-builder.cjs.map +1 -0
- package/dist/lib/utils/source-builder.d.ts +216 -0
- package/dist/lib/utils/source-builder.js +374 -0
- package/dist/lib/utils/source-builder.js.map +1 -0
- package/dist/lib/utils/string.utils.cjs +337 -0
- package/dist/lib/utils/string.utils.cjs.map +1 -0
- package/dist/lib/utils/string.utils.d.ts +173 -0
- package/dist/lib/utils/string.utils.js +324 -0
- package/dist/lib/utils/string.utils.js.map +1 -0
- package/dist/lib/utils/string.utils.types.cjs +3 -0
- package/dist/lib/utils/string.utils.types.cjs.map +1 -0
- package/dist/lib/utils/string.utils.types.d.ts +148 -0
- package/dist/lib/utils/string.utils.types.js +2 -0
- package/dist/lib/utils/string.utils.types.js.map +1 -0
- package/dist/lib/utils/type.utils.cjs +3 -0
- package/dist/lib/utils/type.utils.cjs.map +1 -0
- package/dist/lib/utils/type.utils.d.ts +15 -0
- package/dist/lib/utils/type.utils.js +2 -0
- package/dist/lib/utils/type.utils.js.map +1 -0
- package/package.json +27 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isOpenApiObjectProperty } from '../internal-utils';
|
|
2
|
+
export function resolveAnyOfAndAllOf(schema, ignoreNonObjectParts) {
|
|
3
|
+
if (!ignoreNonObjectParts && (hasInvalidSubSchema(schema.anyOf) || hasInvalidSubSchema(schema.allOf))) {
|
|
4
|
+
return undefined;
|
|
5
|
+
}
|
|
6
|
+
const required = new Set(schema.required);
|
|
7
|
+
const properties = new Map();
|
|
8
|
+
collectSubSchemaProperties(schema.allOf, properties, required, false);
|
|
9
|
+
collectSubSchemaProperties(schema.anyOf, properties, required, true);
|
|
10
|
+
if (properties.size === 0) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return Object.assign(Object.assign({}, schema), { kind: 'object', type: 'object', anyOf: [], allOf: [], properties: properties, required: required, additionalProperties: false });
|
|
14
|
+
}
|
|
15
|
+
function collectSubSchemaProperties(subSchemas, properties, required, optional) {
|
|
16
|
+
for (const subSchema of subSchemas) {
|
|
17
|
+
if (subSchema.kind === 'object') {
|
|
18
|
+
for (const prop of subSchema.properties.values()) {
|
|
19
|
+
if (!properties.has(prop.name)) {
|
|
20
|
+
properties.set(prop.name, prop);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (!optional) {
|
|
24
|
+
for (const prop of subSchema.required) {
|
|
25
|
+
required.add(prop);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (subSchema.kind === 'object' || subSchema.kind === 'combined') {
|
|
30
|
+
collectSubSchemaProperties(subSchema.allOf, properties, required, optional);
|
|
31
|
+
collectSubSchemaProperties(subSchema.anyOf, properties, required, true);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function hasInvalidSubSchema(subSchemas) {
|
|
36
|
+
return subSchemas.some((x) => x.kind !== 'object' && (x.kind !== 'combined' || (!hasInvalidSubSchema(x.allOf) && !hasInvalidSubSchema(x.anyOf))));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Retrieves the first schema reference and the reference chain of a given schema that
|
|
40
|
+
* defines some schema properties. (e.g. schemas with just "$ref" are skipped)
|
|
41
|
+
* @param schema The schema to retrieve the reference from.
|
|
42
|
+
* @param propertiesToIgnore The properties to ignore when checking for a schema definition.
|
|
43
|
+
*/
|
|
44
|
+
export function getSchemaReference(schema, propertiesToIgnore) {
|
|
45
|
+
if (!schema.$ref)
|
|
46
|
+
return schema;
|
|
47
|
+
const hasPropertiesDefined = Object.keys(schema.$src.originalComponent).some((key) => isOpenApiObjectProperty(key) && !propertiesToIgnore.includes(key));
|
|
48
|
+
return hasPropertiesDefined ? schema : getSchemaReference(schema.$ref, propertiesToIgnore);
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=schema.utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.utils.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/schema.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,MAAM,UAAU,oBAAoB,CAClC,MAAwC,EACxC,oBAA6B;IAE7B,IAAI,CAAC,oBAAoB,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;QACrG,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,IAAI,GAAG,EAA6B,CAAC;IACxD,0BAA0B,CAAC,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IACtE,0BAA0B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,OAAO,UAAU,CAAC,IAAI,CACpB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,IAAI,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CACrH,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAiB,EAAE,kBAA2C;IAC/F,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,MAAM,CAAC;IAChC,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAC1E,CAAC,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,GAA0B,CAAC,CAClG,CAAC;IACF,OAAO,oBAAoB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;AAC7F,CAAC"}
|
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SourceBuilder = exports.defaultSourceBuilderOptions = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const condition_1 = require("./condition");
|
|
6
|
+
const string_utils_1 = require("./string.utils");
|
|
7
|
+
exports.defaultSourceBuilderOptions = {
|
|
8
|
+
indent: { type: 'spaces', count: 2 },
|
|
9
|
+
newLine: os_1.EOL,
|
|
10
|
+
charsTreatedAsEmptyLine: ['{'],
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Represents an in-memory source file.
|
|
14
|
+
*/
|
|
15
|
+
class SourceBuilder extends string_utils_1.StringBuilder {
|
|
16
|
+
/**
|
|
17
|
+
* Gets the options used by this instance.
|
|
18
|
+
*/
|
|
19
|
+
get options() {
|
|
20
|
+
return this.__options;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializes a new instance of the SourceBuilder class.
|
|
24
|
+
* @param options The options to use for this instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options) {
|
|
27
|
+
super(options);
|
|
28
|
+
this._linePrefix = '';
|
|
29
|
+
this._isLineIndented = false;
|
|
30
|
+
this._isLastLineEmpty = true;
|
|
31
|
+
this._isCurrentLineEmpty = true;
|
|
32
|
+
/**
|
|
33
|
+
* Gets or sets the current indentation level.
|
|
34
|
+
*/
|
|
35
|
+
this.currentIndentLevel = 0;
|
|
36
|
+
this.__options = Object.assign(Object.assign({}, exports.defaultSourceBuilderOptions), options);
|
|
37
|
+
this._emptyLineCharRegex = new RegExp(`[\\s${this.__options.charsTreatedAsEmptyLine.join('')}]`);
|
|
38
|
+
this._indentString = this.__options.indent.type === 'tabs' ? '\t' : ' '.repeat(this.__options.indent.count);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new instance of the SourceBuilder class from a string.
|
|
42
|
+
* @param str The string to use as the initial content of the builder.
|
|
43
|
+
* @param options The options to use for this instance.
|
|
44
|
+
* @returns A new instance of the SourceBuilder class.
|
|
45
|
+
*/
|
|
46
|
+
static fromString(str, options) {
|
|
47
|
+
const builder = new SourceBuilder(options);
|
|
48
|
+
builder.append(str);
|
|
49
|
+
return builder;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Builds a string using a callback function that receives a `SourceBuilder` instance.
|
|
53
|
+
* @param buildAction The callback function that receives a `SourceBuilder` instance to build the string.
|
|
54
|
+
* @param options The options to use for the `SourceBuilder` instance.
|
|
55
|
+
* @returns The string built by the `SourceBuilder` instance.
|
|
56
|
+
*/
|
|
57
|
+
static build(buildAction, options) {
|
|
58
|
+
const builder = new SourceBuilder(options);
|
|
59
|
+
buildAction(builder);
|
|
60
|
+
return builder.toString();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Appends one or more strings to the end of the current SourceBuilder.
|
|
64
|
+
* @param value The string(s) to append.
|
|
65
|
+
* @returns The current SourceBuilder.
|
|
66
|
+
*/
|
|
67
|
+
append(...value) {
|
|
68
|
+
if (value.length === 0 || !value.some((v) => v && v.length > 0)) {
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
const str = value.join('');
|
|
72
|
+
let lineStartIndex = 0;
|
|
73
|
+
for (let i = 0; i < str.length; i++) {
|
|
74
|
+
if (str[i] === '\r')
|
|
75
|
+
continue;
|
|
76
|
+
if (str[i] === '\n') {
|
|
77
|
+
let lineLength = i - lineStartIndex;
|
|
78
|
+
for (let j = i; j > 0 && str[j - 1] === '\r'; j--) {
|
|
79
|
+
lineLength--;
|
|
80
|
+
}
|
|
81
|
+
if (lineLength > 0) {
|
|
82
|
+
if (!this._isLineIndented) {
|
|
83
|
+
this.appendIndent();
|
|
84
|
+
}
|
|
85
|
+
super.append(str.substring(lineStartIndex, i).replace(/\r/g, ''));
|
|
86
|
+
}
|
|
87
|
+
this._isLastLineEmpty = this._isCurrentLineEmpty;
|
|
88
|
+
super.append(this.__options.newLine);
|
|
89
|
+
this._isCurrentLineEmpty = true;
|
|
90
|
+
this._isLineIndented = false;
|
|
91
|
+
lineStartIndex = i + 1;
|
|
92
|
+
}
|
|
93
|
+
if (!this._emptyLineCharRegex.test(str[i])) {
|
|
94
|
+
this._isCurrentLineEmpty = false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!this._isLineIndented && lineStartIndex < str.length) {
|
|
98
|
+
this.appendIndent();
|
|
99
|
+
this._isLineIndented = true;
|
|
100
|
+
}
|
|
101
|
+
super.append(str.substring(lineStartIndex).replace(/\r/g, ''));
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
106
|
+
* @param value The string(s) to append.
|
|
107
|
+
* @returns The current SourceBuilder.
|
|
108
|
+
*/
|
|
109
|
+
appendLine(...value) {
|
|
110
|
+
return this.append(...value, '\n');
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
114
|
+
* @param condition The condition to check before appending the specified value.
|
|
115
|
+
* @param value The string(s) to append.
|
|
116
|
+
* @returns The current SourceBuilder.
|
|
117
|
+
*/
|
|
118
|
+
appendIf(condition, ...value) {
|
|
119
|
+
return (0, condition_1.evalCondition)(condition) ? this.append(...value) : this;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
123
|
+
* @param condition The condition to check before appending the specified value.
|
|
124
|
+
* @param value The string(s) to append.
|
|
125
|
+
* @returns The current SourceBuilder.
|
|
126
|
+
*/
|
|
127
|
+
appendLineIf(condition, ...value) {
|
|
128
|
+
return (0, condition_1.evalCondition)(condition) ? this.appendLine(...value) : this;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Appends the specified values to this source builder with the specified line prefix.
|
|
132
|
+
* @param {string} prefix - The line prefix to use.
|
|
133
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
134
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
135
|
+
*/
|
|
136
|
+
appendWithLinePrefix(prefix, ...value) {
|
|
137
|
+
return this.applyWithLinePrefix(prefix, (builder) => builder.append(...value));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
141
|
+
* @param {string} prefix - The line prefix to use.
|
|
142
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
143
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
144
|
+
*/
|
|
145
|
+
appendLineWithLinePrefix(prefix, ...value) {
|
|
146
|
+
return this.applyWithLinePrefix(prefix, (builder) => builder.appendLine(...value));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
150
|
+
* @param condition The condition to check before prepending the specified value.
|
|
151
|
+
* @param value The string(s) to prepend.
|
|
152
|
+
* @returns The current SourceBuilder.
|
|
153
|
+
*/
|
|
154
|
+
prependIf(condition, ...value) {
|
|
155
|
+
return (0, condition_1.evalCondition)(condition) ? this.prepend(...value) : this;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
159
|
+
* @param condition The condition to check before appending the specified value.
|
|
160
|
+
* @param value The string(s) to prepend.
|
|
161
|
+
* @returns The current SourceBuilder.
|
|
162
|
+
*/
|
|
163
|
+
prependLineIf(condition, ...value) {
|
|
164
|
+
return (0, condition_1.evalCondition)(condition) ? this.prependLine(...value) : this;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Applies the provided builder function to this source builder.
|
|
168
|
+
* @param builderFn The builder function to apply.
|
|
169
|
+
* @returns This source builder instance.
|
|
170
|
+
*/
|
|
171
|
+
apply(builderFn) {
|
|
172
|
+
builderFn(this);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Applies the provided builder function to this source builder with the specified line prefix.
|
|
177
|
+
* @param prefix The line prefix to use.
|
|
178
|
+
* @param builderFn The builder function to apply.
|
|
179
|
+
* @returns This source builder instance.
|
|
180
|
+
*/
|
|
181
|
+
applyWithLinePrefix(prefix, builderFn) {
|
|
182
|
+
const previousLinePrefix = this._linePrefix;
|
|
183
|
+
this._linePrefix += prefix;
|
|
184
|
+
try {
|
|
185
|
+
builderFn(this);
|
|
186
|
+
}
|
|
187
|
+
finally {
|
|
188
|
+
this._linePrefix = previousLinePrefix;
|
|
189
|
+
}
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
194
|
+
* @returns A reference to this instance.
|
|
195
|
+
*/
|
|
196
|
+
ensurePreviousLineEmpty() {
|
|
197
|
+
if (!this._isCurrentLineEmpty) {
|
|
198
|
+
this.appendLine();
|
|
199
|
+
}
|
|
200
|
+
if (!this._isLastLineEmpty) {
|
|
201
|
+
this.appendLine();
|
|
202
|
+
}
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
207
|
+
* @returns A reference to this instance.
|
|
208
|
+
*/
|
|
209
|
+
ensureCurrentLineEmpty() {
|
|
210
|
+
if (!this._isCurrentLineEmpty) {
|
|
211
|
+
this.appendLine();
|
|
212
|
+
}
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Inserts specified content if the specified condition is true.
|
|
217
|
+
* @param condition The condition to check before inserting content.
|
|
218
|
+
* @param builderFn The function to add content.
|
|
219
|
+
* @returns A reference to this instance.
|
|
220
|
+
*/
|
|
221
|
+
applyIf(condition, builderFn) {
|
|
222
|
+
if ((0, condition_1.evalCondition)(condition)) {
|
|
223
|
+
builderFn(this);
|
|
224
|
+
}
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Inserts specified content depending on the specified condition.
|
|
229
|
+
* @param condition The condition to check before inserting content.
|
|
230
|
+
* @param builderFn The function to add content if the condition is true.
|
|
231
|
+
* @param elseBuilderFn The function to add content if the condition is false.
|
|
232
|
+
* @returns A reference to this instance.
|
|
233
|
+
*/
|
|
234
|
+
applyIfElse(condition, builderFn, elseBuilderFn) {
|
|
235
|
+
if ((0, condition_1.evalCondition)(condition)) {
|
|
236
|
+
builderFn(this);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
elseBuilderFn(this);
|
|
240
|
+
}
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
245
|
+
* @param builderFn The function to add indented content.
|
|
246
|
+
* @param condition The condition to check before adding indentation.
|
|
247
|
+
* @returns A reference to this instance.
|
|
248
|
+
*/
|
|
249
|
+
indent(builderFn, condition = true) {
|
|
250
|
+
const shouldIndent = (0, condition_1.evalCondition)(condition);
|
|
251
|
+
if (shouldIndent) {
|
|
252
|
+
this.currentIndentLevel++;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
builderFn(this);
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
if (shouldIndent) {
|
|
259
|
+
this.currentIndentLevel--;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return this;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Adds parentheses around the specified content and adds one indentation level.
|
|
266
|
+
* @param brackets The brackets to use.
|
|
267
|
+
* @param builderFn The function to add content inside parentheses.
|
|
268
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
269
|
+
* @returns A reference to this instance.
|
|
270
|
+
*/
|
|
271
|
+
parenthesize(brackets, builderFn, indent = true) {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
this.append((_a = brackets[0]) !== null && _a !== void 0 ? _a : '');
|
|
274
|
+
this.indent(builderFn, indent);
|
|
275
|
+
this.append((_b = brackets[1]) !== null && _b !== void 0 ? _b : '');
|
|
276
|
+
return this;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Adds parentheses around the specified content if the specified condition is true.
|
|
280
|
+
* @param condition The condition to check before adding parentheses.
|
|
281
|
+
* @param brackets The brackets to use.
|
|
282
|
+
* @param builderFn The function to add content inside parentheses.
|
|
283
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
284
|
+
* @returns A reference to this instance.
|
|
285
|
+
*/
|
|
286
|
+
parenthesizeIf(condition, brackets, builderFn, indent) {
|
|
287
|
+
if ((0, condition_1.evalCondition)(condition)) {
|
|
288
|
+
this.parenthesize(brackets, builderFn, indent !== null && indent !== void 0 ? indent : true);
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
this.indent(builderFn, indent !== null && indent !== void 0 ? indent : false);
|
|
292
|
+
}
|
|
293
|
+
return this;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Adds content for each item in the specified array.
|
|
297
|
+
* @param items The items to add content for.
|
|
298
|
+
* @param builderFn The function to add content for each item.
|
|
299
|
+
* @returns A reference to this instance.
|
|
300
|
+
*/
|
|
301
|
+
forEach(items, builderFn) {
|
|
302
|
+
return this.forEachImpl(items, builderFn);
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Adds content for each item in the specified array.
|
|
306
|
+
* @param items The items to add content for.
|
|
307
|
+
* @param condition The condition to check before adding content.
|
|
308
|
+
* @param builderFn The function to add content for each item.
|
|
309
|
+
* @returns A reference to this instance.
|
|
310
|
+
*/
|
|
311
|
+
forEachIf(items, condition, builderFn) {
|
|
312
|
+
return (0, condition_1.evalCondition)(condition) ? this.forEachImpl(items, builderFn) : this;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Adds content for each item in the specified array.
|
|
316
|
+
* @param items The items to add content for.
|
|
317
|
+
* @param condition The condition to check before adding content for each item.
|
|
318
|
+
* @param builderFn The function to add content for each item.
|
|
319
|
+
* @returns A reference to this instance.
|
|
320
|
+
*/
|
|
321
|
+
forEachMatching(items, condition, builderFn) {
|
|
322
|
+
return this.forEachImpl(items, builderFn, undefined, condition);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Adds content for each item in the specified array.
|
|
326
|
+
* @param items The items to add content for.
|
|
327
|
+
* @param seperator The seperator to add between items.
|
|
328
|
+
* @param builderFn The function to add content for each item.
|
|
329
|
+
* @returns A reference to this instance.
|
|
330
|
+
*/
|
|
331
|
+
forEachSeparated(items, seperator, builderFn) {
|
|
332
|
+
return this.forEachImpl(items, builderFn, seperator);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Adds content for each item in the specified array.
|
|
336
|
+
* @param items The items to add content for.
|
|
337
|
+
* @param condition The condition to check before adding content for each item.
|
|
338
|
+
* @param seperator The seperator to add between items.
|
|
339
|
+
* @param builderFn The function to add content for each item.
|
|
340
|
+
* @returns A reference to this instance.
|
|
341
|
+
*/
|
|
342
|
+
forEachMatchingSeparated(items, condition, seperator, builderFn) {
|
|
343
|
+
return this.forEachImpl(items, builderFn, seperator, condition);
|
|
344
|
+
}
|
|
345
|
+
forEachImpl(items, builderFn, seperator, condition = true) {
|
|
346
|
+
if (condition === false)
|
|
347
|
+
return this;
|
|
348
|
+
let previousIndex = -1;
|
|
349
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
350
|
+
let previousItem = undefined;
|
|
351
|
+
let index = 0;
|
|
352
|
+
for (const item of items) {
|
|
353
|
+
if ((0, condition_1.evalCondition)(condition, item)) {
|
|
354
|
+
if (previousIndex >= 0 && seperator) {
|
|
355
|
+
if (typeof seperator === 'string') {
|
|
356
|
+
this.append(seperator);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
seperator(this, previousItem, item, previousIndex, index);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
builderFn(this, item, index);
|
|
363
|
+
previousIndex = index;
|
|
364
|
+
previousItem = item;
|
|
365
|
+
}
|
|
366
|
+
index++;
|
|
367
|
+
}
|
|
368
|
+
return this;
|
|
369
|
+
}
|
|
370
|
+
appendIndent() {
|
|
371
|
+
super.append(this._indentString.repeat(this.currentIndentLevel));
|
|
372
|
+
if (this._linePrefix) {
|
|
373
|
+
super.append(this._linePrefix);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
exports.SourceBuilder = SourceBuilder;
|
|
378
|
+
//# sourceMappingURL=source-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-builder.cjs","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/source-builder.ts"],"names":[],"mappings":";;;AAAA,2BAAyB;AAEzB,2CAAuD;AACvD,iDAAqE;AAUxD,QAAA,2BAA2B,GAAyB;IAC/D,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,EAAE;IACpC,OAAO,EAAE,QAAG;IACZ,uBAAuB,EAAE,CAAC,GAAG,CAAC;CAC/B,CAAC;AAiBF;;GAEG;AACH,MAAa,aAAc,SAAQ,4BAAa;IAe9C;;OAEG;IACH,IAAoB,OAAO;QACzB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED;;;OAGG;IACH,YAAY,OAAuC;QACjD,KAAK,CAAC,OAAO,CAAC,CAAC;QAtBT,gBAAW,GAAW,EAAE,CAAC;QACzB,oBAAe,GAAY,KAAK,CAAC;QACjC,qBAAgB,GAAY,IAAI,CAAC;QACjC,wBAAmB,GAAY,IAAI,CAAC;QAE5C;;WAEG;QACI,uBAAkB,GAAW,CAAC,CAAC;QAepC,IAAI,CAAC,SAAS,mCAAQ,mCAA2B,GAAK,OAAO,CAAE,CAAC;QAChE,IAAI,CAAC,mBAAmB,GAAG,IAAI,MAAM,CAAC,OAAO,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;QACjG,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9G,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAU,UAAU,CAAC,GAAW,EAAE,OAAuC;QACpF,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,CA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KAAK,EAAE,CAAC;SACT;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,YAAY;QAClB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACjE,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SAChC;IACH,CAAC;CACF;AArbD,sCAqbC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { Condition } from './condition';
|
|
2
|
+
import { StringBuilder, StringBuilderOptions } from './string.utils';
|
|
3
|
+
import { Nullable } from './type.utils';
|
|
4
|
+
export type IndentOptions = {
|
|
5
|
+
readonly type: 'tabs';
|
|
6
|
+
} | {
|
|
7
|
+
readonly type: 'spaces';
|
|
8
|
+
readonly count: number;
|
|
9
|
+
};
|
|
10
|
+
export type SourceBuilderOptions = StringBuilderOptions & {
|
|
11
|
+
indent: IndentOptions;
|
|
12
|
+
charsTreatedAsEmptyLine: string[];
|
|
13
|
+
};
|
|
14
|
+
export declare const defaultSourceBuilderOptions: SourceBuilderOptions;
|
|
15
|
+
type KnownParatheses = '()' | '[]' | '{}' | '<>';
|
|
16
|
+
export type Paratheses = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<string>, close: Nullable<string>];
|
|
17
|
+
export type SeparatorBuidlerFn<TBuilder extends SourceBuilder, TItem> = (builder: TBuilder, previousItem: TItem, nextItem: TItem, previousItemIndex: number, nextItemIndex: number) => void;
|
|
18
|
+
export type Separator<TBuilder extends SourceBuilder, TItem> = string | SeparatorBuidlerFn<TBuilder, TItem>;
|
|
19
|
+
/**
|
|
20
|
+
* Represents an in-memory source file.
|
|
21
|
+
*/
|
|
22
|
+
export declare class SourceBuilder extends StringBuilder {
|
|
23
|
+
private readonly __options;
|
|
24
|
+
private readonly _emptyLineCharRegex;
|
|
25
|
+
private readonly _indentString;
|
|
26
|
+
private _linePrefix;
|
|
27
|
+
private _isLineIndented;
|
|
28
|
+
private _isLastLineEmpty;
|
|
29
|
+
private _isCurrentLineEmpty;
|
|
30
|
+
/**
|
|
31
|
+
* Gets or sets the current indentation level.
|
|
32
|
+
*/
|
|
33
|
+
currentIndentLevel: number;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the options used by this instance.
|
|
36
|
+
*/
|
|
37
|
+
get options(): SourceBuilderOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Initializes a new instance of the SourceBuilder class.
|
|
40
|
+
* @param options The options to use for this instance.
|
|
41
|
+
*/
|
|
42
|
+
constructor(options?: Partial<SourceBuilderOptions>);
|
|
43
|
+
/**
|
|
44
|
+
* Creates a new instance of the SourceBuilder class from a string.
|
|
45
|
+
* @param str The string to use as the initial content of the builder.
|
|
46
|
+
* @param options The options to use for this instance.
|
|
47
|
+
* @returns A new instance of the SourceBuilder class.
|
|
48
|
+
*/
|
|
49
|
+
static fromString(str: string, options?: Partial<SourceBuilderOptions>): SourceBuilder;
|
|
50
|
+
/**
|
|
51
|
+
* Builds a string using a callback function that receives a `SourceBuilder` instance.
|
|
52
|
+
* @param buildAction The callback function that receives a `SourceBuilder` instance to build the string.
|
|
53
|
+
* @param options The options to use for the `SourceBuilder` instance.
|
|
54
|
+
* @returns The string built by the `SourceBuilder` instance.
|
|
55
|
+
*/
|
|
56
|
+
static build(buildAction: (builder: SourceBuilder) => void, options?: Partial<SourceBuilderOptions>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Appends one or more strings to the end of the current SourceBuilder.
|
|
59
|
+
* @param value The string(s) to append.
|
|
60
|
+
* @returns The current SourceBuilder.
|
|
61
|
+
*/
|
|
62
|
+
append(...value: Nullable<string>[]): this;
|
|
63
|
+
/**
|
|
64
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
65
|
+
* @param value The string(s) to append.
|
|
66
|
+
* @returns The current SourceBuilder.
|
|
67
|
+
*/
|
|
68
|
+
appendLine(...value: Nullable<string>[]): this;
|
|
69
|
+
/**
|
|
70
|
+
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
71
|
+
* @param condition The condition to check before appending the specified value.
|
|
72
|
+
* @param value The string(s) to append.
|
|
73
|
+
* @returns The current SourceBuilder.
|
|
74
|
+
*/
|
|
75
|
+
appendIf(condition: Condition, ...value: Nullable<string>[]): this;
|
|
76
|
+
/**
|
|
77
|
+
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
78
|
+
* @param condition The condition to check before appending the specified value.
|
|
79
|
+
* @param value The string(s) to append.
|
|
80
|
+
* @returns The current SourceBuilder.
|
|
81
|
+
*/
|
|
82
|
+
appendLineIf(condition: Condition, ...value: Nullable<string>[]): this;
|
|
83
|
+
/**
|
|
84
|
+
* Appends the specified values to this source builder with the specified line prefix.
|
|
85
|
+
* @param {string} prefix - The line prefix to use.
|
|
86
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
87
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
88
|
+
*/
|
|
89
|
+
appendWithLinePrefix(prefix: string, ...value: Nullable<string>[]): this;
|
|
90
|
+
/**
|
|
91
|
+
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
92
|
+
* @param {string} prefix - The line prefix to use.
|
|
93
|
+
* @param {...(string|null|undefined)} value - The values to append.
|
|
94
|
+
* @returns {SourceBuilder} This source builder instance.
|
|
95
|
+
*/
|
|
96
|
+
appendLineWithLinePrefix(prefix: string, ...value: Nullable<string>[]): this;
|
|
97
|
+
/**
|
|
98
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
99
|
+
* @param condition The condition to check before prepending the specified value.
|
|
100
|
+
* @param value The string(s) to prepend.
|
|
101
|
+
* @returns The current SourceBuilder.
|
|
102
|
+
*/
|
|
103
|
+
prependIf(condition: Condition, ...value: Nullable<string | ((builder: StringBuilder) => void)>[]): this;
|
|
104
|
+
/**
|
|
105
|
+
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
106
|
+
* @param condition The condition to check before appending the specified value.
|
|
107
|
+
* @param value The string(s) to prepend.
|
|
108
|
+
* @returns The current SourceBuilder.
|
|
109
|
+
*/
|
|
110
|
+
prependLineIf(condition: Condition, ...value: Nullable<string | ((builder: StringBuilder) => void)>[]): this;
|
|
111
|
+
/**
|
|
112
|
+
* Applies the provided builder function to this source builder.
|
|
113
|
+
* @param builderFn The builder function to apply.
|
|
114
|
+
* @returns This source builder instance.
|
|
115
|
+
*/
|
|
116
|
+
apply(builderFn: (builder: this) => void): this;
|
|
117
|
+
/**
|
|
118
|
+
* Applies the provided builder function to this source builder with the specified line prefix.
|
|
119
|
+
* @param prefix The line prefix to use.
|
|
120
|
+
* @param builderFn The builder function to apply.
|
|
121
|
+
* @returns This source builder instance.
|
|
122
|
+
*/
|
|
123
|
+
applyWithLinePrefix(prefix: string, builderFn: (builder: this) => void): this;
|
|
124
|
+
/**
|
|
125
|
+
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
126
|
+
* @returns A reference to this instance.
|
|
127
|
+
*/
|
|
128
|
+
ensurePreviousLineEmpty(): this;
|
|
129
|
+
/**
|
|
130
|
+
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
131
|
+
* @returns A reference to this instance.
|
|
132
|
+
*/
|
|
133
|
+
ensureCurrentLineEmpty(): this;
|
|
134
|
+
/**
|
|
135
|
+
* Inserts specified content if the specified condition is true.
|
|
136
|
+
* @param condition The condition to check before inserting content.
|
|
137
|
+
* @param builderFn The function to add content.
|
|
138
|
+
* @returns A reference to this instance.
|
|
139
|
+
*/
|
|
140
|
+
applyIf(condition: Condition, builderFn: (builder: this) => void): this;
|
|
141
|
+
/**
|
|
142
|
+
* Inserts specified content depending on the specified condition.
|
|
143
|
+
* @param condition The condition to check before inserting content.
|
|
144
|
+
* @param builderFn The function to add content if the condition is true.
|
|
145
|
+
* @param elseBuilderFn The function to add content if the condition is false.
|
|
146
|
+
* @returns A reference to this instance.
|
|
147
|
+
*/
|
|
148
|
+
applyIfElse(condition: Condition, builderFn: (builder: this) => void, elseBuilderFn: (builder: this) => void): this;
|
|
149
|
+
/**
|
|
150
|
+
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
151
|
+
* @param builderFn The function to add indented content.
|
|
152
|
+
* @param condition The condition to check before adding indentation.
|
|
153
|
+
* @returns A reference to this instance.
|
|
154
|
+
*/
|
|
155
|
+
indent(builderFn: (builder: this) => void, condition?: Condition): this;
|
|
156
|
+
/**
|
|
157
|
+
* Adds parentheses around the specified content and adds one indentation level.
|
|
158
|
+
* @param brackets The brackets to use.
|
|
159
|
+
* @param builderFn The function to add content inside parentheses.
|
|
160
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
161
|
+
* @returns A reference to this instance.
|
|
162
|
+
*/
|
|
163
|
+
parenthesize(brackets: Paratheses, builderFn: (builder: this) => void, indent?: boolean): this;
|
|
164
|
+
/**
|
|
165
|
+
* Adds parentheses around the specified content if the specified condition is true.
|
|
166
|
+
* @param condition The condition to check before adding parentheses.
|
|
167
|
+
* @param brackets The brackets to use.
|
|
168
|
+
* @param builderFn The function to add content inside parentheses.
|
|
169
|
+
* @param indent Whether to indent the content inside parentheses. Defaults to `true`.
|
|
170
|
+
* @returns A reference to this instance.
|
|
171
|
+
*/
|
|
172
|
+
parenthesizeIf(condition: Condition, brackets: Paratheses, builderFn: (builder: this) => void, indent?: boolean): this;
|
|
173
|
+
/**
|
|
174
|
+
* Adds content for each item in the specified array.
|
|
175
|
+
* @param items The items to add content for.
|
|
176
|
+
* @param builderFn The function to add content for each item.
|
|
177
|
+
* @returns A reference to this instance.
|
|
178
|
+
*/
|
|
179
|
+
forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
180
|
+
/**
|
|
181
|
+
* Adds content for each item in the specified array.
|
|
182
|
+
* @param items The items to add content for.
|
|
183
|
+
* @param condition The condition to check before adding content.
|
|
184
|
+
* @param builderFn The function to add content for each item.
|
|
185
|
+
* @returns A reference to this instance.
|
|
186
|
+
*/
|
|
187
|
+
forEachIf<T>(items: Iterable<T>, condition: Condition, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
188
|
+
/**
|
|
189
|
+
* Adds content for each item in the specified array.
|
|
190
|
+
* @param items The items to add content for.
|
|
191
|
+
* @param condition The condition to check before adding content for each item.
|
|
192
|
+
* @param builderFn The function to add content for each item.
|
|
193
|
+
* @returns A reference to this instance.
|
|
194
|
+
*/
|
|
195
|
+
forEachMatching<T>(items: Iterable<T>, condition: Condition<T>, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
196
|
+
/**
|
|
197
|
+
* Adds content for each item in the specified array.
|
|
198
|
+
* @param items The items to add content for.
|
|
199
|
+
* @param seperator The seperator to add between items.
|
|
200
|
+
* @param builderFn The function to add content for each item.
|
|
201
|
+
* @returns A reference to this instance.
|
|
202
|
+
*/
|
|
203
|
+
forEachSeparated<T>(items: Iterable<T>, seperator: Separator<this, T>, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
204
|
+
/**
|
|
205
|
+
* Adds content for each item in the specified array.
|
|
206
|
+
* @param items The items to add content for.
|
|
207
|
+
* @param condition The condition to check before adding content for each item.
|
|
208
|
+
* @param seperator The seperator to add between items.
|
|
209
|
+
* @param builderFn The function to add content for each item.
|
|
210
|
+
* @returns A reference to this instance.
|
|
211
|
+
*/
|
|
212
|
+
forEachMatchingSeparated<T>(items: Iterable<T>, condition: Condition<T>, seperator: Separator<this, T>, builderFn: (builder: this, item: T, index: number) => void): this;
|
|
213
|
+
private forEachImpl;
|
|
214
|
+
private appendIndent;
|
|
215
|
+
}
|
|
216
|
+
export {};
|