@goast/core 0.1.1 → 0.2.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/cjs/index.js +1 -0
- package/cjs/lib/ast/index.js +4 -0
- package/cjs/lib/ast/node.js +27 -0
- package/cjs/lib/parse/parser.js +1 -1
- package/cjs/lib/transform/transform-endpoint.js +1 -1
- package/cjs/lib/transform/transform-schema.js +4 -2
- package/cjs/lib/utils/array.utils.js +11 -0
- package/cjs/lib/utils/class.utils.js +33 -0
- package/cjs/lib/utils/common.utils.js +75 -1
- package/cjs/lib/utils/error.utils.js +7 -0
- package/cjs/lib/utils/index.js +4 -0
- package/cjs/lib/utils/object.utils.js +6 -2
- package/cjs/lib/utils/schema.utils.js +2 -1
- package/cjs/lib/utils/source-builder.js +171 -81
- package/cjs/lib/utils/string-builder/index.js +8 -0
- package/cjs/lib/utils/string-builder/options.js +7 -0
- package/cjs/lib/utils/string-builder/string-builder.js +142 -0
- package/cjs/lib/utils/string-builder/utils.js +38 -0
- package/cjs/lib/utils/string.utils.js +123 -107
- package/cjs/lib/utils/type.utils.js +9 -0
- package/esm/index.js +1 -0
- package/esm/lib/ast/index.js +1 -0
- package/esm/lib/ast/node.js +23 -0
- package/esm/lib/parse/parser.js +1 -1
- package/esm/lib/transform/transform-endpoint.js +1 -1
- package/esm/lib/transform/transform-schema.js +4 -2
- package/esm/lib/utils/array.utils.js +7 -0
- package/esm/lib/utils/class.utils.js +27 -0
- package/esm/lib/utils/common.utils.js +64 -0
- package/esm/lib/utils/error.utils.js +3 -0
- package/esm/lib/utils/index.js +4 -0
- package/esm/lib/utils/object.utils.js +6 -2
- package/esm/lib/utils/schema.utils.js +2 -1
- package/esm/lib/utils/source-builder.js +170 -80
- package/esm/lib/utils/string-builder/index.js +3 -0
- package/esm/lib/utils/string-builder/options.js +4 -0
- package/esm/lib/utils/string-builder/string-builder.js +138 -0
- package/esm/lib/utils/string-builder/utils.js +30 -0
- package/esm/lib/utils/string.utils.js +111 -105
- package/esm/lib/utils/type.utils.js +6 -1
- package/package.json +5 -5
- package/types/index.d.ts +1 -0
- package/types/lib/ast/index.d.ts +1 -0
- package/types/lib/ast/node.d.ts +14 -0
- package/types/lib/transform/api-types.d.ts +3 -1
- package/types/lib/utils/array.utils.d.ts +1 -0
- package/types/lib/utils/class.utils.d.ts +7 -0
- package/types/lib/utils/common.utils.d.ts +14 -2
- package/types/lib/utils/error.utils.d.ts +1 -0
- package/types/lib/utils/index.d.ts +4 -0
- package/types/lib/utils/object.utils.d.ts +1 -1
- package/types/lib/utils/source-builder.d.ts +55 -37
- package/types/lib/utils/string-builder/index.d.ts +3 -0
- package/types/lib/utils/string-builder/options.d.ts +8 -0
- package/types/lib/utils/string-builder/string-builder.d.ts +72 -0
- package/types/lib/utils/string-builder/utils.d.ts +21 -0
- package/types/lib/utils/string.utils.d.ts +20 -66
- package/types/lib/utils/type.utils.d.ts +44 -5
|
@@ -1,5 +1,32 @@
|
|
|
1
|
-
import { EOL } from 'os';
|
|
2
1
|
import { isNullish } from './common.utils';
|
|
2
|
+
export function adjustCasing(a, b) {
|
|
3
|
+
if (typeof a === 'string') {
|
|
4
|
+
if (typeof b === 'string') {
|
|
5
|
+
return b;
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
return Object.assign({ casing: a }, b);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
else if (typeof b === 'string') {
|
|
12
|
+
return Object.assign(Object.assign({}, a), { casing: b });
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return Object.assign(Object.assign({}, a), b);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function lowercase(str) {
|
|
19
|
+
return str.toLowerCase();
|
|
20
|
+
}
|
|
21
|
+
export function uppercase(str) {
|
|
22
|
+
return str.toUpperCase();
|
|
23
|
+
}
|
|
24
|
+
export function capitalize(str) {
|
|
25
|
+
return (str.charAt(0).toUpperCase() + str.slice(1));
|
|
26
|
+
}
|
|
27
|
+
export function uncapitalize(str) {
|
|
28
|
+
return (str.charAt(0).toLowerCase() + str.slice(1));
|
|
29
|
+
}
|
|
3
30
|
/**
|
|
4
31
|
* Gets the words from a string. Words are separated by capital letters. Leading numbers are removed. Non-alphanumerical characters are removed and interpreted as word seperators. Multiple uppercase letters are interpreted as one word.
|
|
5
32
|
* @param str The string to get the words from.
|
|
@@ -218,111 +245,90 @@ export function toCustomCase(str, options) {
|
|
|
218
245
|
export function escapeRegExp(str) {
|
|
219
246
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
220
247
|
}
|
|
221
|
-
export const defaultStringBuilderOptions = {
|
|
222
|
-
newLine: EOL,
|
|
223
|
-
};
|
|
224
248
|
/**
|
|
225
|
-
*
|
|
249
|
+
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
250
|
+
* @param str The string to splice.
|
|
251
|
+
* @param start The index at which to start changing the string.
|
|
252
|
+
* @param deleteCount The number of characters to remove.
|
|
253
|
+
* @param insert The string to insert.
|
|
254
|
+
* @returns The spliced string.
|
|
226
255
|
*/
|
|
227
|
-
export
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
return this;
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
309
|
-
* @param value The string(s) to prepend.
|
|
310
|
-
* @returns The current StringBuilder.
|
|
311
|
-
*/
|
|
312
|
-
prependLine(...value) {
|
|
313
|
-
return this.prepend(...value, this._options.newLine);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Converts the value of this instance to a string.
|
|
317
|
-
* @returns A string whose value is the same as this instance.
|
|
318
|
-
*/
|
|
319
|
-
toString() {
|
|
320
|
-
return this._str;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Removes all characters from the current StringBuilder.
|
|
324
|
-
*/
|
|
325
|
-
clear() {
|
|
326
|
-
this._str = '';
|
|
256
|
+
export function spliceString(str, start, deleteCount, insert) {
|
|
257
|
+
return str.slice(0, start) + insert + str.slice(start + deleteCount);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Removes leading indentation based on the last line. Also removes the first line if it is empty.
|
|
261
|
+
* @param str The string to trim.
|
|
262
|
+
*/
|
|
263
|
+
export function trimIndent(str) {
|
|
264
|
+
var _a, _b;
|
|
265
|
+
const indent = (_b = (_a = str.match(/\n( *).*$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '';
|
|
266
|
+
if (indent.length === 0)
|
|
267
|
+
return str;
|
|
268
|
+
return str.replace(/^\r?\n/, '').replace(new RegExp(`^ {0,${indent.length}}`, 'gm'), '');
|
|
269
|
+
}
|
|
270
|
+
function isNonLineBreakWhitespaceChar(char) {
|
|
271
|
+
return (char === ' ' ||
|
|
272
|
+
char === '\t' ||
|
|
273
|
+
char === '\f' ||
|
|
274
|
+
char === '\v' ||
|
|
275
|
+
char === '\u00a0' ||
|
|
276
|
+
char === '\u1680' ||
|
|
277
|
+
char === '\u2000' ||
|
|
278
|
+
char === '\u2001' ||
|
|
279
|
+
char === '\u2002' ||
|
|
280
|
+
char === '\u2003' ||
|
|
281
|
+
char === '\u2004' ||
|
|
282
|
+
char === '\u2005' ||
|
|
283
|
+
char === '\u2006' ||
|
|
284
|
+
char === '\u2007' ||
|
|
285
|
+
char === '\u2008' ||
|
|
286
|
+
char === '\u2009' ||
|
|
287
|
+
char === '\u200a' ||
|
|
288
|
+
char === '\u2028' ||
|
|
289
|
+
char === '\u2029' ||
|
|
290
|
+
char === '\u202f' ||
|
|
291
|
+
char === '\u205f' ||
|
|
292
|
+
char === '\u3000' ||
|
|
293
|
+
char === '\ufeff');
|
|
294
|
+
}
|
|
295
|
+
export function trimEnd(str, includeNewLine = true) {
|
|
296
|
+
if (includeNewLine)
|
|
297
|
+
return str.trimEnd();
|
|
298
|
+
let i = str.length;
|
|
299
|
+
for (; isNonLineBreakWhitespaceChar(str[i - 1]); i--)
|
|
300
|
+
;
|
|
301
|
+
return str.substring(0, i);
|
|
302
|
+
}
|
|
303
|
+
export function trimStart(str, includeNewLine = true) {
|
|
304
|
+
if (includeNewLine)
|
|
305
|
+
return str.trimStart();
|
|
306
|
+
let i = 0;
|
|
307
|
+
for (; isNonLineBreakWhitespaceChar(str[i]); i++)
|
|
308
|
+
;
|
|
309
|
+
return str.substring(i);
|
|
310
|
+
}
|
|
311
|
+
export function trim(str, includeNewLine = true) {
|
|
312
|
+
if (includeNewLine)
|
|
313
|
+
return str.trim();
|
|
314
|
+
let s = 0;
|
|
315
|
+
for (; isNonLineBreakWhitespaceChar(str[s]); s++)
|
|
316
|
+
;
|
|
317
|
+
let e = str.length;
|
|
318
|
+
for (; isNonLineBreakWhitespaceChar(str[e - 1]); e--)
|
|
319
|
+
;
|
|
320
|
+
return str.substring(s, e);
|
|
321
|
+
}
|
|
322
|
+
export function removeStr(str, rem) {
|
|
323
|
+
let i = str.indexOf(rem);
|
|
324
|
+
if (i === -1)
|
|
325
|
+
return str;
|
|
326
|
+
let result = '';
|
|
327
|
+
let s = 0;
|
|
328
|
+
while (i !== -1) {
|
|
329
|
+
result += str.substring(s, i);
|
|
330
|
+
s = i + rem.length;
|
|
331
|
+
i = str.indexOf(rem, s);
|
|
327
332
|
}
|
|
333
|
+
return result + str.substring(s);
|
|
328
334
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goast/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"repository": "https://github.com/MaSch0212/goast.git",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Marc Schmidt (MaSch0212)",
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"fs-extra": "^11.
|
|
13
|
-
"node-fetch": "^2.
|
|
14
|
-
"yaml": "^2.
|
|
15
|
-
"tslib": "
|
|
12
|
+
"fs-extra": "^11.2.0",
|
|
13
|
+
"node-fetch": "^2.7.0",
|
|
14
|
+
"yaml": "^2.4.1",
|
|
15
|
+
"tslib": "2.6.2"
|
|
16
16
|
},
|
|
17
17
|
"module": "./esm/index.js",
|
|
18
18
|
"main": "./cjs/index.js",
|
package/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './node';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AppendValue, Prettify, StringBuilder } from '../utils';
|
|
2
|
+
export type AstNodeInject<TBuilder extends StringBuilder, TInjects extends string> = {
|
|
3
|
+
[K in `${'after' | 'before'}${Capitalize<TInjects>}`]?: AppendValue<TBuilder>;
|
|
4
|
+
};
|
|
5
|
+
export type AstNodeOptions<TBase extends abstract new (...args: any) => any, TExtensions extends object = {}> = Prettify<TExtensions & ConstructorParameters<TBase>[0]>;
|
|
6
|
+
export declare abstract class AstNode<TBuilder extends StringBuilder = StringBuilder, TInjects extends string = never> {
|
|
7
|
+
inject: AstNodeInject<TBuilder, TInjects | ''>;
|
|
8
|
+
constructor(options: {
|
|
9
|
+
inject?: AstNode<TBuilder, TInjects>['inject'];
|
|
10
|
+
});
|
|
11
|
+
write(builder: TBuilder): void;
|
|
12
|
+
protected getParentNode(builder: TBuilder): AstNode | undefined;
|
|
13
|
+
protected abstract onWrite(builder: TBuilder): void;
|
|
14
|
+
}
|
|
@@ -108,7 +108,9 @@ export type ApiSchemaBase = ApiSchemaComponent & {
|
|
|
108
108
|
custom: Record<string, unknown>;
|
|
109
109
|
not: ApiSchema | undefined;
|
|
110
110
|
discriminator: ApiSchemaDiscriminator | undefined;
|
|
111
|
-
inheritedSchemas: ApiSchema
|
|
111
|
+
inheritedSchemas: (ApiSchema & {
|
|
112
|
+
discriminator: NonNullable<ApiSchema['discriminator']>;
|
|
113
|
+
})[];
|
|
112
114
|
};
|
|
113
115
|
export type ApiSchema<T extends ApiSchemaKind = ApiSchemaKind> = ApiSchemaBase & ApiSchemaExtensions<T>;
|
|
114
116
|
type AdditionalCombinedSchemaProperties = {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function removeItems<T>(array: T[], predicate: (item: T) => boolean): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function classifyArray<TItem, TClassification extends Record<string, abstract new (...args: any[]) => any>>(items: Iterable<TItem>, classification: TClassification): {
|
|
2
|
+
[P in keyof TClassification]: InstanceType<TClassification[P]>[];
|
|
3
|
+
} & {
|
|
4
|
+
rest: Exclude<TItem, InstanceType<TClassification[string]>>[];
|
|
5
|
+
};
|
|
6
|
+
export declare function isInstanceOf<T>(item: unknown, type: abstract new (...args: any[]) => T): item is T;
|
|
7
|
+
export declare function getIsInstanceOf<T>(type: abstract new (...args: any[]) => T): (item: unknown) => item is T;
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SingleOrMultiple } from './type.utils';
|
|
2
2
|
export declare function isNullish(value: unknown): value is null | undefined;
|
|
3
|
-
export declare function notNullish<T>(value:
|
|
3
|
+
export declare function notNullish<T>(value: T): value is NonNullable<T>;
|
|
4
|
+
export declare function concatSingleOrMultiple<T>(...values: SingleOrMultiple<T>[]): SingleOrMultiple<T>;
|
|
5
|
+
export declare function isIterable(value: unknown): value is Iterable<unknown>;
|
|
6
|
+
export declare function toArray<T>(value: T | T[] | Iterable<T>): T[];
|
|
7
|
+
export declare function modify<T>(value: T, callback: (value: NonNullable<T>) => void): T;
|
|
8
|
+
export declare function run<T>(value: T, callback: (value: T) => void): T;
|
|
9
|
+
export declare function transform<T, U>(value: T, callback: (value: T) => U): U;
|
|
10
|
+
type IterableItem<T> = T extends Iterable<infer U> ? U : never;
|
|
11
|
+
export declare function modifyEach<T extends Iterable<unknown>>(values: T, callback: (value: NonNullable<IterableItem<T>>) => void): T;
|
|
12
|
+
export declare function runEach<T extends Iterable<unknown>>(values: T, callback: (value: IterableItem<T>) => void): T;
|
|
13
|
+
export declare function transformEach<T, U>(values: Iterable<T>, callback: (value: T) => U): U[];
|
|
14
|
+
export declare function asVoid(_: unknown): void;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function throwExp(message: string): never;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
+
export * from './array.utils';
|
|
2
|
+
export * from './class.utils';
|
|
1
3
|
export * from './common.utils';
|
|
2
4
|
export * from './endpoint.utils';
|
|
5
|
+
export * from './error.utils';
|
|
3
6
|
export * from './factory';
|
|
4
7
|
export * from './generator.utils';
|
|
5
8
|
export * from './object.utils';
|
|
6
9
|
export * from './schema.utils';
|
|
7
10
|
export * from './source-builder';
|
|
11
|
+
export * from './string-builder';
|
|
8
12
|
export * from './string.utils';
|
|
9
13
|
export * from './string.utils.types';
|
|
10
14
|
export * from './type.utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function createOverwriteProxy<T extends object>(target: T): T;
|
|
1
|
+
export declare function createOverwriteProxy<T extends object>(target: T, values?: Partial<T>): T;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Condition } from './condition';
|
|
2
|
-
import {
|
|
2
|
+
import { AppendParam, AppendValue, StringBuilder, StringBuilderOptions } from './string-builder';
|
|
3
|
+
import { BuilderFn } from './string-builder/string-builder';
|
|
3
4
|
import { Nullable } from './type.utils';
|
|
4
5
|
export type IndentOptions = {
|
|
5
6
|
readonly type: 'tabs';
|
|
@@ -9,13 +10,12 @@ export type IndentOptions = {
|
|
|
9
10
|
};
|
|
10
11
|
export type SourceBuilderOptions = StringBuilderOptions & {
|
|
11
12
|
indent: IndentOptions;
|
|
12
|
-
charsTreatedAsEmptyLine: string[];
|
|
13
13
|
};
|
|
14
14
|
export declare const defaultSourceBuilderOptions: SourceBuilderOptions;
|
|
15
15
|
type KnownParatheses = '()' | '[]' | '{}' | '<>';
|
|
16
|
-
export type Paratheses = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<
|
|
17
|
-
export type SeparatorBuidlerFn<TBuilder
|
|
18
|
-
export type Separator<TBuilder
|
|
16
|
+
export type Paratheses<TBuilder extends StringBuilder> = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<AppendValue<TBuilder>>, close: Nullable<AppendValue<TBuilder>>];
|
|
17
|
+
export type SeparatorBuidlerFn<TBuilder, TItem> = (builder: TBuilder, previousItem: TItem, nextItem: TItem, previousItemIndex: number, nextItemIndex: number) => void;
|
|
18
|
+
export type Separator<TBuilder, TItem> = string | SeparatorBuidlerFn<TBuilder, TItem>;
|
|
19
19
|
/**
|
|
20
20
|
* Options for the `parenthesize` methods of the `SourceBuilder`.
|
|
21
21
|
* @see SourceBuilder.parenthesize
|
|
@@ -23,20 +23,28 @@ export type Separator<TBuilder extends SourceBuilder, TItem> = string | Separato
|
|
|
23
23
|
*/
|
|
24
24
|
export type ParenthesizeOptions = {
|
|
25
25
|
/**
|
|
26
|
-
* Whether to add line breaks after start and before end of the parentheses.
|
|
26
|
+
* Whether to add line breaks after start and before end of the parentheses.
|
|
27
|
+
* @default false
|
|
27
28
|
*/
|
|
28
29
|
readonly multiline?: boolean;
|
|
29
30
|
/**
|
|
30
|
-
* Whether to indent the content inside parentheses.
|
|
31
|
+
* Whether to indent the content inside parentheses.
|
|
32
|
+
* @default true
|
|
31
33
|
*/
|
|
32
34
|
readonly indent?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to pretend that the current line and the one before is empty or consists only of whitespace characters.
|
|
37
|
+
* This is useful when the parentheses are used as a block and `ensurePreviousLineEmpty` is used.
|
|
38
|
+
* @default true
|
|
39
|
+
*/
|
|
40
|
+
readonly pretendEmpty?: boolean;
|
|
33
41
|
};
|
|
34
42
|
/**
|
|
35
43
|
* Options for the `forEach` methods of the `SourceBuilder`.
|
|
36
44
|
* @see SourceBuilder.forEach
|
|
37
45
|
* @see SourceBuilder.forEachIf
|
|
38
46
|
*/
|
|
39
|
-
export type ForEachOptions<TBuilder
|
|
47
|
+
export type ForEachOptions<TBuilder, TItem> = {
|
|
40
48
|
/**
|
|
41
49
|
* The condition to check before adding content for each item. Defaults to `true`.
|
|
42
50
|
*/
|
|
@@ -46,21 +54,20 @@ export type ForEachOptions<TBuilder extends SourceBuilder, TItem> = {
|
|
|
46
54
|
*/
|
|
47
55
|
readonly separator?: Separator<TBuilder, TItem>;
|
|
48
56
|
};
|
|
57
|
+
type SwitchCase<TValue, TBuilder extends StringBuilder> = {
|
|
58
|
+
case: TValue;
|
|
59
|
+
value: AppendValue<TBuilder>;
|
|
60
|
+
};
|
|
49
61
|
/**
|
|
50
62
|
* Represents an in-memory source file.
|
|
51
63
|
*/
|
|
52
|
-
export declare class SourceBuilder extends StringBuilder {
|
|
64
|
+
export declare class SourceBuilder<TAdditionalAppends = never> extends StringBuilder<TAdditionalAppends> {
|
|
53
65
|
private readonly __options;
|
|
54
|
-
private readonly _emptyLineCharRegex;
|
|
55
66
|
private readonly _indentString;
|
|
56
|
-
private _linePrefix;
|
|
57
67
|
private _isLineIndented;
|
|
58
68
|
private _isLastLineEmpty;
|
|
59
69
|
private _isCurrentLineEmpty;
|
|
60
|
-
|
|
61
|
-
* Gets or sets the current indentation level.
|
|
62
|
-
*/
|
|
63
|
-
currentIndentLevel: number;
|
|
70
|
+
private _linePrefixNodes;
|
|
64
71
|
/**
|
|
65
72
|
* Gets the options used by this instance.
|
|
66
73
|
*/
|
|
@@ -83,63 +90,58 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
83
90
|
* @param options The options to use for the `SourceBuilder` instance.
|
|
84
91
|
* @returns The string built by the `SourceBuilder` instance.
|
|
85
92
|
*/
|
|
86
|
-
static build(buildAction:
|
|
87
|
-
|
|
88
|
-
* Appends one or more strings to the end of the current SourceBuilder.
|
|
89
|
-
* @param value The string(s) to append.
|
|
90
|
-
* @returns The current SourceBuilder.
|
|
91
|
-
*/
|
|
92
|
-
append(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
93
|
+
static build(buildAction: AppendParam<SourceBuilder, never>, options?: Partial<SourceBuilderOptions>): string;
|
|
94
|
+
protected appendSingle(value: AppendParam<this, TAdditionalAppends>): void;
|
|
93
95
|
/**
|
|
94
96
|
* Appends one or more strings to the end of the current SourceBuilder if the specified condition is true.
|
|
95
97
|
* @param condition The condition to check before appending the specified value.
|
|
96
98
|
* @param value The string(s) to append.
|
|
97
99
|
* @returns The current SourceBuilder.
|
|
98
100
|
*/
|
|
99
|
-
appendIf(condition: Condition, ...value:
|
|
101
|
+
appendIf(condition: Condition, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
100
102
|
/**
|
|
101
103
|
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator.
|
|
102
104
|
* @param value The string(s) to append.
|
|
103
105
|
* @returns The current SourceBuilder.
|
|
104
106
|
*/
|
|
105
|
-
appendLine(...value:
|
|
107
|
+
appendLine(...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
106
108
|
/**
|
|
107
109
|
* Appends one or more strings to the end of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
108
110
|
* @param condition The condition to check before appending the specified value.
|
|
109
111
|
* @param value The string(s) to append.
|
|
110
112
|
* @returns The current SourceBuilder.
|
|
111
113
|
*/
|
|
112
|
-
appendLineIf(condition: Condition, ...value:
|
|
114
|
+
appendLineIf(condition: Condition, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
113
115
|
/**
|
|
114
116
|
* Appends the specified values to this source builder with the specified line prefix.
|
|
115
117
|
* @param {string} prefix - The line prefix to use.
|
|
116
118
|
* @param {...(string|null|undefined)} value - The values to append.
|
|
117
119
|
* @returns {SourceBuilder} This source builder instance.
|
|
118
120
|
*/
|
|
119
|
-
appendWithLinePrefix(prefix: string, ...value:
|
|
121
|
+
appendWithLinePrefix(prefix: string, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
120
122
|
/**
|
|
121
123
|
* Appends the specified values to this source builder as a new line with the specified line prefix.
|
|
122
124
|
* @param {string} prefix - The line prefix to use.
|
|
123
125
|
* @param {...(string|null|undefined)} value - The values to append.
|
|
124
126
|
* @returns {SourceBuilder} This source builder instance.
|
|
125
127
|
*/
|
|
126
|
-
appendLineWithLinePrefix(prefix: string, ...value:
|
|
128
|
+
appendLineWithLinePrefix(prefix: string, ...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
127
129
|
/**
|
|
128
130
|
* Prepends one or more strings to the beginning of the current SourceBuilder if the specified condition is true.
|
|
129
131
|
* @param condition The condition to check before prepending the specified value.
|
|
130
132
|
* @param value The string(s) to prepend.
|
|
131
133
|
* @returns The current SourceBuilder.
|
|
132
134
|
*/
|
|
133
|
-
prependIf(condition: Condition, ...value:
|
|
135
|
+
prependIf(condition: Condition, ...value: AppendParam<StringBuilder, never>[]): this;
|
|
134
136
|
/**
|
|
135
137
|
* Prepends one or more strings to the beginning of the current SourceBuilder, followed by a line terminator, if the specified condition is true.
|
|
136
138
|
* @param condition The condition to check before appending the specified value.
|
|
137
139
|
* @param value The string(s) to prepend.
|
|
138
140
|
* @returns The current SourceBuilder.
|
|
139
141
|
*/
|
|
140
|
-
prependLineIf(condition: Condition, ...value:
|
|
142
|
+
prependLineIf(condition: Condition, ...value: AppendParam<StringBuilder, never>[]): this;
|
|
141
143
|
/**
|
|
142
|
-
* Ensures that the current line is empty or consists only of whitespace characters.
|
|
144
|
+
* Ensures that the current line and the one before is empty or consists only of whitespace characters.
|
|
143
145
|
* @returns A reference to this instance.
|
|
144
146
|
*/
|
|
145
147
|
ensurePreviousLineEmpty(): this;
|
|
@@ -148,6 +150,16 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
148
150
|
* @returns A reference to this instance.
|
|
149
151
|
*/
|
|
150
152
|
ensureCurrentLineEmpty(): this;
|
|
153
|
+
/**
|
|
154
|
+
* Pretends that the current line and the one before is empty or consists only of whitespace characters.
|
|
155
|
+
* @returns A reference to this instance.
|
|
156
|
+
*/
|
|
157
|
+
pretendPreviousLineEmpty(): this;
|
|
158
|
+
/**
|
|
159
|
+
* Pretends that the current line is empty or consists only of whitespace characters.
|
|
160
|
+
* @returns A reference to this instance.
|
|
161
|
+
*/
|
|
162
|
+
pretendCurrentLineEmpty(): this;
|
|
151
163
|
/**
|
|
152
164
|
* Inserts specified content if the specified condition is true.
|
|
153
165
|
* @param condition The condition to check before inserting content.
|
|
@@ -155,21 +167,23 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
155
167
|
* @param elseBuilderFn The function to add content if the condition is false.
|
|
156
168
|
* @returns A reference to this instance.
|
|
157
169
|
*/
|
|
158
|
-
if(condition: Condition, builderFn:
|
|
170
|
+
if(condition: Condition, builderFn: AppendParam<this, TAdditionalAppends>, elseBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
|
|
171
|
+
switch<T extends string | number>(value: T, cases: Record<T, AppendParam<this, TAdditionalAppends>>, defaultBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
|
|
172
|
+
switch<T>(value: T, cases: SwitchCase<T, this>[], defaultBuilderFn?: AppendParam<this, TAdditionalAppends>, equals?: (a: T, b: T) => boolean): this;
|
|
159
173
|
/**
|
|
160
174
|
* Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
|
|
161
175
|
* @param builderFn The function to add indented content or the content itself.
|
|
162
176
|
* @param condition The condition to check before adding indentation.
|
|
163
177
|
* @returns A reference to this instance.
|
|
164
178
|
*/
|
|
165
|
-
indent(value:
|
|
179
|
+
indent(value: AppendParam<this, TAdditionalAppends>): this;
|
|
166
180
|
/**
|
|
167
181
|
* Adds one indentation level if the specified condition is true. If the current line already contains characters, only subsequent lines are affected.
|
|
168
182
|
* @param builderFn The function to add indented content or the content itself.
|
|
169
183
|
* @param condition The condition to check before adding indentation.
|
|
170
184
|
* @returns A reference to this instance.
|
|
171
185
|
*/
|
|
172
|
-
indentIf(condition: Condition, value:
|
|
186
|
+
indentIf(condition: Condition, value: AppendParam<this, TAdditionalAppends>): this;
|
|
173
187
|
/**
|
|
174
188
|
* Adds parentheses around the specified content.
|
|
175
189
|
* @param brackets The brackets to use.
|
|
@@ -177,7 +191,7 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
177
191
|
* @param options Options for the parentheses.
|
|
178
192
|
* @returns A reference to this instance.
|
|
179
193
|
*/
|
|
180
|
-
parenthesize(brackets: Paratheses
|
|
194
|
+
parenthesize(brackets: Paratheses<this>, value: AppendParam<this, TAdditionalAppends>, options?: ParenthesizeOptions): this;
|
|
181
195
|
/**
|
|
182
196
|
* Adds parentheses around the specified content if the specified condition is true.
|
|
183
197
|
* @param condition The condition to check before adding parentheses.
|
|
@@ -186,7 +200,7 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
186
200
|
* @param options Options for the parentheses.
|
|
187
201
|
* @returns A reference to this instance.
|
|
188
202
|
*/
|
|
189
|
-
parenthesizeIf(condition: Condition, brackets: Paratheses
|
|
203
|
+
parenthesizeIf(condition: Condition, brackets: Paratheses<this>, value: AppendParam<this, TAdditionalAppends>, options?: ParenthesizeOptions): this;
|
|
190
204
|
/**
|
|
191
205
|
* Adds content for each item in the specified array.
|
|
192
206
|
* @param items The items to add content for.
|
|
@@ -196,8 +210,12 @@ export declare class SourceBuilder extends StringBuilder {
|
|
|
196
210
|
*/
|
|
197
211
|
forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
198
212
|
forEachIf<T>(condition: Condition, items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
|
|
199
|
-
appendSeparated(items: Iterable<
|
|
200
|
-
appendSeparatedIf(condition: Condition, items: Iterable<
|
|
213
|
+
appendSeparated(items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
|
|
214
|
+
appendSeparatedIf(condition: Condition, items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
|
|
201
215
|
private appendIndent;
|
|
202
216
|
}
|
|
217
|
+
declare function _builderTemplate<T extends SourceBuilder>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]): BuilderFn<T>;
|
|
218
|
+
export declare const builderTemplate: typeof _builderTemplate & {
|
|
219
|
+
indent: <T extends SourceBuilder<never>>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]) => BuilderFn<T>;
|
|
220
|
+
};
|
|
203
221
|
export {};
|