@goast/core 0.7.0 → 0.7.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.
Files changed (85) hide show
  1. package/dist/src/ast/node.d.ts +43 -0
  2. package/dist/src/ast/node.js +29 -0
  3. package/dist/src/codegen/config.d.ts +9 -0
  4. package/dist/src/codegen/config.js +4 -0
  5. package/dist/src/codegen/endpoints-generator.d.ts +32 -0
  6. package/dist/src/codegen/endpoints-generator.js +19 -0
  7. package/dist/src/codegen/generator.d.ts +108 -0
  8. package/dist/src/codegen/generator.js +103 -0
  9. package/dist/src/codegen/internal-utils.d.ts +8 -0
  10. package/dist/src/codegen/internal-utils.js +8 -0
  11. package/dist/src/codegen/schemas-generator.d.ts +33 -0
  12. package/dist/src/codegen/schemas-generator.js +20 -0
  13. package/dist/src/codegen/services-generator.d.ts +24 -0
  14. package/dist/src/codegen/services-generator.js +11 -0
  15. package/dist/src/codegen/types.d.ts +56 -0
  16. package/dist/src/collect/collector.d.ts +8 -0
  17. package/dist/src/collect/collector.js +8 -0
  18. package/dist/src/collect/helpers.d.ts +16 -0
  19. package/dist/src/collect/helpers.js +16 -0
  20. package/dist/src/collect/types.d.ts +28 -0
  21. package/dist/src/internal-utils.d.ts +7 -0
  22. package/dist/src/internal-utils.js +7 -0
  23. package/dist/src/parse/deref-proxy.d.ts +19 -0
  24. package/dist/src/parse/deref-proxy.js +19 -0
  25. package/dist/src/parse/openapi-types.d.ts +168 -0
  26. package/dist/src/parse/parser.d.ts +38 -0
  27. package/dist/src/parse/parser.js +38 -0
  28. package/dist/src/parse/types.d.ts +37 -0
  29. package/dist/src/parse/types.js +4 -0
  30. package/dist/src/transform/api-types.d.ts +408 -0
  31. package/dist/src/transform/helpers.d.ts +73 -0
  32. package/dist/src/transform/helpers.js +73 -0
  33. package/dist/src/transform/transform-document.d.ts +7 -0
  34. package/dist/src/transform/transform-document.js +7 -0
  35. package/dist/src/transform/transform-endpoint.d.ts +8 -0
  36. package/dist/src/transform/transform-endpoint.js +8 -0
  37. package/dist/src/transform/transform-schema.d.ts +10 -0
  38. package/dist/src/transform/transform-schema.js +10 -0
  39. package/dist/src/transform/transformer.d.ts +7 -0
  40. package/dist/src/transform/transformer.js +7 -0
  41. package/dist/src/transform/types.d.ts +61 -0
  42. package/dist/src/transform/types.js +4 -0
  43. package/dist/src/utils/action-provider.d.ts +38 -0
  44. package/dist/src/utils/action-provider.js +38 -0
  45. package/dist/src/utils/api-data.utils.d.ts +9 -0
  46. package/dist/src/utils/api-data.utils.js +9 -0
  47. package/dist/src/utils/array.utils.d.ts +7 -0
  48. package/dist/src/utils/array.utils.js +7 -0
  49. package/dist/src/utils/asset-manager.d.ts +22 -0
  50. package/dist/src/utils/asset-manager.js +22 -0
  51. package/dist/src/utils/class.utils.d.ts +22 -0
  52. package/dist/src/utils/class.utils.js +22 -0
  53. package/dist/src/utils/common.utils.d.ts +81 -0
  54. package/dist/src/utils/common.utils.js +81 -0
  55. package/dist/src/utils/condition.d.ts +22 -0
  56. package/dist/src/utils/endpoint.utils.d.ts +12 -0
  57. package/dist/src/utils/endpoint.utils.js +12 -0
  58. package/dist/src/utils/error.utils.d.ts +6 -0
  59. package/dist/src/utils/error.utils.js +6 -0
  60. package/dist/src/utils/factory.d.ts +45 -0
  61. package/dist/src/utils/factory.js +45 -0
  62. package/dist/src/utils/file-system.utils.d.ts +37 -0
  63. package/dist/src/utils/file-system.utils.js +20 -0
  64. package/dist/src/utils/generator.utils.d.ts +7 -0
  65. package/dist/src/utils/generator.utils.js +7 -0
  66. package/dist/src/utils/object.utils.d.ts +16 -0
  67. package/dist/src/utils/object.utils.js +16 -0
  68. package/dist/src/utils/schema-factory.d.ts +197 -0
  69. package/dist/src/utils/schema-factory.js +146 -0
  70. package/dist/src/utils/schema.utils.d.ts +15 -0
  71. package/dist/src/utils/schema.utils.js +15 -0
  72. package/dist/src/utils/source-builder.d.ts +103 -0
  73. package/dist/src/utils/source-builder.js +58 -0
  74. package/dist/src/utils/string-builder/string-builder.d.ts +24 -0
  75. package/dist/src/utils/string-builder/string-builder.js +11 -0
  76. package/dist/src/utils/string-builder/utils.d.ts +68 -0
  77. package/dist/src/utils/string-builder/utils.js +33 -0
  78. package/dist/src/utils/string.utils.d.ts +78 -0
  79. package/dist/src/utils/string.utils.js +64 -0
  80. package/dist/src/utils/string.utils.types.d.ts +34 -0
  81. package/dist/src/utils/type.utils.d.ts +132 -0
  82. package/dist/src/utils/type.utils.js +19 -0
  83. package/dist/src/utils/yaml-info.d.ts +35 -0
  84. package/dist/src/utils/yaml-info.js +25 -0
  85. package/package.json +1 -1
