@skmtc/core 0.0.782 → 0.0.783

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 (43) hide show
  1. package/esm/context/CoreContext.d.ts +175 -0
  2. package/esm/context/CoreContext.d.ts.map +1 -1
  3. package/esm/context/CoreContext.js +178 -0
  4. package/esm/dsl/ContentBase.d.ts +115 -0
  5. package/esm/dsl/ContentBase.d.ts.map +1 -1
  6. package/esm/dsl/ContentBase.js +110 -0
  7. package/esm/helpers/strings.d.ts +63 -0
  8. package/esm/helpers/strings.d.ts.map +1 -1
  9. package/esm/helpers/strings.js +59 -0
  10. package/esm/mod.d.ts +66 -0
  11. package/esm/mod.d.ts.map +1 -1
  12. package/esm/mod.js +66 -0
  13. package/esm/run/toArtifacts.d.ts +114 -0
  14. package/esm/run/toArtifacts.d.ts.map +1 -1
  15. package/esm/run/toArtifacts.js +86 -0
  16. package/esm/types/Settings.d.ts +129 -0
  17. package/esm/types/Settings.d.ts.map +1 -1
  18. package/esm/types/Settings.js +3 -0
  19. package/esm/typescript/List.d.ts +111 -0
  20. package/esm/typescript/List.d.ts.map +1 -1
  21. package/esm/typescript/List.js +106 -0
  22. package/package.json +1 -1
  23. package/script/context/CoreContext.d.ts +175 -0
  24. package/script/context/CoreContext.d.ts.map +1 -1
  25. package/script/context/CoreContext.js +178 -0
  26. package/script/dsl/ContentBase.d.ts +115 -0
  27. package/script/dsl/ContentBase.d.ts.map +1 -1
  28. package/script/dsl/ContentBase.js +110 -0
  29. package/script/helpers/strings.d.ts +63 -0
  30. package/script/helpers/strings.d.ts.map +1 -1
  31. package/script/helpers/strings.js +59 -0
  32. package/script/mod.d.ts +66 -0
  33. package/script/mod.d.ts.map +1 -1
  34. package/script/mod.js +66 -0
  35. package/script/run/toArtifacts.d.ts +114 -0
  36. package/script/run/toArtifacts.d.ts.map +1 -1
  37. package/script/run/toArtifacts.js +86 -0
  38. package/script/types/Settings.d.ts +129 -0
  39. package/script/types/Settings.d.ts.map +1 -1
  40. package/script/types/Settings.js +3 -0
  41. package/script/typescript/List.d.ts +111 -0
  42. package/script/typescript/List.d.ts.map +1 -1
  43. package/script/typescript/List.js +106 -0
@@ -57,18 +57,93 @@ const tracer_js_1 = require("../helpers/tracer.js");
57
57
  const ResultsLog_js_1 = require("../helpers/ResultsLog.js");
58
58
  const Sentry = __importStar(require("@sentry/node"));
59
59
  const join_js_1 = require("../deps/jsr.io/@std/path/1.1.2/join.js");
