@skmtc/core 0.0.792 → 0.0.793

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 (71) hide show
  1. package/esm/dsl/GeneratedValueList.d.ts +158 -0
  2. package/esm/dsl/GeneratedValueList.d.ts.map +1 -1
  3. package/esm/dsl/GeneratedValueList.js +158 -0
  4. package/esm/dsl/Stringable.d.ts +76 -0
  5. package/esm/dsl/Stringable.d.ts.map +1 -1
  6. package/esm/dsl/Stringable.js +75 -0
  7. package/esm/helpers/collateExamples.d.ts +150 -0
  8. package/esm/helpers/collateExamples.d.ts.map +1 -1
  9. package/esm/helpers/collateExamples.js +145 -0
  10. package/esm/helpers/formatNumber.d.ts +95 -0
  11. package/esm/helpers/formatNumber.d.ts.map +1 -1
  12. package/esm/helpers/formatNumber.js +95 -0
  13. package/esm/helpers/generationStats.d.ts +287 -1
  14. package/esm/helpers/generationStats.d.ts.map +1 -1
  15. package/esm/helpers/generationStats.js +266 -0
  16. package/esm/helpers/isEmpty.d.ts +62 -0
  17. package/esm/helpers/isEmpty.d.ts.map +1 -1
  18. package/esm/helpers/isEmpty.js +62 -0
  19. package/esm/helpers/isImported.d.ts +80 -0
  20. package/esm/helpers/isImported.d.ts.map +1 -1
  21. package/esm/helpers/isImported.js +80 -0
  22. package/esm/helpers/parseModuleName.d.ts +175 -0
  23. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  24. package/esm/helpers/parseModuleName.js +153 -0
  25. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  26. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  27. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  28. package/esm/oas/schema/Schema.d.ts +117 -0
  29. package/esm/oas/schema/Schema.d.ts.map +1 -1
  30. package/esm/typescript/identifiers.d.ts +159 -0
  31. package/esm/typescript/identifiers.d.ts.map +1 -1
  32. package/esm/typescript/identifiers.js +159 -0
  33. package/esm/typescript/withDescription.d.ts +119 -0
  34. package/esm/typescript/withDescription.d.ts.map +1 -1
  35. package/esm/typescript/withDescription.js +119 -0
  36. package/package.json +1 -1
  37. package/script/dsl/GeneratedValueList.d.ts +158 -0
  38. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  39. package/script/dsl/GeneratedValueList.js +158 -0
  40. package/script/dsl/Stringable.d.ts +76 -0
  41. package/script/dsl/Stringable.d.ts.map +1 -1
  42. package/script/dsl/Stringable.js +75 -0
  43. package/script/helpers/collateExamples.d.ts +150 -0
  44. package/script/helpers/collateExamples.d.ts.map +1 -1
  45. package/script/helpers/collateExamples.js +145 -0
  46. package/script/helpers/formatNumber.d.ts +95 -0
  47. package/script/helpers/formatNumber.d.ts.map +1 -1
  48. package/script/helpers/formatNumber.js +95 -0
  49. package/script/helpers/generationStats.d.ts +287 -1
  50. package/script/helpers/generationStats.d.ts.map +1 -1
  51. package/script/helpers/generationStats.js +266 -0
  52. package/script/helpers/isEmpty.d.ts +62 -0
  53. package/script/helpers/isEmpty.d.ts.map +1 -1
  54. package/script/helpers/isEmpty.js +62 -0
  55. package/script/helpers/isImported.d.ts +80 -0
  56. package/script/helpers/isImported.d.ts.map +1 -1
  57. package/script/helpers/isImported.js +80 -0
  58. package/script/helpers/parseModuleName.d.ts +175 -0
  59. package/script/helpers/parseModuleName.d.ts.map +1 -1
  60. package/script/helpers/parseModuleName.js +153 -0
  61. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  62. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  63. package/script/helpers/toResolvedArtifactPath.js +140 -0
  64. package/script/oas/schema/Schema.d.ts +117 -0
  65. package/script/oas/schema/Schema.d.ts.map +1 -1
  66. package/script/typescript/identifiers.d.ts +159 -0
  67. package/script/typescript/identifiers.d.ts.map +1 -1
  68. package/script/typescript/identifiers.js +159 -0
  69. package/script/typescript/withDescription.d.ts +119 -0
  70. package/script/typescript/withDescription.d.ts.map +1 -1
  71. package/script/typescript/withDescription.js +119 -0