@@ -3,6 +3,10 @@ import { type StringBuilderOptions } from './string-builder/options.ts';
3
3
  import { type AppendParam, type BuilderFn, StringBuilder } from './string-builder/string-builder.ts';
4
4
  import type { AppendValue } from './string-builder/utils.ts';
5
5
  import type { Nullable } from './type.utils.ts';
6
+ /**
7
+ * Describes one level of indentation. `{ type: 'tabs' }` indents with a tab character, and `{ type: 'spaces', count }`
8
+ * indents with `count` space characters.
9
+ */
6
10
  export type IndentOptions = {
7
11
  readonly type: 'tabs';
8
12
  } | {
@@ -24,8 +28,31 @@ export type SourceBuilderOptions = StringBuilderOptions & {
24
28
  */
25
29
  export declare const defaultSourceBuilderOptions: SourceBuilderOptions;
26
30
  type KnownParatheses = '()' | '[]' | '{}' | '<>';
31
+ /**
32
+ * The brackets that `parenthesize` adds around content. A string is split into its characters, where the first
33
+ * character is the opening and the second character is the closing bracket. A tuple specifies the opening and closing
34
+ * values explicitly, and nullish values are appended as nothing.
35
+ * @template TBuilder The builder type that the brackets are appended to.
36
+ */
27
37
  export type Paratheses<TBuilder extends StringBuilder> = KnownParatheses | Omit<string, KnownParatheses> | [open: Nullable<AppendValue<TBuilder>>, close: Nullable<AppendValue<TBuilder>>];
38
+ /**
39
+ * A callback that appends a separator between two items of a `forEach` loop.
40
+ * @template TBuilder The builder type that the separator is appended to.
41
+ * @template TItem The type of the items.
42
+ * @param builder The builder to append the separator to.
43
+ * @param previousItem The item before the separator.
44
+ * @param nextItem The item after the separator.
45
+ * @param previousItemIndex The index of the item before the separator.
46
+ * @param nextItemIndex The index of the item after the separator.
47
+ */
28
48
  export type SeparatorBuidlerFn<TBuilder, TItem> = (builder: TBuilder, previousItem: TItem, nextItem: TItem, previousItemIndex: number, nextItemIndex: number) => void;
49
+ /**
50
+ * A separator between two items of a `forEach` loop: either a string that is appended as is, or a callback that appends
51
+ * the separator.
52
+ * @template TBuilder The builder type that the separator is appended to.
53
+ * @template TItem The type of the items.
54
+ * @see SeparatorBuidlerFn
55
+ */
29
56
  export type Separator<TBuilder, TItem> = string | SeparatorBuidlerFn<TBuilder, TItem>;
30
57
  /**
31
58
  * Options for the `parenthesize` methods of the `SourceBuilder`.
@@ -69,6 +96,11 @@ type SwitchCase<TValue, TBuilder extends StringBuilder> = {
69
96
  case: TValue;
70
97
  value: AppendValue<TBuilder>;
71
98
  };
99
+ /**
100
+ * Gets the string that represents one level of indentation.
101
+ * @param options The indentation to get the string for.
102
+ * @returns A tab character for tabs, or the number of spaces specified by `count`.
103
+ */
72
104
  export declare function getIndentString(options: IndentOptions): string;
73
105
  /**
74
106
  * Represents an in-memory source file.
@@ -84,6 +116,10 @@ export declare class SourceBuilder<TAdditionalAppends = never> extends StringBui
84
116
  * Gets the options used by this instance.
85
117
  */
86
118
  get options(): SourceBuilderOptions;
119
+ /**
120
+ * Gets a value indicating whether the current line is empty or consists only of whitespace characters.
121
+ * The `pretend...LineEmpty` methods affect this value.
122
+ */
87
123
  get isCurrentLineEmpty(): boolean;
88
124
  /**
89
125
  * Initializes a new instance of the SourceBuilder class.
@@ -181,7 +217,25 @@ export declare class SourceBuilder<TAdditionalAppends = never> extends StringBui
181
217
  * @returns A reference to this instance.
182
218
  */
183
219
  if(condition: Condition, builderFn: AppendParam<this, TAdditionalAppends>, elseBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
220
+ /**
221
+ * Appends the content of the case that has the specified key, or the default content if there is no such case.
222
+ * The content of a case that is nullish is replaced by the default content.
223
+ * @param value The value to switch on. Only strings and numbers are used as keys.
224
+ * @param cases The content of each case, keyed by the case value.
225
+ * @param defaultBuilderFn The content to append if no case matches.
226
+ * @returns A reference to this instance.
227
+ */
184
228
  switch<T extends string | number>(value: T, cases: Record<T, AppendParam<this, TAdditionalAppends>>, defaultBuilderFn?: AppendParam<this, TAdditionalAppends>): this;
229
+ /**
230
+ * Appends the content of the first case whose value matches the switch value, or the default content if none matches.
231
+ * This overload works with any value type and supports a custom comparison.
232
+ * @template T The type of the switch value and the case values.
233
+ * @param value The value to switch on.
234
+ * @param cases The cases to compare the value with, in order.
235
+ * @param defaultBuilderFn The content to append if no case matches.
236
+ * @param equals The function that compares the switch value with a case value. Defaults to strict equality.
237
+ * @returns A reference to this instance.
238
+ */
185
239
  switch<T>(value: T, cases: SwitchCase<T, this>[], defaultBuilderFn?: AppendParam<this, TAdditionalAppends>, equals?: (a: T, b: T) => boolean): this;
186
240
  /**
187
241
  * Adds one indentation level. If the current line already contains characters, only subsequent lines are affected.
@@ -222,14 +276,63 @@ export declare class SourceBuilder<TAdditionalAppends = never> extends StringBui
222
276
  * @returns A reference to this instance.
223
277
  */
224
278
  forEach<T>(items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
279
+ /**
280
+ * Adds content for each item in the specified items if the specified condition is true.
281
+ * @template T The type of the items.
282
+ * @param condition The condition to check before adding content for the items.
283
+ * @param items The items to add content for.
284
+ * @param builderFn The function to add content for each item.
285
+ * @param options The options for the loop.
286
+ * @returns A reference to this instance.
287
+ */
225
288
  forEachIf<T>(condition: Condition, items: Iterable<T>, builderFn: (builder: this, item: T, index: number) => void, options?: ForEachOptions<this, T>): this;
289
+ /**
290
+ * Appends the items with the specified separator between them. The separator is also appended before an item that
291
+ * appends nothing, such as `null`, so that item leaves an empty slot.
292
+ * @param items The items to append.
293
+ * @param separator The string to append between two items.
294
+ * @returns A reference to this instance.
295
+ * @example
296
+ * ```ts
297
+ * new SourceBuilder().appendSeparated(['a', 'b', 'c'], ', '); // => 'a, b, c'
298
+ * ```
299
+ */
226
300
  appendSeparated(items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
301
+ /**
302
+ * Appends the items with the specified separator between them if the specified condition is true.
303
+ * @param condition The condition to check before appending the items.
304
+ * @param items The items to append.
305
+ * @param separator The string to append between two items.
306
+ * @returns A reference to this instance.
307
+ * @see SourceBuilder.appendSeparated
308
+ */
227
309
  appendSeparatedIf(condition: Condition, items: Iterable<AppendParam<this, TAdditionalAppends>>, separator: string): this;
228
310
  private appendIndent;
229
311
  }
230
312
  declare function _builderTemplate<T extends SourceBuilder>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]): BuilderFn<T>;
231
313
  declare const _builderTemplateExtensions: {
314
+ /**
315
+ * Creates a builder function from a template, like `builderTemplate`, and indents its content by one level.
316
+ * @template T The type of the builder.
317
+ * @param template The strings of the template literal.
318
+ * @param substitutions The values that are substituted into the template.
319
+ * @returns A builder function that appends the indented content.
320
+ */
232
321
  readonly indent: <T extends SourceBuilder>(template: readonly string[] | ArrayLike<string>, ...substitutions: AppendValue<T>[]) => BuilderFn<T>;
233
322
  };
323
+ /**
324
+ * Creates a builder function from a template literal, which can be passed to `append`. Each substitution is appended as
325
+ * an append value. The indentation of the last line of the template is removed from the lines of the template, so the
326
+ * template can be indented to match the surrounding code. Use `builderTemplate.indent` to also indent the content by
327
+ * one level.
328
+ * @example
329
+ * ```ts
330
+ * const sb = new SourceBuilder({ newLine: '\n' });
331
+ * sb.append(builderTemplate`
332
+ * const ${name} = ${value};
333
+ * `);
334
+ * // => "\n const foo = 1;\n"
335
+ * ```
336
+ */
234
337
  export declare const builderTemplate: typeof _builderTemplate & typeof _builderTemplateExtensions;
235
338
  export {};
@@ -10,6 +10,11 @@ export const defaultSourceBuilderOptions = {
10
10
  ...defaultStringBuilderOptions,
11
11
  indent: { type: 'spaces', count: 2 },
12
12
  };
13
+ /**
14
+ * Gets the string that represents one level of indentation.
15
+ * @param options The indentation to get the string for.
16
+ * @returns A tab character for tabs, or the number of spaces specified by `count`.
17
+ */
13
18
  export function getIndentString(options) {
14
19
  return options.type === 'tabs' ? '\t' : ' '.repeat(options.count);
15
20
  }
@@ -29,6 +34,10 @@ export class SourceBuilder extends StringBuilder {
29
34
  get options() {
30
35
  return this.__options;
31
36
  }
37
+ /**
38
+ * Gets a value indicating whether the current line is empty or consists only of whitespace characters.
39
+ * The `pretend...LineEmpty` methods affect this value.
40
+ */
32
41
  get isCurrentLineEmpty() {
33
42
  return this._isCurrentLineEmpty;
34
43
  }
@@ -373,15 +382,43 @@ export class SourceBuilder extends StringBuilder {
373
382
  }
374
383
  return this;
375
384
  }
385
+ /**
386
+ * Adds content for each item in the specified items if the specified condition is true.
387
+ * @template T The type of the items.
388
+ * @param condition The condition to check before adding content for the items.
389
+ * @param items The items to add content for.
390
+ * @param builderFn The function to add content for each item.
391
+ * @param options The options for the loop.
392
+ * @returns A reference to this instance.
393
+ */
376
394
  forEachIf(condition, items, builderFn, options) {
377
395
  if (evalCondition(condition)) {
378
396
  return this.forEach(items, builderFn, options);
379
397
  }
380
398
  return this;
381
399
  }
400
+ /**
401
+ * Appends the items with the specified separator between them. The separator is also appended before an item that
402
+ * appends nothing, such as `null`, so that item leaves an empty slot.
403
+ * @param items The items to append.
404
+ * @param separator The string to append between two items.
405
+ * @returns A reference to this instance.
406
+ * @example
407
+ * ```ts
408
+ * new SourceBuilder().appendSeparated(['a', 'b', 'c'], ', '); // => 'a, b, c'
409
+ * ```
410
+ */
382
411
  appendSeparated(items, separator) {
383
412
  return this.forEach(items, (builder, item) => builder.append(item), { separator });
384
413
  }
414
+ /**
415
+ * Appends the items with the specified separator between them if the specified condition is true.
416
+ * @param condition The condition to check before appending the items.
417
+ * @param items The items to append.
418
+ * @param separator The string to append between two items.
419
+ * @returns A reference to this instance.
420
+ * @see SourceBuilder.appendSeparated
421
+ */
385
422
  appendSeparatedIf(condition, items, separator) {
386
423
  if (evalCondition(condition)) {
387
424
  return this.appendSeparated(items, separator);
@@ -411,8 +448,29 @@ function _builderTemplate(template, ...substitutions) {
411
448
  };
412
449
  }
413
450
  const _builderTemplateExtensions = {
451
+ /**
452
+ * Creates a builder function from a template, like `builderTemplate`, and indents its content by one level.
453
+ * @template T The type of the builder.
454
+ * @param template The strings of the template literal.
455
+ * @param substitutions The values that are substituted into the template.
456
+ * @returns A builder function that appends the indented content.
457
+ */
414
458
  indent: (template, ...substitutions) => {
415
459
  return (b) => b.indent(_builderTemplate(template, ...substitutions));
416
460
  },
417
461
  };
462
+ /**
463
+ * Creates a builder function from a template literal, which can be passed to `append`. Each substitution is appended as
464
+ * an append value. The indentation of the last line of the template is removed from the lines of the template, so the
465
+ * template can be indented to match the surrounding code. Use `builderTemplate.indent` to also indent the content by
466
+ * one level.
467
+ * @example
468
+ * ```ts
469
+ * const sb = new SourceBuilder({ newLine: '\n' });
470
+ * sb.append(builderTemplate`
471
+ * const ${name} = ${value};
472
+ * `);
473
+ * // => "\n const foo = 1;\n"
474
+ * ```
475
+ */
418
476
  export const builderTemplate = Object.assign(_builderTemplate, _builderTemplateExtensions);
@@ -1,12 +1,29 @@
1
1
  import type { Nullable, SingleOrMultiple } from '../type.utils.ts';
2
2
  import { type StringBuilderOptions } from './options.ts';
3
+ /**
4
+ * A callback that receives a builder and appends content to it.
5
+ * @template TBuilder The builder type that is passed to the callback.
6
+ */
3
7
  export type BuilderFn<TBuilder extends StringBuilder> = (builder: TBuilder) => void;
8
+ /**
9
+ * A primitive value that can be appended to a `StringBuilder`. Numbers and booleans are converted with `toString`.
10
+ */
4
11
  export type Primitive = string | number | boolean;
12
+ /**
13
+ * A value, or an array of values, that can be appended to a `StringBuilder`. Nullish values are ignored, arrays are
14
+ * flattened, and functions are invoked with the builder.
15
+ * @template TBuilder The builder type that the value is appended to.
16
+ * @template TAdditionalAppends Additional value types that the builder accepts.
17
+ */
5
18
  export type AppendParam<TBuilder extends StringBuilder, TAdditionalAppends> = SingleOrMultiple<Primitive | null | undefined | BuilderFn<TBuilder> | TAdditionalAppends | {
6
19
  __type: 'append-value-group';
7
20
  values: AppendParam<TBuilder, TAdditionalAppends>[];
8
21
  separator: string | null;
9
22
  }>;
23
+ /**
24
+ * The key of the method that carries the additional append types of a `StringBuilder` subclass in the type system.
25
+ * The method is never called at runtime.
26
+ */
10
27
  export declare const AdditionalAppendsSymbol: unique symbol;
11
28
  /**
12
29
  * Represents a mutable string of characters.
@@ -14,7 +31,14 @@ export declare const AdditionalAppendsSymbol: unique symbol;
14
31
  export declare class StringBuilder<TAdditionalAppends = never> {
15
32
  private readonly _options;
16
33
  protected str: string;
34
+ /**
35
+ * Type-only marker for the additional append types. Calling it throws, because it must never be called at runtime.
36
+ * @param _ The additional append value. Not used.
37
+ */
17
38
  [AdditionalAppendsSymbol](_: TAdditionalAppends): void;
39
+ /**
40
+ * Gets the options used by this instance.
41
+ */
18
42
  get options(): StringBuilderOptions;
19
43
  /**
20
44
  * Initializes a new instance of the StringBuilder class.
@@ -1,5 +1,9 @@
1
1
  import { isNullish } from '../common.utils.js';
2
2
  import { defaultStringBuilderOptions } from './options.js';
3
+ /**
4
+ * The key of the method that carries the additional append types of a `StringBuilder` subclass in the type system.
5
+ * The method is never called at runtime.
6
+ */
3
7
  export const AdditionalAppendsSymbol = Symbol('AdditionalAppends');
4
8
  /**
5
9
  * Represents a mutable string of characters.
@@ -7,9 +11,16 @@ export const AdditionalAppendsSymbol = Symbol('AdditionalAppends');
7
11
  export class StringBuilder {
8
12
  _options;
9
13
  str = '';
14
+ /**
15
+ * Type-only marker for the additional append types. Calling it throws, because it must never be called at runtime.
16
+ * @param _ The additional append value. Not used.
17
+ */
10
18
  [AdditionalAppendsSymbol](_) {
11
19
  throw new Error('This method should never be called.');
12
20
  }
21
+ /**
22
+ * Gets the options used by this instance.
23
+ */
13
24
  get options() {
14
25
  return this._options;
15
26
  }
@@ -1,21 +1,89 @@
1
1
  import type { Nullable } from '../type.utils.ts';
2
2
  import type { AdditionalAppendsSymbol, AppendParam, BuilderFn, Primitive, StringBuilder } from './string-builder.ts';
3
+ /**
4
+ * A value that can be appended to a `StringBuilder` without any additional append types: a primitive, a build function
5
+ * or an append value group.
6
+ * @template TBuilder The builder type that build functions receive.
7
+ */
3
8
  export type BasicAppendValue<TBuilder extends StringBuilder = StringBuilder> = Primitive | BuilderFn<TBuilder> | BasicAppendValueGroup<TBuilder>;
9
+ /**
10
+ * A group of basic append values that are appended one after another, optionally with a separator in between.
11
+ * @template TBuilder The builder type that build functions receive.
12
+ */
4
13
  export type BasicAppendValueGroup<TBuilder extends StringBuilder = StringBuilder> = {
14
+ /**
15
+ * The type marker that identifies the object as an append value group.
16
+ */
5
17
  __type: 'append-value-group';
18
+ /**
19
+ * The values to append in order.
20
+ */
6
21
  values: BasicAppendValue<TBuilder>[];
22
+ /**
23
+ * The string to append between two values, or `null` for no separator.
24
+ */
7
25
  separator: string | null;
8
26
  };
27
+ /**
28
+ * A value that can be appended to a `StringBuilder`, including the additional append types of the builder.
29
+ * @template TBuilder The builder type that determines the additional append types.
30
+ */
9
31
  export type AppendValue<TBuilder extends StringBuilder = StringBuilder> = NonNullable<AppendParam<TBuilder, Parameters<TBuilder[typeof AdditionalAppendsSymbol]>[0]>>;
32
+ /**
33
+ * A group of append values that are appended one after another, optionally with a separator in between.
34
+ * @template TBuilder The builder type that determines the additional append types.
35
+ */
10
36
  export type AppendValueGroup<TBuilder extends StringBuilder = StringBuilder> = {
37
+ /**
38
+ * The type marker that identifies the object as an append value group.
39
+ */
11
40
  __type: 'append-value-group';
41
+ /**
42
+ * The values to append in order.
43
+ */
12
44
  values: AppendValue<TBuilder>[];
45
+ /**
46
+ * The string to append between two values, or `null` for no separator.
47
+ */
13
48
  separator: string | null;
14
49
  };
15
50
  /** @deprecated Use AppendValue<TBuilder> instead */
16
51
  export type TextOrBuilderFn<TBuilder> = string | ((builder: TBuilder) => void);
52
+ /**
53
+ * Creates a group of basic append values. Nullish values are removed from the group.
54
+ * @template TBuilder The builder type that build functions receive.
55
+ * @param values The values to group. `null` and `undefined` yield an empty group.
56
+ * @param separator The string to append between two values. Defaults to no separator.
57
+ * @returns The append value group.
58
+ */
17
59
  export declare function basicAppendValueGroup<TBuilder extends StringBuilder = StringBuilder>(values: Nullable<Nullable<BasicAppendValue<TBuilder>>[]>, separator?: Nullable<string>): BasicAppendValueGroup<TBuilder>;
60
+ /**
61
+ * Creates a group of append values. Nullish values are removed from the group.
62
+ * @template TBuilder The builder type that determines the additional append types.
63
+ * @param values The values to group. `null` and `undefined` yield an empty group.
64
+ * @param separator The string to append between two values. Defaults to no separator.
65
+ * @returns The append value group.
66
+ */
18
67
  export declare function appendValueGroup<TBuilder extends StringBuilder = StringBuilder>(values: Nullable<Nullable<AppendValue<TBuilder>>[]>, separator?: Nullable<string>): AppendValueGroup<TBuilder>;
68
+ /**
69
+ * Checks whether a value is a basic append value: a string, number, boolean, function or append value group.
70
+ * Nullish values, arrays and other objects are not append values.
71
+ * @param value The value to check.
72
+ * @returns `true` if the value is an append value; otherwise, `false`.
73
+ */
19
74
  export declare function isAppendValue(value: unknown): value is AppendValue<never>;
75
+ /**
76
+ * Checks whether a value is an append value group, that is an object with the `append-value-group` type marker.
77
+ * @template TBuilder The builder type of the group.
78
+ * @param value The value to check.
79
+ * @returns `true` if the value is an append value group; otherwise, `false`.
80
+ */
20
81
  export declare function isAppendValueGroup<TBuilder extends StringBuilder = StringBuilder>(value: unknown): value is AppendValueGroup<TBuilder>;
82
+ /**
83
+ * Combines multiple append values into one. A single value is returned as is. Otherwise, the values are returned as an
84
+ * array in which array arguments are flattened by one level. Without any values, an empty array is returned.
85
+ * @template TBuilder The builder type that determines the additional append types.
86
+ * @param values The append values to combine.
87
+ * @returns The combined append value.
88
+ */
21
89
  export declare function concatAppendValues<TBuilder extends StringBuilder = StringBuilder>(...values: AppendValue<TBuilder>[]): AppendValue<TBuilder>;
@@ -1,4 +1,11 @@
1
1
  import { concatSingleOrMultiple, notNullish } from '../common.utils.js';
2
+ /**
3
+ * Creates a group of basic append values. Nullish values are removed from the group.
4
+ * @template TBuilder The builder type that build functions receive.
5
+ * @param values The values to group. `null` and `undefined` yield an empty group.
6
+ * @param separator The string to append between two values. Defaults to no separator.
7
+ * @returns The append value group.
8
+ */
2
9
  export function basicAppendValueGroup(values, separator) {
3
10
  return {
4
11
  __type: 'append-value-group',
@@ -6,6 +13,13 @@ export function basicAppendValueGroup(values, separator) {
6
13
  separator: separator ?? null,
7
14
  };
8
15
  }
16
+ /**
17
+ * Creates a group of append values. Nullish values are removed from the group.
18
+ * @template TBuilder The builder type that determines the additional append types.
19
+ * @param values The values to group. `null` and `undefined` yield an empty group.
20
+ * @param separator The string to append between two values. Defaults to no separator.
21
+ * @returns The append value group.
22
+ */
9
23
  export function appendValueGroup(values, separator) {
10
24
  return {
11
25
  __type: 'append-value-group',
@@ -13,6 +27,12 @@ export function appendValueGroup(values, separator) {
13
27
  separator: separator ?? null,
14
28
  };
15
29
  }
30
+ /**
31
+ * Checks whether a value is a basic append value: a string, number, boolean, function or append value group.
32
+ * Nullish values, arrays and other objects are not append values.
33
+ * @param value The value to check.
34
+ * @returns `true` if the value is an append value; otherwise, `false`.
35
+ */
16
36
  export function isAppendValue(value) {
17
37
  return (typeof value === 'string' ||
18
38
  typeof value === 'number' ||
@@ -20,9 +40,22 @@ export function isAppendValue(value) {
20
40
  typeof value === 'function' ||
21
41
  isAppendValueGroup(value));
22
42
  }
43
+ /**
44
+ * Checks whether a value is an append value group, that is an object with the `append-value-group` type marker.
45
+ * @template TBuilder The builder type of the group.
46
+ * @param value The value to check.
47
+ * @returns `true` if the value is an append value group; otherwise, `false`.
48
+ */
23
49
  export function isAppendValueGroup(value) {
24
50
  return typeof value === 'object' && value !== null && '__type' in value && value.__type === 'append-value-group';
25
51
  }
52
+ /**
53
+ * Combines multiple append values into one. A single value is returned as is. Otherwise, the values are returned as an
54
+ * array in which array arguments are flattened by one level. Without any values, an empty array is returned.
55
+ * @template TBuilder The builder type that determines the additional append types.
56
+ * @param values The append values to combine.
57
+ * @returns The combined append value.
58
+ */
26
59
  export function concatAppendValues(...values) {
27
60
  return concatSingleOrMultiple(...values);
28
61
  }
@@ -1,10 +1,46 @@
1
1
  import type { CamelCaseOptions, CustomCaseOptions, KebabCaseOptions, PascalCaseOptions, SnakeCaseOptions, StringCasing, StringCasingWithOptions, WordCasing } from './string.utils.types.ts';
2
2
  import type { Nullable } from './type.utils.ts';
3
+ /**
4
+ * Applies overrides to a casing. If both arguments are plain casings, `b` is returned. Otherwise the result is an
5
+ * object that combines the options of both arguments, where the properties of `b` take precedence.
6
+ * @param a The base casing, either a plain casing or a casing with options.
7
+ * @param b The casing or the options that override `a`.
8
+ * @returns The adjusted casing.
9
+ * @example
10
+ * ```ts
11
+ * adjustCasing('camel', 'pascal'); // => 'pascal'
12
+ * adjustCasing('camel', { prefix: '_' }); // => { casing: 'camel', prefix: '_' }
13
+ * adjustCasing({ casing: 'camel', prefix: '_' }, 'pascal'); // => { casing: 'pascal', prefix: '_' }
14
+ * adjustCasing({ casing: 'camel', prefix: '_' }, { suffix: '_' }); // => { casing: 'camel', prefix: '_', suffix: '_' }
15
+ * ```
16
+ */
3
17
  export declare function adjustCasing(a: StringCasing, b: StringCasing): StringCasing;
4
18
  export declare function adjustCasing(a: StringCasing | StringCasingWithOptions, b: StringCasing | Partial<StringCasingWithOptions>): StringCasingWithOptions;
19
+ /**
20
+ * Converts all characters of a string to lower case.
21
+ * @param str The string to convert.
22
+ * @returns The lower case string.
23
+ */
5
24
  export declare function lowercase<T extends string>(str: T): Lowercase<T>;
25
+ /**
26
+ * Converts all characters of a string to upper case.
27
+ * @param str The string to convert.
28
+ * @returns The upper case string.
29
+ */
6
30
  export declare function uppercase<T extends string>(str: T): Uppercase<T>;
31
+ /**
32
+ * Converts the first character of a string to upper case and leaves the remaining characters unchanged.
33
+ * An empty string is returned as is.
34
+ * @param str The string to capitalize.
35
+ * @returns The capitalized string.
36
+ */
7
37
  export declare function capitalize<T extends string>(str: T): Capitalize<T>;
38
+ /**
39
+ * Converts the first character of a string to lower case and leaves the remaining characters unchanged.
40
+ * An empty string is returned as is.
41
+ * @param str The string to uncapitalize.
42
+ * @returns The uncapitalized string.
43
+ */
8
44
  export declare function uncapitalize<T extends string>(str: T): Uncapitalize<T>;
9
45
  /**
10
46
  * 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.
@@ -35,6 +71,21 @@ export declare function getWords(str: Nullable<string>): string[];
35
71
  * toCasing('FooBar', 'first-lower-alternating') // => 'fOoBaR'
36
72
  */
37
73
  export declare function wordToCasing(str: Nullable<string>, casing: WordCasing): string;
74
+ /**
75
+ * Converts a string to the specified casing. The `camel`, `pascal`, `kebab`, `snake` and `custom` casings are
76
+ * delegated to their dedicated functions. All other casings are applied to the words of the string joined together,
77
+ * so non-alphanumerical characters are removed.
78
+ * @param str The string to convert. `null` and `undefined` are treated as an empty string. The `first-*` word casings
79
+ * throw a `TypeError` for an empty string.
80
+ * @param casing The casing to convert to, optionally with options for that casing.
81
+ * @returns The converted string.
82
+ * @example
83
+ * ```ts
84
+ * toCasing('foo bar', 'pascal'); // => 'FooBar'
85
+ * toCasing('foo bar', 'first-upper'); // => 'Foobar'
86
+ * toCasing('foo_bar', { casing: 'kebab', wordCasing: 'all-upper' }); // => 'FOO-BAR'
87
+ * ```
88
+ */
38
89
  export declare function toCasing<T extends StringCasing>(str: Nullable<string>, casing: T | StringCasingWithOptions<T>): string;
39
90
  /**
40
91
  * Converts a string to camel case.
@@ -142,7 +193,34 @@ export declare function spliceString(str: string, start: number, deleteCount: nu
142
193
  * @param str The string to trim.
143
194
  */
144
195
  export declare function trimIndent(str: string): string;
196
+ /**
197
+ * Removes trailing whitespace from a string.
198
+ * @param str The string to trim.
199
+ * @param includeNewLine Whether to also remove trailing line breaks. Defaults to `true`. If `false`, only whitespace
200
+ * characters other than line breaks are removed.
201
+ * @returns The trimmed string.
202
+ */
145
203
  export declare function trimEnd(str: string, includeNewLine?: boolean): string;
204
+ /**
205
+ * Removes leading whitespace from a string.
206
+ * @param str The string to trim.
207
+ * @param includeNewLine Whether to also remove leading line breaks. Defaults to `true`. If `false`, only whitespace
208
+ * characters other than line breaks are removed.
209
+ * @returns The trimmed string.
210
+ */
146
211
  export declare function trimStart(str: string, includeNewLine?: boolean): string;
212
+ /**
213
+ * Removes leading and trailing whitespace from a string.
214
+ * @param str The string to trim.
215
+ * @param includeNewLine Whether to also remove leading and trailing line breaks. Defaults to `true`. If `false`, only
216
+ * whitespace characters other than line breaks are removed.
217
+ * @returns The trimmed string.
218
+ */
147
219
  export declare function trim(str: string, includeNewLine?: boolean): string;
220
+ /**
221
+ * Removes all occurrences of a substring from a string. The substring is matched literally, not as a regex.
222
+ * @param str The string to remove the substring from.
223
+ * @param rem The substring to remove. Must not be empty, because the search would never advance.
224
+ * @returns The string without the occurrences of `rem`, or `str` itself if `rem` does not occur in it.
225
+ */
148
226
  export declare function removeStr(str: string, rem: string): string;