60
+ /**
61
+ * The main orchestration class for the SKMTC transformation pipeline.
62
+ *
63
+ * `CoreContext` manages the three-phase process of transforming OpenAPI v3 documents
64
+ * into code artifacts. It coordinates parsing, generation, and rendering phases while
65
+ * providing logging, tracing, and error handling capabilities.
66
+ *
67
+ * ## Pipeline Phases
68
+ *
69
+ * 1. **Parse Phase**: Uses {@link ParseContext} to convert OpenAPI JSON into OAS objects
70
+ * 2. **Generate Phase**: Uses {@link GenerateContext} to transform OAS objects with generators
71
+ * 3. **Render Phase**: Uses {@link RenderContext} to format and prepare final artifacts
72
+ *
73
+ * @example Basic usage
74
+ * ```typescript
75
+ * import { CoreContext } from '@skmtc/core';
76
+ *
77
+ * const context = new CoreContext({
78
+ * spanId: 'user-api-generation',
79
+ * logsPath: './logs',
80
+ * silent: false
81
+ * });
82
+ *
83
+ * const result = await context.toArtifacts({
84
+ * documentObject: openApiDoc,
85
+ * settings: clientSettings,
86
+ * toGeneratorConfigMap: () => generators,
87
+ * prettier: prettierConfig,
88
+ * silent: false
89
+ * });
90
+ * ```
91
+ *
92
+ * @example Using individual phases
93
+ * ```typescript
94
+ * const context = new CoreContext({
95
+ * spanId: 'custom-pipeline',
96
+ * silent: true
97
+ * });
98
+ *
99
+ * // Parse phase only
100
+ * const { oasDocument } = context.parse(openApiDoc);
101
+ *
102
+ * // Then use document for custom processing
103
+ * console.log('Parsed schemas:', Object.keys(oasDocument.components.schemas));
104
+ * ```
105
+ */
60
106
  class CoreContext {
107
+ /**
108
+ * Creates a new CoreContext instance.
109
+ *
110
+ * @param args - Configuration for the context
111
+ * @param args.spanId - Unique identifier for this transformation span
112
+ * @param args.logsPath - Optional directory path for log files
113
+ * @param args.silent - Whether to suppress console output
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * // Basic context with console logging
118
+ * const context = new CoreContext({
119
+ * spanId: 'my-generation',
120
+ * silent: false
121
+ * });
122
+ *
123
+ * // Context with file logging
124
+ * const context = new CoreContext({
125
+ * spanId: 'batch-job-123',
126
+ * logsPath: './logs/generation',
127
+ * silent: true
128
+ * });
129
+ * ```
130
+ */
61
131
  constructor({ spanId, logsPath, silent }) {
62
132
  _CoreContext_instances.add(this);
133
+ /** Logger instance for the context */
63
134
  Object.defineProperty(this, "logger", {
64
135
  enumerable: true,
65
136
  configurable: true,
66
137
  writable: true,
67
138
  value: void 0
68
139
  });
140
+ /** Current execution phase for pipeline tracking */
69
141
  _CoreContext_phase.set(this, void 0);
142
+ /** Results log for tracking generation outcomes */
70
143
  _CoreContext_results.set(this, void 0);
144
+ /** Stack trail for distributed tracing */
71
145
  _CoreContext_stackTrail.set(this, void 0);
146
+ /** Whether to suppress console output */
72
147
  Object.defineProperty(this, "silent", {
73
148
  enumerable: true,
74
149
  configurable: true,
@@ -80,6 +155,38 @@ class CoreContext {
80
155
  this.logger = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupLogger).call(this, { spanId, logsPath });
81
156
  this.silent = silent;
82
157
  }
158
+ /**
159
+ * Parses an OpenAPI v3 document into internal OAS objects.
160
+ *
161
+ * This method executes only the parse phase of the pipeline, converting
162
+ * the raw OpenAPI JSON into structured OAS objects that can be used for
163
+ * generation or custom processing.
164
+ *
165
+ * @param documentObject - The OpenAPI v3 document to parse
166
+ * @returns An object containing the parsed OAS document
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * import { CoreContext } from '@skmtc/core';
171
+ *
172
+ * const context = new CoreContext({
173
+ * spanId: 'parse-only',
174
+ * silent: true
175
+ * });
176
+ *
177
+ * const { oasDocument } = context.parse(openApiDoc);
178
+ *
179
+ * // Access parsed components
180
+ * console.log('Models:', Object.keys(oasDocument.components.schemas));
181
+ * console.log('Paths:', Object.keys(oasDocument.paths));
182
+ *
183
+ * // Use for custom processing
184
+ * const userModel = oasDocument.components.schemas['User'];
185
+ * if (userModel && !userModel.isRef()) {
186
+ * console.log('User properties:', Object.keys(userModel.properties));
187
+ * }
188
+ * ```
189
+ */
83
190
  parse(documentObject) {
84
191
  __classPrivateFieldSet(this, _CoreContext_phase, __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupParsePhase).call(this, documentObject), "f");
85
192
  const oasDocument = __classPrivateFieldGet(this, _CoreContext_phase, "f").context.parse();
@@ -87,6 +194,77 @@ class CoreContext {
87
194
  oasDocument
88
195
  };
89
196
  }
197
+ /**
198
+ * Executes the complete transformation pipeline to generate code artifacts.
199
+ *
200
+ * This method orchestrates all three phases:
201
+ * 1. **Parse**: Convert OpenAPI document to OAS objects
202
+ * 2. **Generate**: Transform OAS objects using generators
203
+ * 3. **Render**: Format and prepare final artifacts
204
+ *
205
+ * The result includes both the generated code files and comprehensive metadata
206
+ * about the generation process, including file mappings, previews, and results.
207
+ *
208
+ * @param args - Configuration for the artifact generation
209
+ * @param args.documentObject - The OpenAPI v3 document to process
210
+ * @param args.settings - Client settings for customization
211
+ * @param args.toGeneratorConfigMap - Function returning generator configuration
212
+ * @param args.prettier - Optional Prettier configuration for code formatting
213
+ * @param args.silent - Whether to suppress console output during generation
214
+ * @returns Promise resolving to rendered artifacts and metadata
215
+ *
216
+ * @example Complete pipeline
217
+ * ```typescript
218
+ * const context = new CoreContext({
219
+ * spanId: 'api-client-gen',
220
+ * silent: false
221
+ * });
222
+ *
223
+ * const result = await context.toArtifacts({
224
+ * documentObject: openApiDoc,
225
+ * settings: {
226
+ * basePath: './src/api',
227
+ * skip: {
228
+ * models: ['Internal*'],
229
+ * operations: {
230
+ * '/health': ['get'],
231
+ * '/debug/**': ['*']
232
+ * }
233
+ * }
234
+ * },
235
+ * toGeneratorConfigMap: () => ({
236
+ * models: {
237
+ * generator: MyModelGenerator,
238
+ * settings: { includeValidation: true }
239
+ * },
240
+ * operations: {
241
+ * generator: MyOperationGenerator,
242
+ * settings: { generateTypes: true }
243
+ * }
244
+ * }),
245
+ * prettier: {
246
+ * semi: false,
247
+ * singleQuote: true,
248
+ * trailingComma: 'all'
249
+ * },
250
+ * silent: false
251
+ * });
252
+ *
253
+ * // Access generated artifacts
254
+ * console.log('Generated files:', Object.keys(result.artifacts));
255
+ *
256
+ * // Write to filesystem
257
+ * for (const [path, content] of Object.entries(result.artifacts)) {
258
+ * await Deno.writeTextFile(path, content);
259
+ * }
260
+ *
261
+ * // Access metadata
262
+ * console.log('Generation results:', result.results);
263
+ * console.log('File mappings:', result.files);
264
+ * ```
265
+ *
266
+ * @throws Will throw an error if any phase of the pipeline fails
267
+ */
90
268
  async toArtifacts({ documentObject, settings, toGeneratorConfigMap, prettier }) {
91
269
  try {
92
270
  const oasDocument = this.trace('parse', () => {
@@ -1,15 +1,130 @@
1
1
  import type { GenerateContext } from '../context/GenerateContext.js';
2
2
  import type { RegisterArgs } from '../context/GenerateContext.js';
3
3
  import type { GeneratorKey } from '../types/GeneratorKeys.js';
4
+ /**
5
+ * Constructor arguments for {@link ContentBase}.
6
+ */
4
7
  type ContentBaseArgs = {
8
+ /** The generation context providing OAS objects and utilities */
5
9
  context: GenerateContext;
10
+ /** Optional generator key for tracking and identification */
6
11
  generatorKey?: GeneratorKey;
7
12
  };
13
+ /**
14
+ * Base class for all content generators in the SKMTC DSL system.
15
+ *
16
+ * `ContentBase` provides the foundation for creating custom generators that transform
17
+ * OpenAPI Schema (OAS) objects into code artifacts. It handles registration with the
18
+ * generation context, skipping logic, and provides access to the pipeline's utilities.
19
+ *
20
+ * ## Generator Lifecycle
21
+ *
22
+ * 1. **Construction**: Initialize with context and optional generator key
23
+ * 2. **Registration**: Call {@link register} to add artifacts to the pipeline
24
+ * 3. **Generation**: Implement custom logic using context utilities
25
+ * 4. **Rendering**: Artifacts are automatically rendered by the pipeline
26
+ *
27
+ * @example Basic generator
28
+ * ```typescript
29
+ * import { ContentBase } from '@skmtc/core';
30
+ *
31
+ * class MyModelGenerator extends ContentBase {
32
+ * generate() {
33
+ * // Skip if not needed
34
+ * if (this.shouldSkip()) return;
35
+ *
36
+ * // Access OAS objects through context
37
+ * const schemas = this.context.oasDocument.components.schemas;
38
+ *
39
+ * for (const [name, schema] of Object.entries(schemas)) {
40
+ * if (schema.isRef()) continue;
41
+ *
42
+ * const file = new File({
43
+ * context: this.context,
44
+ * path: `./models/${name}.ts`,
45
+ * content: this.generateModelContent(schema)
46
+ * });
47
+ *
48
+ * // Register the file for rendering
49
+ * this.register({ file });
50
+ * }
51
+ * }
52
+ *
53
+ * private generateModelContent(schema: OasObject): string {
54
+ * // Custom model generation logic
55
+ * return `export interface ${schema.name} { ... }`;
56
+ * }
57
+ * }
58
+ * ```
59
+ *
60
+ * @example Generator with skipping logic
61
+ * ```typescript
62
+ * class ConditionalGenerator extends ContentBase {
63
+ * generate() {
64
+ * // Check if generation should be skipped
65
+ * if (this.shouldSkipBasedOnSettings()) {
66
+ * this.skip('Disabled in settings');
67
+ * return;
68
+ * }
69
+ *
70
+ * // Continue with generation...
71
+ * const file = this.createOutputFile();
72
+ * this.register({ file });
73
+ * }
74
+ *
75
+ * private shouldSkipBasedOnSettings(): boolean {
76
+ * return this.context.settings?.skip?.models?.includes('MyModel') ?? false;
77
+ * }
78
+ * }
79
+ * ```
80
+ */
8
81
  export declare class ContentBase {
82
+ /** The generation context providing access to OAS objects and utilities */
9
83
  context: GenerateContext;
84
+ /** Whether this generator has been skipped */
10
85
  skipped: boolean;
86
+ /** Optional generator key for identification and tracking */
11
87
  generatorKey: GeneratorKey | undefined;
88
+ /**
89
+ * Creates a new ContentBase instance.
90
+ *
91
+ * @param args - Construction arguments
92
+ * @param args.context - The generation context
93
+ * @param args.generatorKey - Optional generator key
94
+ */
12
95
  constructor({ context, generatorKey }: ContentBaseArgs);
96
+ /**
97
+ * Registers generated artifacts with the rendering pipeline.
98
+ *
99
+ * This method is called by generator implementations to add files,
100
+ * JSON artifacts, or other content to the generation output.
101
+ *
102
+ * @param args - The artifacts to register
103
+ * @param args.file - Optional file to register
104
+ * @param args.jsonFile - Optional JSON file to register
105
+ *
106
+ * @example Registering a file
107
+ * ```typescript
108
+ * const file = new File({
109
+ * context: this.context,
110
+ * path: './output.ts',
111
+ * content: 'export const value = 42;'
112
+ * });
113
+ *
114
+ * this.register({ file });
115
+ * ```
116
+ *
117
+ * @example Registering JSON data
118
+ * ```typescript
119
+ * const jsonFile = new JsonFile({
120
+ * context: this.context,
121
+ * path: './config.json',
122
+ * data: { version: '1.0.0', features: ['api'] }
123
+ * });
124
+ *
125
+ * this.register({ jsonFile });
126
+ * ```
127
+ */
13
128
  register(args: RegisterArgs): void;
14
129
  }
15
130
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"ContentBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,eAAe,CAAA;IACxB,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED,qBAAa,WAAW;IACtB,OAAO,EAAE,eAAe,CAAA;IACxB,OAAO,EAAE,OAAO,CAAQ;IACxB,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;gBAE1B,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,eAAe;IAKtD,QAAQ,CAAC,IAAI,EAAE,YAAY;CAG5B"}
1
+ {"version":3,"file":"ContentBase.d.ts","sourceRoot":"","sources":["../../src/dsl/ContentBase.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAA;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAE7D;;GAEG;AACH,KAAK,eAAe,GAAG;IACrB,iEAAiE;IACjE,OAAO,EAAE,eAAe,CAAA;IACxB,6DAA6D;IAC7D,YAAY,CAAC,EAAE,YAAY,CAAA;CAC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,qBAAa,WAAW;IACtB,2EAA2E;IAC3E,OAAO,EAAE,eAAe,CAAA;IAExB,8CAA8C;IAC9C,OAAO,EAAE,OAAO,CAAQ;IAExB,6DAA6D;IAC7D,YAAY,EAAE,YAAY,GAAG,SAAS,CAAA;IAEtC;;;;;;OAMG;gBACS,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,eAAe;IAKtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,QAAQ,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;CAGnC"}
@@ -1,20 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContentBase = void 0;
4
+ /**
5
+ * Base class for all content generators in the SKMTC DSL system.
6
+ *
7
+ * `ContentBase` provides the foundation for creating custom generators that transform
8
+ * OpenAPI Schema (OAS) objects into code artifacts. It handles registration with the
9
+ * generation context, skipping logic, and provides access to the pipeline's utilities.
10
+ *
11
+ * ## Generator Lifecycle
12
+ *
13
+ * 1. **Construction**: Initialize with context and optional generator key
14
+ * 2. **Registration**: Call {@link register} to add artifacts to the pipeline
15
+ * 3. **Generation**: Implement custom logic using context utilities
16
+ * 4. **Rendering**: Artifacts are automatically rendered by the pipeline
17
+ *
18
+ * @example Basic generator
19
+ * ```typescript
20
+ * import { ContentBase } from '@skmtc/core';
21
+ *
22
+ * class MyModelGenerator extends ContentBase {
23
+ * generate() {
24
+ * // Skip if not needed
25
+ * if (this.shouldSkip()) return;
26
+ *
27
+ * // Access OAS objects through context
28
+ * const schemas = this.context.oasDocument.components.schemas;
29
+ *
30
+ * for (const [name, schema] of Object.entries(schemas)) {
31
+ * if (schema.isRef()) continue;
32
+ *
33
+ * const file = new File({
34
+ * context: this.context,
35
+ * path: `./models/${name}.ts`,
36
+ * content: this.generateModelContent(schema)
37
+ * });
38
+ *
39
+ * // Register the file for rendering
40
+ * this.register({ file });
41
+ * }
42
+ * }
43
+ *
44
+ * private generateModelContent(schema: OasObject): string {
45
+ * // Custom model generation logic
46
+ * return `export interface ${schema.name} { ... }`;
47
+ * }
48
+ * }
49
+ * ```
50
+ *
51
+ * @example Generator with skipping logic
52
+ * ```typescript
53
+ * class ConditionalGenerator extends ContentBase {
54
+ * generate() {
55
+ * // Check if generation should be skipped
56
+ * if (this.shouldSkipBasedOnSettings()) {
57
+ * this.skip('Disabled in settings');
58
+ * return;
59
+ * }
60
+ *
61
+ * // Continue with generation...
62
+ * const file = this.createOutputFile();
63
+ * this.register({ file });
64
+ * }
65
+ *
66
+ * private shouldSkipBasedOnSettings(): boolean {
67
+ * return this.context.settings?.skip?.models?.includes('MyModel') ?? false;
68
+ * }
69
+ * }
70
+ * ```
71
+ */
4
72
  class ContentBase {
73
+ /**
74
+ * Creates a new ContentBase instance.
75
+ *
76
+ * @param args - Construction arguments
77
+ * @param args.context - The generation context
78
+ * @param args.generatorKey - Optional generator key
79
+ */
5
80
  constructor({ context, generatorKey }) {
81
+ /** The generation context providing access to OAS objects and utilities */
6
82
  Object.defineProperty(this, "context", {
7
83
  enumerable: true,
8
84
  configurable: true,
9
85
  writable: true,
10
86
  value: void 0
11
87
  });
88
+ /** Whether this generator has been skipped */
12
89
  Object.defineProperty(this, "skipped", {
13
90
  enumerable: true,
14
91
  configurable: true,
15
92
  writable: true,
16
93
  value: false
17
94
  });
95
+ /** Optional generator key for identification and tracking */
18
96
  Object.defineProperty(this, "generatorKey", {
19
97
  enumerable: true,
20
98
  configurable: true,
@@ -24,6 +102,38 @@ class ContentBase {
24
102
  this.context = context;
25
103
  this.generatorKey = generatorKey;
26
104
  }
105
+ /**
106
+ * Registers generated artifacts with the rendering pipeline.
107
+ *
108
+ * This method is called by generator implementations to add files,
109
+ * JSON artifacts, or other content to the generation output.
110
+ *
111
+ * @param args - The artifacts to register
112
+ * @param args.file - Optional file to register
113
+ * @param args.jsonFile - Optional JSON file to register
114
+ *
115
+ * @example Registering a file
116
+ * ```typescript
117
+ * const file = new File({
118
+ * context: this.context,
119
+ * path: './output.ts',
120
+ * content: 'export const value = 42;'
121
+ * });
122
+ *
123
+ * this.register({ file });
124
+ * ```
125
+ *
126
+ * @example Registering JSON data
127
+ * ```typescript
128
+ * const jsonFile = new JsonFile({
129
+ * context: this.context,
130
+ * path: './config.json',
131
+ * data: { version: '1.0.0', features: ['api'] }
132
+ * });
133
+ *
134
+ * this.register({ jsonFile });
135
+ * ```
136
+ */
27
137
  register(args) {
28
138
  this.context.register(args);
29
139
  }
@@ -1,9 +1,72 @@
1
+ /**
2
+ * Capitalizes the first character of a string.
3
+ *
4
+ * @param str - The string to capitalize
5
+ * @returns The string with the first character uppercased
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * capitalize('hello world'); // 'Hello world'
10
+ * capitalize('API'); // 'API'
11
+ * capitalize(''); // ''
12
+ * ```
13
+ */
1
14
  import "../_dnt.polyfills.js";
2
15
  export declare const capitalize: (str: string) => string;
16
+ /**
17
+ * Decapitalizes (lowercases) the first character of a string.
18
+ *
19
+ * @param str - The string to decapitalize
20
+ * @returns The string with the first character lowercased
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * decapitalize('Hello World'); // 'hello World'
25
+ * decapitalize('API'); // 'aPI'
26
+ * decapitalize(''); // ''
27
+ * ```
28
+ */
3
29
  export declare const decapitalize: (str: string) => string;
30
+ /**
31
+ * Options for controlling camelCase conversion behavior.
32
+ */
4
33
  type CamelCaseOptions = {
34
+ /** Whether to capitalize the first character (PascalCase) */
5
35
  upperFirst?: boolean;
6
36
  };
37
+ /**
38
+ * Converts a string to camelCase, removing non-alphanumeric characters.
39
+ *
40
+ * This function handles various input formats including kebab-case, snake_case,
41
+ * space-separated words, and mixed formats. It intelligently capitalizes words
42
+ * after the first unless `upperFirst` is specified.
43
+ *
44
+ * @param str - The string to convert to camelCase
45
+ * @param options - Options to control the conversion
46
+ * @param options.upperFirst - Whether to capitalize the first character (default: false)
47
+ * @returns The camelCase version of the input string
48
+ *
49
+ * @example Basic usage
50
+ * ```typescript
51
+ * camelCase('hello world'); // 'helloWorld'
52
+ * camelCase('user-name'); // 'userName'
53
+ * camelCase('api_key'); // 'apiKey'
54
+ * camelCase('HTTP-Response'); // 'httpResponse'
55
+ * ```
56
+ *
57
+ * @example PascalCase (upperFirst)
58
+ * ```typescript
59
+ * camelCase('user profile', { upperFirst: true }); // 'UserProfile'
60
+ * camelCase('api-client', { upperFirst: true }); // 'ApiClient'
61
+ * ```
62
+ *
63
+ * @example Complex inputs
64
+ * ```typescript
65
+ * camelCase('get-user-by-id'); // 'getUserById'
66
+ * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
67
+ * camelCase('2fa-enabled'); // '2faEnabled'
68
+ * ```
69
+ */
7
70
  export declare const camelCase: (str: string, { upperFirst }?: CamelCaseOptions) => string;
8
71
  export {};
9
72
  //# sourceMappingURL=strings.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED,KAAK,gBAAgB,GAAG;IACtB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,iBAAgB,gBAAqB,KAAG,MAgB9E,CAAA"}
1
+ {"version":3,"file":"strings.d.ts","sourceRoot":"","sources":["../../src/helpers/strings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,sBAAsB,CAAC;AAE9B,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MAExC,CAAA;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAE1C,CAAA;AAED;;GAEG;AACH,KAAK,gBAAgB,GAAG;IACtB,6DAA6D;IAC7D,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,EAAE,iBAAgB,gBAAqB,KAAG,MAgB9E,CAAA"}
@@ -1,15 +1,74 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.camelCase = exports.decapitalize = exports.capitalize = void 0;
4
+ /**
5
+ * Capitalizes the first character of a string.
6
+ *
7
+ * @param str - The string to capitalize
8
+ * @returns The string with the first character uppercased
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * capitalize('hello world'); // 'Hello world'
13
+ * capitalize('API'); // 'API'
14
+ * capitalize(''); // ''
15
+ * ```
16
+ */
4
17
  require("../_dnt.polyfills.js");
5
18
  const capitalize = (str) => {
6
19
  return str.charAt(0).toUpperCase() + str.slice(1);
7
20
  };
8
21
  exports.capitalize = capitalize;
22
+ /**
23
+ * Decapitalizes (lowercases) the first character of a string.
24
+ *
25
+ * @param str - The string to decapitalize
26
+ * @returns The string with the first character lowercased
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * decapitalize('Hello World'); // 'hello World'
31
+ * decapitalize('API'); // 'aPI'
32
+ * decapitalize(''); // ''
33
+ * ```
34
+ */
9
35
  const decapitalize = (str) => {
10
36
  return str.charAt(0).toLocaleLowerCase() + str.slice(1);
11
37
  };
12
38
  exports.decapitalize = decapitalize;
39
+ /**
40
+ * Converts a string to camelCase, removing non-alphanumeric characters.
41
+ *
42
+ * This function handles various input formats including kebab-case, snake_case,
43
+ * space-separated words, and mixed formats. It intelligently capitalizes words
44
+ * after the first unless `upperFirst` is specified.
45
+ *
46
+ * @param str - The string to convert to camelCase
47
+ * @param options - Options to control the conversion
48
+ * @param options.upperFirst - Whether to capitalize the first character (default: false)
49
+ * @returns The camelCase version of the input string
50
+ *
51
+ * @example Basic usage
52
+ * ```typescript
53
+ * camelCase('hello world'); // 'helloWorld'
54
+ * camelCase('user-name'); // 'userName'
55
+ * camelCase('api_key'); // 'apiKey'
56
+ * camelCase('HTTP-Response'); // 'httpResponse'
57
+ * ```
58
+ *
59
+ * @example PascalCase (upperFirst)
60
+ * ```typescript
61
+ * camelCase('user profile', { upperFirst: true }); // 'UserProfile'
62
+ * camelCase('api-client', { upperFirst: true }); // 'ApiClient'
63
+ * ```
64
+ *
65
+ * @example Complex inputs
66
+ * ```typescript
67
+ * camelCase('get-user-by-id'); // 'getUserById'
68
+ * camelCase('XML_HTTP_Request'); // 'xmlHttpRequest'
69
+ * camelCase('2fa-enabled'); // '2faEnabled'
70
+ * ```
71
+ */
13
72
  const camelCase = (str, { upperFirst } = {}) => {
14
73
  let doCapitalize = Boolean(upperFirst);
15
74
  const camelCased = str.replace(/[^a-zA-Z0-9]+([a-zA-Z0-9]+)/g, (_, matched) => {