@@ -1,3 +1,122 @@
1
+ /**
2
+ * Wraps a value with a JSDoc comment if a description is provided.
3
+ *
4
+ * This utility function is used throughout the SKMTC code generation system to
5
+ * add JSDoc documentation comments to generated TypeScript code. If a description
6
+ * is provided, it formats it as a single-line JSDoc comment above the value.
7
+ * If no description is provided, the value is returned unchanged.
8
+ *
9
+ * @param value - The code value to potentially wrap with documentation
10
+ * @param modifiers - Modifiers object containing optional description
11
+ * @param modifiers.description - Optional description text for the JSDoc comment
12
+ * @returns The value with JSDoc comment prepended if description exists, otherwise just the value
13
+ *
14
+ * @example With description
15
+ * ```typescript
16
+ * import { withDescription } from '@skmtc/core';
17
+ *
18
+ * const result = withDescription(
19
+ * 'export const API_URL = "https://api.example.com";',
20
+ * { description: 'Base URL for all API requests' }
21
+ * );
22
+ *
23
+ * console.log(result);
24
+ * // /** Base URL for all API requests *\/
25
+ * // export const API_URL = "https://api.example.com";
26
+ * ```
27
+ *
28
+ * @example Without description
29
+ * ```typescript
30
+ * const result = withDescription(
31
+ * 'export const API_URL = "https://api.example.com";',
32
+ * { description: undefined }
33
+ * );
34
+ *
35
+ * console.log(result);
36
+ * // export const API_URL = "https://api.example.com";
37
+ * ```
38
+ *
39
+ * @example Using with Definition class
40
+ * ```typescript
41
+ * class ModelGenerator {
42
+ * generateInterface(name: string, description?: string) {
43
+ * const interfaceCode = `interface ${name} {
44
+ * id: string;
45
+ * name: string;
46
+ * }`;
47
+ *
48
+ * return withDescription(interfaceCode, { description });
49
+ * }
50
+ * }
51
+ *
52
+ * const generator = new ModelGenerator();
53
+ * const documented = generator.generateInterface('User', 'Represents a user in the system');
54
+ *
55
+ * console.log(documented);
56
+ * // /** Represents a user in the system *\/
57
+ * // interface User {
58
+ * // id: string;
59
+ * // name: string;
60
+ * // }
61
+ * ```
62
+ *
63
+ * @example Integration with generated definitions
64
+ * ```typescript
65
+ * import { Definition, Identifier, withDescription } from '@skmtc/core';
66
+ *
67
+ * class DocumentedGenerator {
68
+ * createDefinition(name: string, value: string, docs?: string) {
69
+ * return new Definition({
70
+ * context: this.context,
71
+ * identifier: Identifier.createVariable(name),
72
+ * description: docs, // This gets processed by withDescription internally
73
+ * value: {
74
+ * generatorKey: 'documented',
75
+ * content: value
76
+ * }
77
+ * });
78
+ * }
79
+ * }
80
+ * ```
81
+ *
82
+ * @example Complex documentation
83
+ * ```typescript
84
+ * const complexDoc = withDescription(
85
+ * `export type Status = 'active' | 'inactive' | 'pending';`,
86
+ * {
87
+ * description: 'User account status - active users can access all features'
88
+ * }
89
+ * );
90
+ *
91
+ * console.log(complexDoc);
92
+ * // /** User account status - active users can access all features *\/
93
+ * // export type Status = 'active' | 'inactive' | 'pending';
94
+ * ```
95
+ *
96
+ * @example Conditional documentation
97
+ * ```typescript
98
+ * function generateWithOptionalDocs(
99
+ * code: string,
100
+ * includeDescription: boolean
101
+ * ) {
102
+ * return withDescription(code, {
103
+ * description: includeDescription
104
+ * ? 'This is an auto-generated definition'
105
+ * : undefined
106
+ * });
107
+ * }
108
+ *
109
+ * const withDocs = generateWithOptionalDocs('export const VALUE = 42;', true);
110
+ * const withoutDocs = generateWithOptionalDocs('export const VALUE = 42;', false);
111
+ *
112
+ * console.log(withDocs);
113
+ * // /** This is an auto-generated definition *\/
114
+ * // export const VALUE = 42;
115
+ *
116
+ * console.log(withoutDocs);
117
+ * // export const VALUE = 42;
118
+ * ```
119
+ */
1
120
  export const withDescription = (value, { description }) => {
2
121
  return description ? `/** ${description} */\n${value}` : `${value}`;
3
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.0.792",
3
+ "version": "0.0.793",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/skmtc/skmtc.git"
@@ -1,9 +1,167 @@
1
1
  import type { GeneratedValue } from '../types/GeneratedValue.js';
2
+ /**
3
+ * A utility class for managing lists of generated values with customizable separators.
4
+ *
5
+ * `GeneratedValueList` provides a way to collect multiple generated values and combine
6
+ * them into a single string with a specified separator. It automatically filters out
7
+ * empty values to prevent generating unnecessary whitespace or malformed output.
8
+ *
9
+ * This class is useful for building lists of code elements like function parameters,
10
+ * import statements, or any other comma-separated (or otherwise separated) constructs
11
+ * where individual items might sometimes be empty.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Custom Separators**: Support for any string separator (commas, newlines, spaces, etc.)
16
+ * - **Empty Filtering**: Automatically removes empty values from output
17
+ * - **Type Safety**: Works with any GeneratedValue type
18
+ * - **Incremental Building**: Values can be added one at a time
19
+ *
20
+ * @example Basic usage with comma separation
21
+ * ```typescript
22
+ * import { GeneratedValueList } from '@skmtc/core';
23
+ *
24
+ * const parameterList = new GeneratedValueList(', ');
25
+ * parameterList.add({ toString: () => 'id: string' });
26
+ * parameterList.add({ toString: () => 'name: string' });
27
+ * parameterList.add({ toString: () => 'email?: string' });
28
+ *
29
+ * console.log(parameterList.toString());
30
+ * // 'id: string, name: string, email?: string'
31
+ * ```
32
+ *
33
+ * @example With newline separation for code blocks
34
+ * ```typescript
35
+ * const codeLines = new GeneratedValueList('\n');
36
+ * codeLines.add({ toString: () => 'import { User } from "./types";' });
37
+ * codeLines.add({ toString: () => 'import { validate } from "./utils";' });
38
+ * codeLines.add({ toString: () => '' }); // Empty line will be filtered
39
+ * codeLines.add({ toString: () => 'export class UserService {' });
40
+ * codeLines.add({ toString: () => ' // Implementation' });
41
+ * codeLines.add({ toString: () => '}' });
42
+ *
43
+ * console.log(codeLines.toString());
44
+ * // import { User } from "./types";
45
+ * // import { validate } from "./utils";
46
+ * // export class UserService {
47
+ * // // Implementation
48
+ * // }
49
+ * ```
50
+ *
51
+ * @example Empty value filtering
52
+ * ```typescript
53
+ * const mixedList = new GeneratedValueList(' | ');
54
+ * mixedList.add({ toString: () => "'active'" });
55
+ * mixedList.add({ toString: () => '' }); // This will be filtered out
56
+ * mixedList.add({ toString: () => "'inactive'" });
57
+ * mixedList.add({ toString: () => "'pending'" });
58
+ *
59
+ * console.log(mixedList.toString());
60
+ * // "'active' | 'inactive' | 'pending'"
61
+ * ```
62
+ *
63
+ * @example Using in code generation
64
+ * ```typescript
65
+ * class InterfaceGenerator {
66
+ * generateInterface(name: string, properties: Array<{name: string, type: string}>) {
67
+ * const propertyList = new GeneratedValueList(';\n ');
68
+ *
69
+ * properties.forEach(prop => {
70
+ * if (prop.type) { // Only add properties that have types
71
+ * propertyList.add({
72
+ * toString: () => `${prop.name}: ${prop.type}`
73
+ * });
74
+ * }
75
+ * });
76
+ *
77
+ * return `interface ${name} {\n ${propertyList.toString()};\n}`;
78
+ * }
79
+ * }
80
+ *
81
+ * const generator = new InterfaceGenerator();
82
+ * const userInterface = generator.generateInterface('User', [
83
+ * { name: 'id', type: 'string' },
84
+ * { name: 'name', type: 'string' },
85
+ * { name: 'invalid', type: '' }, // Will be filtered out
86
+ * { name: 'email', type: 'string | null' }
87
+ * ]);
88
+ *
89
+ * console.log(userInterface);
90
+ * // interface User {
91
+ * // id: string;
92
+ * // name: string;
93
+ * // email: string | null;
94
+ * // }
95
+ * ```
96
+ */
2
97
  export declare class GeneratedValueList {
98
+ /** The separator string used to join values */
3
99
  separator: string;
100
+ /** Internal array of generated values */
4
101
  private items;
102
+ /**
103
+ * Creates a new GeneratedValueList with the specified separator.
104
+ *
105
+ * @param separator - The string to use when joining values (e.g., ', ', '\n', ' | ')
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // For comma-separated lists
110
+ * const commaList = new GeneratedValueList(', ');
111
+ *
112
+ * // For line-separated content
113
+ * const lineList = new GeneratedValueList('\n');
114
+ *
115
+ * // For union types
116
+ * const unionList = new GeneratedValueList(' | ');
117
+ * ```
118
+ */
5
119
  constructor(separator: string);
120
+ /**
121
+ * Adds a generated value to the list.
122
+ *
123
+ * The value will be included in the output string when `toString()` is called,
124
+ * unless the value's `toString()` method returns an empty string, in which case
125
+ * it will be automatically filtered out.
126
+ *
127
+ * @param str - The generated value to add to the list
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const list = new GeneratedValueList(', ');
132
+ *
133
+ * // Add simple values
134
+ * list.add({ toString: () => 'value1' });
135
+ * list.add({ toString: () => 'value2' });
136
+ *
137
+ * // Add conditional values
138
+ * const conditionalValue = shouldInclude ? 'conditional' : '';
139
+ * list.add({ toString: () => conditionalValue });
140
+ *
141
+ * console.log(list.toString()); // 'value1, value2' (conditional filtered if empty)
142
+ * ```
143
+ */
6
144
  add(str: GeneratedValue): void;
145
+ /**
146
+ * Converts the list to a string representation with values joined by the separator.
147
+ *
148
+ * This method processes all added values by calling their `toString()` methods,
149
+ * filters out any empty strings (matching the {@link EMPTY} constant), and joins
150
+ * the remaining values with the configured separator.
151
+ *
152
+ * @returns The joined string representation of all non-empty values
153
+ *
154
+ * @example
155
+ * ```typescript
156
+ * const list = new GeneratedValueList(' -> ');
157
+ * list.add({ toString: () => 'start' });
158
+ * list.add({ toString: () => '' }); // Will be filtered out
159
+ * list.add({ toString: () => 'middle' });
160
+ * list.add({ toString: () => 'end' });
161
+ *
162
+ * console.log(list.toString()); // 'start -> middle -> end'
163
+ * ```
164
+ */
7
165
  toString(): string;
8
166
  }
9
167
  //# sourceMappingURL=GeneratedValueList.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GeneratedValueList.d.ts","sourceRoot":"","sources":["../../src/dsl/GeneratedValueList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhE,qBAAa,kBAAkB;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,KAAK,CAAuB;gBAExB,SAAS,EAAE,MAAM;IAI7B,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAI9B,QAAQ,IAAI,MAAM;CAMnB"}
1
+ {"version":3,"file":"GeneratedValueList.d.ts","sourceRoot":"","sources":["../../src/dsl/GeneratedValueList.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAGhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8FG;AACH,qBAAa,kBAAkB;IAC7B,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAA;IAEjB,yCAAyC;IACzC,OAAO,CAAC,KAAK,CAAuB;IAEpC;;;;;;;;;;;;;;;;OAgBG;gBACS,SAAS,EAAE,MAAM;IAI7B;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI;IAI9B;;;;;;;;;;;;;;;;;;;OAmBG;IACH,QAAQ,IAAI,MAAM;CAMnB"}
@@ -2,14 +2,128 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GeneratedValueList = void 0;
4
4
  const constants_js_1 = require("./constants.js");
5
+ /**
6
+ * A utility class for managing lists of generated values with customizable separators.
7
+ *
8
+ * `GeneratedValueList` provides a way to collect multiple generated values and combine
9
+ * them into a single string with a specified separator. It automatically filters out
10
+ * empty values to prevent generating unnecessary whitespace or malformed output.
11
+ *
12
+ * This class is useful for building lists of code elements like function parameters,
13
+ * import statements, or any other comma-separated (or otherwise separated) constructs
14
+ * where individual items might sometimes be empty.
15
+ *
16
+ * ## Key Features
17
+ *
18
+ * - **Custom Separators**: Support for any string separator (commas, newlines, spaces, etc.)
19
+ * - **Empty Filtering**: Automatically removes empty values from output
20
+ * - **Type Safety**: Works with any GeneratedValue type
21
+ * - **Incremental Building**: Values can be added one at a time
22
+ *
23
+ * @example Basic usage with comma separation
24
+ * ```typescript
25
+ * import { GeneratedValueList } from '@skmtc/core';
26
+ *
27
+ * const parameterList = new GeneratedValueList(', ');
28
+ * parameterList.add({ toString: () => 'id: string' });
29
+ * parameterList.add({ toString: () => 'name: string' });
30
+ * parameterList.add({ toString: () => 'email?: string' });
31
+ *
32
+ * console.log(parameterList.toString());
33
+ * // 'id: string, name: string, email?: string'
34
+ * ```
35
+ *
36
+ * @example With newline separation for code blocks
37
+ * ```typescript
38
+ * const codeLines = new GeneratedValueList('\n');
39
+ * codeLines.add({ toString: () => 'import { User } from "./types";' });
40
+ * codeLines.add({ toString: () => 'import { validate } from "./utils";' });
41
+ * codeLines.add({ toString: () => '' }); // Empty line will be filtered
42
+ * codeLines.add({ toString: () => 'export class UserService {' });
43
+ * codeLines.add({ toString: () => ' // Implementation' });
44
+ * codeLines.add({ toString: () => '}' });
45
+ *
46
+ * console.log(codeLines.toString());
47
+ * // import { User } from "./types";
48
+ * // import { validate } from "./utils";
49
+ * // export class UserService {
50
+ * // // Implementation
51
+ * // }
52
+ * ```
53
+ *
54
+ * @example Empty value filtering
55
+ * ```typescript
56
+ * const mixedList = new GeneratedValueList(' | ');
57
+ * mixedList.add({ toString: () => "'active'" });
58
+ * mixedList.add({ toString: () => '' }); // This will be filtered out
59
+ * mixedList.add({ toString: () => "'inactive'" });
60
+ * mixedList.add({ toString: () => "'pending'" });
61
+ *
62
+ * console.log(mixedList.toString());
63
+ * // "'active' | 'inactive' | 'pending'"
64
+ * ```
65
+ *
66
+ * @example Using in code generation
67
+ * ```typescript
68
+ * class InterfaceGenerator {
69
+ * generateInterface(name: string, properties: Array<{name: string, type: string}>) {
70
+ * const propertyList = new GeneratedValueList(';\n ');
71
+ *
72
+ * properties.forEach(prop => {
73
+ * if (prop.type) { // Only add properties that have types
74
+ * propertyList.add({
75
+ * toString: () => `${prop.name}: ${prop.type}`
76
+ * });
77
+ * }
78
+ * });
79
+ *
80
+ * return `interface ${name} {\n ${propertyList.toString()};\n}`;
81
+ * }
82
+ * }
83
+ *
84
+ * const generator = new InterfaceGenerator();
85
+ * const userInterface = generator.generateInterface('User', [
86
+ * { name: 'id', type: 'string' },
87
+ * { name: 'name', type: 'string' },
88
+ * { name: 'invalid', type: '' }, // Will be filtered out
89
+ * { name: 'email', type: 'string | null' }
90
+ * ]);
91
+ *
92
+ * console.log(userInterface);
93
+ * // interface User {
94
+ * // id: string;
95
+ * // name: string;
96
+ * // email: string | null;
97
+ * // }
98
+ * ```
99
+ */
5
100
  class GeneratedValueList {
101
+ /**
102
+ * Creates a new GeneratedValueList with the specified separator.
103
+ *
104
+ * @param separator - The string to use when joining values (e.g., ', ', '\n', ' | ')
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * // For comma-separated lists
109
+ * const commaList = new GeneratedValueList(', ');
110
+ *
111
+ * // For line-separated content
112
+ * const lineList = new GeneratedValueList('\n');
113
+ *
114
+ * // For union types
115
+ * const unionList = new GeneratedValueList(' | ');
116
+ * ```
117
+ */
6
118
  constructor(separator) {
119
+ /** The separator string used to join values */
7
120
  Object.defineProperty(this, "separator", {
8
121
  enumerable: true,
9
122
  configurable: true,
10
123
  writable: true,
11
124
  value: void 0
12
125
  });
126
+ /** Internal array of generated values */
13
127
  Object.defineProperty(this, "items", {
14
128
  enumerable: true,
15
129
  configurable: true,
@@ -18,9 +132,53 @@ class GeneratedValueList {
18
132
  });
19
133
  this.separator = separator;
20
134
  }
135
+ /**
136
+ * Adds a generated value to the list.
137
+ *
138
+ * The value will be included in the output string when `toString()` is called,
139
+ * unless the value's `toString()` method returns an empty string, in which case
140
+ * it will be automatically filtered out.
141
+ *
142
+ * @param str - The generated value to add to the list
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const list = new GeneratedValueList(', ');
147
+ *
148
+ * // Add simple values
149
+ * list.add({ toString: () => 'value1' });
150
+ * list.add({ toString: () => 'value2' });
151
+ *
152
+ * // Add conditional values
153
+ * const conditionalValue = shouldInclude ? 'conditional' : '';
154
+ * list.add({ toString: () => conditionalValue });
155
+ *
156
+ * console.log(list.toString()); // 'value1, value2' (conditional filtered if empty)
157
+ * ```
158
+ */
21
159
  add(str) {
22
160
  this.items.push(str);
23
161
  }
162
+ /**
163
+ * Converts the list to a string representation with values joined by the separator.
164
+ *
165
+ * This method processes all added values by calling their `toString()` methods,
166
+ * filters out any empty strings (matching the {@link EMPTY} constant), and joins
167
+ * the remaining values with the configured separator.
168
+ *
169
+ * @returns The joined string representation of all non-empty values
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * const list = new GeneratedValueList(' -> ');
174
+ * list.add({ toString: () => 'start' });
175
+ * list.add({ toString: () => '' }); // Will be filtered out
176
+ * list.add({ toString: () => 'middle' });
177
+ * list.add({ toString: () => 'end' });
178
+ *
179
+ * console.log(list.toString()); // 'start -> middle -> end'
180
+ * ```
181
+ */
24
182
  toString() {
25
183
  return this.items
26
184
  .map(item => item.toString())
@@ -1,5 +1,81 @@
1
+ /**
2
+ * Represents any object that can be converted to a string representation.
3
+ *
4
+ * The `Stringable` interface is a fundamental type used throughout the SKMTC DSL
5
+ * system to ensure that objects can be converted to strings for code generation.
6
+ * This interface matches JavaScript's built-in `toString()` contract and is used
7
+ * extensively by the {@link List} class and other string-building utilities.
8
+ *
9
+ * ## Usage in SKMTC
10
+ *
11
+ * This type is used as a constraint in generic classes and functions that need
12
+ * to output string representations. It allows for type-safe string building
13
+ * while accommodating both primitive types and custom objects.
14
+ *
15
+ * @example Built-in types are stringable
16
+ * ```typescript
17
+ * import type { Stringable } from '@skmtc/core';
18
+ *
19
+ * // All these types implement Stringable
20
+ * const str: Stringable = 'hello'; // string
21
+ * const num: Stringable = 42; // number
22
+ * const bool: Stringable = true; // boolean
23
+ * const obj: Stringable = { toString: () => 'custom' }; // custom object
24
+ * ```
25
+ *
26
+ * @example Custom classes implementing Stringable
27
+ * ```typescript
28
+ * class CodeBlock implements Stringable {
29
+ * constructor(private code: string) {}
30
+ *
31
+ * toString(): string {
32
+ * return `{\n ${this.code}\n}`;
33
+ * }
34
+ * }
35
+ *
36
+ * const block = new CodeBlock('console.log("hello");');
37
+ * console.log(block.toString());
38
+ * // {
39
+ * // console.log("hello");
40
+ * // }
41
+ * ```
42
+ *
43
+ * @example Using with List class
44
+ * ```typescript
45
+ * import { List } from '@skmtc/core';
46
+ *
47
+ * // List accepts any Stringable items
48
+ * const stringables: Stringable[] = [
49
+ * 'string literal',
50
+ * 42,
51
+ * true,
52
+ * { toString: () => 'custom object' },
53
+ * new CodeBlock('return value;')
54
+ * ];
55
+ *
56
+ * const list = new List(stringables);
57
+ * console.log(list.toString());
58
+ * // string literal, 42, true, custom object, {
59
+ * // return value;
60
+ * // }
61
+ * ```
62
+ *
63
+ * @example Type constraints in generics
64
+ * ```typescript
65
+ * function joinWithCommas<T extends Stringable>(items: T[]): string {
66
+ * return items.map(item => item.toString()).join(', ');
67
+ * }
68
+ *
69
+ * const result = joinWithCommas([1, 2, 3]); // "1, 2, 3"
70
+ * const identifiers = joinWithCommas([
71
+ * Identifier.createVariable('user'),
72
+ * Identifier.createType('User')
73
+ * ]); // "user, User"
74
+ * ```
75
+ */
1
76
  import "../_dnt.polyfills.js";
2
77
  export type Stringable = {
78
+ /** Converts the object to its string representation */
3
79
  toString: () => string;
4
80
  };
5
81
  //# sourceMappingURL=Stringable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,EAAE,MAAM,MAAM,CAAA;CACvB,CAAA"}
1
+ {"version":3,"file":"Stringable.d.ts","sourceRoot":"","sources":["../../src/dsl/Stringable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0EG;AACH,OAAO,sBAAsB,CAAC;AAE9B,MAAM,MAAM,UAAU,GAAG;IACvB,uDAAuD;IACvD,QAAQ,EAAE,MAAM,MAAM,CAAA;CACvB,CAAA"}
@@ -1,3 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Represents any object that can be converted to a string representation.
5
+ *
6
+ * The `Stringable` interface is a fundamental type used throughout the SKMTC DSL
7
+ * system to ensure that objects can be converted to strings for code generation.
8
+ * This interface matches JavaScript's built-in `toString()` contract and is used
9
+ * extensively by the {@link List} class and other string-building utilities.
10
+ *
11
+ * ## Usage in SKMTC
12
+ *
13
+ * This type is used as a constraint in generic classes and functions that need
14
+ * to output string representations. It allows for type-safe string building
15
+ * while accommodating both primitive types and custom objects.
16
+ *
17
+ * @example Built-in types are stringable
18
+ * ```typescript
19
+ * import type { Stringable } from '@skmtc/core';
20
+ *
21
+ * // All these types implement Stringable
22
+ * const str: Stringable = 'hello'; // string
23
+ * const num: Stringable = 42; // number
24
+ * const bool: Stringable = true; // boolean
25
+ * const obj: Stringable = { toString: () => 'custom' }; // custom object
26
+ * ```
27
+ *
28
+ * @example Custom classes implementing Stringable
29
+ * ```typescript
30
+ * class CodeBlock implements Stringable {
31
+ * constructor(private code: string) {}
32
+ *
33
+ * toString(): string {
34
+ * return `{\n ${this.code}\n}`;
35
+ * }
36
+ * }
37
+ *
38
+ * const block = new CodeBlock('console.log("hello");');
39
+ * console.log(block.toString());
40
+ * // {
41
+ * // console.log("hello");
42
+ * // }
43
+ * ```
44
+ *
45
+ * @example Using with List class
46
+ * ```typescript
47
+ * import { List } from '@skmtc/core';
48
+ *
49
+ * // List accepts any Stringable items
50
+ * const stringables: Stringable[] = [
51
+ * 'string literal',
52
+ * 42,
53
+ * true,
54
+ * { toString: () => 'custom object' },
55
+ * new CodeBlock('return value;')
56
+ * ];
57
+ *
58
+ * const list = new List(stringables);
59
+ * console.log(list.toString());
60
+ * // string literal, 42, true, custom object, {
61
+ * // return value;
62
+ * // }
63
+ * ```
64
+ *
65
+ * @example Type constraints in generics
66
+ * ```typescript
67
+ * function joinWithCommas<T extends Stringable>(items: T[]): string {
68
+ * return items.map(item => item.toString()).join(', ');
69
+ * }
70
+ *
71
+ * const result = joinWithCommas([1, 2, 3]); // "1, 2, 3"
72
+ * const identifiers = joinWithCommas([
73
+ * Identifier.createVariable('user'),
74
+ * Identifier.createType('User')
75
+ * ]); // "user, User"
76
+ * ```
77
+ */
3
78
  require("../_dnt.polyfills.js");