@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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { StringBuilderOptions } from './options';
|
|
2
|
+
import { Nullable, SingleOrMultiple } from '../type.utils';
|
|
3
|
+
export type BuilderFn<TBuilder extends StringBuilder> = (builder: TBuilder) => void;
|
|
4
|
+
export type Primitive = string | number | boolean;
|
|
5
|
+
export type AppendParam<TBuilder extends StringBuilder, TAdditionalAppends> = SingleOrMultiple<Primitive | null | undefined | BuilderFn<TBuilder> | TAdditionalAppends | {
|
|
6
|
+
__type: 'append-value-group';
|
|
7
|
+
values: AppendParam<TBuilder, TAdditionalAppends>[];
|
|
8
|
+
separator: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
export declare const AdditionalAppendsSymbol: unique symbol;
|
|
11
|
+
/**
|
|
12
|
+
* Represents a mutable string of characters.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StringBuilder<TAdditionalAppends = never> {
|
|
15
|
+
private readonly _options;
|
|
16
|
+
protected str: string;
|
|
17
|
+
[AdditionalAppendsSymbol](_: TAdditionalAppends): void;
|
|
18
|
+
get options(): StringBuilderOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Initializes a new instance of the StringBuilder class.
|
|
21
|
+
* @param options The options.
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: Partial<StringBuilderOptions>);
|
|
24
|
+
/**
|
|
25
|
+
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
26
|
+
* @param str The string to append.
|
|
27
|
+
* @param options The options.
|
|
28
|
+
* @returns A new StringBuilder instance.
|
|
29
|
+
*/
|
|
30
|
+
static fromString(str: string, options?: Partial<StringBuilderOptions>): StringBuilder;
|
|
31
|
+
/**
|
|
32
|
+
* Builds a string using a StringBuilder build action.
|
|
33
|
+
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
34
|
+
* @param options The options for the StringBuilder instance.
|
|
35
|
+
* @returns The built string.
|
|
36
|
+
*/
|
|
37
|
+
static build(buildAction: AppendParam<StringBuilder, never>, options?: Partial<StringBuilderOptions>): string;
|
|
38
|
+
protected appendSingle(value: AppendParam<this, TAdditionalAppends>): void;
|
|
39
|
+
/**
|
|
40
|
+
* Appends one or more strings to the end of the current StringBuilder.
|
|
41
|
+
* @param value The string(s) to append.
|
|
42
|
+
* @returns The current StringBuilder.
|
|
43
|
+
*/
|
|
44
|
+
append(...value: AppendParam<this, TAdditionalAppends>[]): this;
|
|
45
|
+
/**
|
|
46
|
+
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
47
|
+
* @param value
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
appendLine(...value: Nullable<AppendParam<this, TAdditionalAppends>>[]): this;
|
|
51
|
+
/**
|
|
52
|
+
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
53
|
+
* @param value The string(s) to prepend.
|
|
54
|
+
* @returns The current StringBuilder.
|
|
55
|
+
*/
|
|
56
|
+
prepend(...value: AppendParam<StringBuilder, never>[]): this;
|
|
57
|
+
/**
|
|
58
|
+
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
59
|
+
* @param value The string(s) to prepend.
|
|
60
|
+
* @returns The current StringBuilder.
|
|
61
|
+
*/
|
|
62
|
+
prependLine(...value: AppendParam<StringBuilder, never>[]): this;
|
|
63
|
+
/**
|
|
64
|
+
* Converts the value of this instance to a string.
|
|
65
|
+
* @returns A string whose value is the same as this instance.
|
|
66
|
+
*/
|
|
67
|
+
toString(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Removes all characters from the current StringBuilder.
|
|
70
|
+
*/
|
|
71
|
+
clear(): void;
|
|
72
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Nullable } from '../type.utils';
|
|
2
|
+
import type { AdditionalAppendsSymbol, AppendParam, BuilderFn, Primitive, StringBuilder } from './string-builder';
|
|
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>;
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { WordCasing, StringCasing, CamelCaseOptions, PascalCaseOptions, KebabCaseOptions, SnakeCaseOptions, CustomCaseOptions, StringCasingWithOptions } from './string.utils.types';
|
|
2
2
|
import { Nullable } from './type.utils';
|
|
3
|
+
export declare function adjustCasing(a: StringCasing, b: StringCasing): StringCasing;
|
|
4
|
+
export declare function adjustCasing(a: StringCasing | StringCasingWithOptions, b: StringCasing | Partial<StringCasingWithOptions>): StringCasingWithOptions;
|
|
5
|
+
export declare function lowercase<T extends string>(str: T): Lowercase<T>;
|
|
6
|
+
export declare function uppercase<T extends string>(str: T): Uppercase<T>;
|
|
7
|
+
export declare function capitalize<T extends string>(str: T): Capitalize<T>;
|
|
8
|
+
export declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>;
|
|
3
9
|
/**
|
|
4
10
|
* 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
11
|
* @param str The string to get the words from.
|
|
@@ -104,72 +110,20 @@ export declare function toCustomCase(str: Nullable<string>, options: CustomCaseO
|
|
|
104
110
|
*/
|
|
105
111
|
export declare function escapeRegExp(str: string): string;
|
|
106
112
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
113
|
+
* Removes characters from a string and, if necessary, inserts new characters in their place, returning the spliced string.
|
|
114
|
+
* @param str The string to splice.
|
|
115
|
+
* @param start The index at which to start changing the string.
|
|
116
|
+
* @param deleteCount The number of characters to remove.
|
|
117
|
+
* @param insert The string to insert.
|
|
118
|
+
* @returns The spliced string.
|
|
109
119
|
*/
|
|
110
|
-
export
|
|
111
|
-
readonly newLine: string;
|
|
112
|
-
};
|
|
113
|
-
export declare const defaultStringBuilderOptions: StringBuilderOptions;
|
|
114
|
-
export type BuilderFn<TBuilder extends StringBuilder> = (builder: TBuilder) => void;
|
|
115
|
-
export type TextOrBuilderFn<TBuilder extends StringBuilder> = string | BuilderFn<TBuilder>;
|
|
120
|
+
export declare function spliceString(str: string, start: number, deleteCount: number, insert: string): string;
|
|
116
121
|
/**
|
|
117
|
-
*
|
|
122
|
+
* Removes leading indentation based on the last line. Also removes the first line if it is empty.
|
|
123
|
+
* @param str The string to trim.
|
|
118
124
|
*/
|
|
119
|
-
export declare
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* Initializes a new instance of the StringBuilder class.
|
|
125
|
-
* @param options The options.
|
|
126
|
-
*/
|
|
127
|
-
constructor(options?: Partial<StringBuilderOptions>);
|
|
128
|
-
/**
|
|
129
|
-
* Creates a new StringBuilder instance and appends the specified string to it.
|
|
130
|
-
* @param str The string to append.
|
|
131
|
-
* @param options The options.
|
|
132
|
-
* @returns A new StringBuilder instance.
|
|
133
|
-
*/
|
|
134
|
-
static fromString(str: string, options?: Partial<StringBuilderOptions>): StringBuilder;
|
|
135
|
-
/**
|
|
136
|
-
* Builds a string using a StringBuilder build action.
|
|
137
|
-
* @param buildAction The build action to perform on the StringBuilder instance.
|
|
138
|
-
* @param options The options for the StringBuilder instance.
|
|
139
|
-
* @returns The built string.
|
|
140
|
-
*/
|
|
141
|
-
static build(buildAction: (builder: StringBuilder) => void, options?: Partial<StringBuilderOptions>): string;
|
|
142
|
-
/**
|
|
143
|
-
* Appends one or more strings to the end of the current StringBuilder.
|
|
144
|
-
* @param value The string(s) to append.
|
|
145
|
-
* @returns The current StringBuilder.
|
|
146
|
-
*/
|
|
147
|
-
append(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
148
|
-
/**
|
|
149
|
-
* Appends one or more strings to the end of the current StringBuilder, followed by a line terminator.
|
|
150
|
-
* @param value
|
|
151
|
-
* @returns
|
|
152
|
-
*/
|
|
153
|
-
appendLine(...value: Nullable<TextOrBuilderFn<this>>[]): this;
|
|
154
|
-
/**
|
|
155
|
-
* Prepends one or more strings to the beginning of the current StringBuilder.
|
|
156
|
-
* @param value The string(s) to prepend.
|
|
157
|
-
* @returns The current StringBuilder.
|
|
158
|
-
*/
|
|
159
|
-
prepend(...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
160
|
-
/**
|
|
161
|
-
* Prepends one or more strings to the beginning of the current StringBuilder, followed by a line terminator.
|
|
162
|
-
* @param value The string(s) to prepend.
|
|
163
|
-
* @returns The current StringBuilder.
|
|
164
|
-
*/
|
|
165
|
-
prependLine(...value: Nullable<TextOrBuilderFn<StringBuilder>>[]): this;
|
|
166
|
-
/**
|
|
167
|
-
* Converts the value of this instance to a string.
|
|
168
|
-
* @returns A string whose value is the same as this instance.
|
|
169
|
-
*/
|
|
170
|
-
toString(): string;
|
|
171
|
-
/**
|
|
172
|
-
* Removes all characters from the current StringBuilder.
|
|
173
|
-
*/
|
|
174
|
-
clear(): void;
|
|
175
|
-
}
|
|
125
|
+
export declare function trimIndent(str: string): string;
|
|
126
|
+
export declare function trimEnd(str: string, includeNewLine?: boolean): string;
|
|
127
|
+
export declare function trimStart(str: string, includeNewLine?: boolean): string;
|
|
128
|
+
export declare function trim(str: string, includeNewLine?: boolean): string;
|
|
129
|
+
export declare function removeStr(str: string, rem: string): string;
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
type
|
|
2
|
-
[P in Exclude<keyof T, keyof U>]: T[P];
|
|
3
|
-
} & U;
|
|
4
|
-
export type Merge<U extends unknown[]> = U extends [infer A, ...infer R] ? MergeTwo<A, Merge<R>> : {};
|
|
1
|
+
export type Merge<U extends unknown[]> = U extends [infer A, ...infer R] ? A & Merge<R> : {};
|
|
5
2
|
export type OptionalProperties<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
6
3
|
export type RequiredProperties<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
7
4
|
export type ArrayItem<T> = T extends (infer U)[] ? U : never;
|
|
5
|
+
export type SingleOrMultiple<T> = T | T[];
|
|
6
|
+
export type Single<T> = T extends (infer U)[] ? U : T;
|
|
7
|
+
export type Multiple<T> = T extends (infer U)[] ? U[] : T[];
|
|
8
8
|
export type Nullable<T> = T | null | undefined;
|
|
9
|
-
export interface Constructor<T, TArgs extends any[]> extends Function {
|
|
9
|
+
export interface Constructor<T, TArgs extends any[] = any[]> extends Function {
|
|
10
10
|
new (...args: TArgs): T;
|
|
11
11
|
}
|
|
12
12
|
export type EmptyConstructor<T> = Constructor<T, []>;
|
|
13
13
|
export type FunctionNames<T> = {
|
|
14
14
|
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;
|
|
15
15
|
}[keyof T];
|
|
16
|
+
export type Prettify<T> = {
|
|
17
|
+
[K in keyof T]: T[K];
|
|
18
|
+
} & {};
|
|
19
|
+
export type ValueOf<T> = T[keyof T];
|
|
20
|
+
export type NonEmptyArray<T> = [T, ...T[]];
|
|
21
|
+
type MustInclude<T, U extends T[]> = [T] extends [ValueOf<U>] ? U : never;
|
|
22
|
+
export declare function stringUnionToArray<T>(): <U extends NonEmptyArray<T>>(...elements: MustInclude<T, U>) => MustInclude<T, U>;
|
|
23
|
+
export type StringSuggestions<T extends string> = T | Omit<string, T>;
|
|
24
|
+
export declare function suggestionsAsString<T>(value: T): T extends StringSuggestions<infer U> ? Exclude<T, StringSuggestions<U>> | string : T;
|
|
25
|
+
export type ParametersWithOverloads<T extends (...args: any[]) => any> = T extends {
|
|
26
|
+
(...args: infer A1): any;
|
|
27
|
+
(...args: infer A2): any;
|
|
28
|
+
(...args: infer A3): any;
|
|
29
|
+
(...args: infer A4): any;
|
|
30
|
+
(...args: infer A5): any;
|
|
31
|
+
(...args: infer A6): any;
|
|
32
|
+
} ? A1 | A2 | A3 | A4 | A5 | A6 : T extends {
|
|
33
|
+
(...args: infer A1): any;
|
|
34
|
+
(...args: infer A2): any;
|
|
35
|
+
(...args: infer A3): any;
|
|
36
|
+
(...args: infer A4): any;
|
|
37
|
+
(...args: infer A5): any;
|
|
38
|
+
} ? A1 | A2 | A3 | A4 | A5 : T extends {
|
|
39
|
+
(...args: infer A1): any;
|
|
40
|
+
(...args: infer A2): any;
|
|
41
|
+
(...args: infer A3): any;
|
|
42
|
+
(...args: infer A4): any;
|
|
43
|
+
} ? A1 | A2 | A3 | A4 : T extends {
|
|
44
|
+
(...args: infer A1): any;
|
|
45
|
+
(...args: infer A2): any;
|
|
46
|
+
(...args: infer A3): any;
|
|
47
|
+
} ? A1 | A2 | A3 : T extends {
|
|
48
|
+
(...args: infer A1): any;
|
|
49
|
+
(...args: infer A2): any;
|
|
50
|
+
} ? A1 | A2 : T extends {
|
|
51
|
+
(...args: infer A1): any;
|
|
52
|
+
} ? A1 : never;
|
|
53
|
+
type _TupleOf<T, N extends number, R extends unknown[]> = R['length'] extends N ? R : _TupleOf<T, N, [T, ...R]>;
|
|
54
|
+
export type TupleWithCount<T, N extends number | number[]> = N extends number ? number extends N ? T[] : _TupleOf<T, N, []> : N extends [infer A, ...infer R] ? A extends number ? R extends number[] ? TupleWithCount<T, A> | TupleWithCount<T, R> : never : never : N extends [] ? never : T[];
|
|
16
55
|
export {};
|