@skmtc/core 0.0.792 → 0.0.794

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 (113) 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/ResultsLog.d.ts +193 -0
  8. package/esm/helpers/ResultsLog.d.ts.map +1 -1
  9. package/esm/helpers/ResultsLog.js +213 -0
  10. package/esm/helpers/collateExamples.d.ts +150 -0
  11. package/esm/helpers/collateExamples.d.ts.map +1 -1
  12. package/esm/helpers/collateExamples.js +145 -0
  13. package/esm/helpers/formatNumber.d.ts +95 -0
  14. package/esm/helpers/formatNumber.d.ts.map +1 -1
  15. package/esm/helpers/formatNumber.js +95 -0
  16. package/esm/helpers/generationStats.d.ts +287 -1
  17. package/esm/helpers/generationStats.d.ts.map +1 -1
  18. package/esm/helpers/generationStats.js +266 -0
  19. package/esm/helpers/isEmpty.d.ts +62 -0
  20. package/esm/helpers/isEmpty.d.ts.map +1 -1
  21. package/esm/helpers/isEmpty.js +62 -0
  22. package/esm/helpers/isImported.d.ts +80 -0
  23. package/esm/helpers/isImported.d.ts.map +1 -1
  24. package/esm/helpers/isImported.js +80 -0
  25. package/esm/helpers/parseModuleName.d.ts +175 -0
  26. package/esm/helpers/parseModuleName.d.ts.map +1 -1
  27. package/esm/helpers/parseModuleName.js +153 -0
  28. package/esm/helpers/toResolvedArtifactPath.d.ts +145 -0
  29. package/esm/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  30. package/esm/helpers/toResolvedArtifactPath.js +140 -0
  31. package/esm/helpers/tracer.d.ts +124 -0
  32. package/esm/helpers/tracer.d.ts.map +1 -1
  33. package/esm/helpers/tracer.js +124 -0
  34. package/esm/oas/schema/Schema.d.ts +117 -0
  35. package/esm/oas/schema/Schema.d.ts.map +1 -1
  36. package/esm/typescript/PathParams.d.ts +198 -0
  37. package/esm/typescript/PathParams.d.ts.map +1 -1
  38. package/esm/typescript/PathParams.js +190 -0
  39. package/esm/typescript/ReactRouterPathParams.d.ts +190 -0
  40. package/esm/typescript/ReactRouterPathParams.d.ts.map +1 -1
  41. package/esm/typescript/ReactRouterPathParams.js +183 -0
  42. package/esm/typescript/identifiers.d.ts +159 -0
  43. package/esm/typescript/identifiers.d.ts.map +1 -1
  44. package/esm/typescript/identifiers.js +159 -0
  45. package/esm/typescript/keyValues.d.ts +125 -0
  46. package/esm/typescript/keyValues.d.ts.map +1 -1
  47. package/esm/typescript/keyValues.js +125 -1
  48. package/esm/typescript/toPathParams.d.ts +179 -0
  49. package/esm/typescript/toPathParams.d.ts.map +1 -1
  50. package/esm/typescript/toPathParams.js +179 -0
  51. package/esm/typescript/toPathTemplate.d.ts +114 -0
  52. package/esm/typescript/toPathTemplate.d.ts.map +1 -1
  53. package/esm/typescript/toPathTemplate.js +114 -0
  54. package/esm/typescript/withDescription.d.ts +119 -0
  55. package/esm/typescript/withDescription.d.ts.map +1 -1
  56. package/esm/typescript/withDescription.js +119 -0
  57. package/package.json +1 -1
  58. package/script/dsl/GeneratedValueList.d.ts +158 -0
  59. package/script/dsl/GeneratedValueList.d.ts.map +1 -1
  60. package/script/dsl/GeneratedValueList.js +158 -0
  61. package/script/dsl/Stringable.d.ts +76 -0
  62. package/script/dsl/Stringable.d.ts.map +1 -1
  63. package/script/dsl/Stringable.js +75 -0
  64. package/script/helpers/ResultsLog.d.ts +193 -0
  65. package/script/helpers/ResultsLog.d.ts.map +1 -1
  66. package/script/helpers/ResultsLog.js +213 -0
  67. package/script/helpers/collateExamples.d.ts +150 -0
  68. package/script/helpers/collateExamples.d.ts.map +1 -1
  69. package/script/helpers/collateExamples.js +145 -0
  70. package/script/helpers/formatNumber.d.ts +95 -0
  71. package/script/helpers/formatNumber.d.ts.map +1 -1
  72. package/script/helpers/formatNumber.js +95 -0
  73. package/script/helpers/generationStats.d.ts +287 -1
  74. package/script/helpers/generationStats.d.ts.map +1 -1
  75. package/script/helpers/generationStats.js +266 -0
  76. package/script/helpers/isEmpty.d.ts +62 -0
  77. package/script/helpers/isEmpty.d.ts.map +1 -1
  78. package/script/helpers/isEmpty.js +62 -0
  79. package/script/helpers/isImported.d.ts +80 -0
  80. package/script/helpers/isImported.d.ts.map +1 -1
  81. package/script/helpers/isImported.js +80 -0
  82. package/script/helpers/parseModuleName.d.ts +175 -0
  83. package/script/helpers/parseModuleName.d.ts.map +1 -1
  84. package/script/helpers/parseModuleName.js +153 -0
  85. package/script/helpers/toResolvedArtifactPath.d.ts +145 -0
  86. package/script/helpers/toResolvedArtifactPath.d.ts.map +1 -1
  87. package/script/helpers/toResolvedArtifactPath.js +140 -0
  88. package/script/helpers/tracer.d.ts +124 -0
  89. package/script/helpers/tracer.d.ts.map +1 -1
  90. package/script/helpers/tracer.js +124 -0
  91. package/script/oas/schema/Schema.d.ts +117 -0
  92. package/script/oas/schema/Schema.d.ts.map +1 -1
  93. package/script/typescript/PathParams.d.ts +198 -0
  94. package/script/typescript/PathParams.d.ts.map +1 -1
  95. package/script/typescript/PathParams.js +190 -0
  96. package/script/typescript/ReactRouterPathParams.d.ts +190 -0
  97. package/script/typescript/ReactRouterPathParams.d.ts.map +1 -1
  98. package/script/typescript/ReactRouterPathParams.js +183 -0
  99. package/script/typescript/identifiers.d.ts +159 -0
  100. package/script/typescript/identifiers.d.ts.map +1 -1
  101. package/script/typescript/identifiers.js +159 -0
  102. package/script/typescript/keyValues.d.ts +125 -0
  103. package/script/typescript/keyValues.d.ts.map +1 -1
  104. package/script/typescript/keyValues.js +125 -1
  105. package/script/typescript/toPathParams.d.ts +179 -0
  106. package/script/typescript/toPathParams.d.ts.map +1 -1
  107. package/script/typescript/toPathParams.js +179 -0
  108. package/script/typescript/toPathTemplate.d.ts +114 -0
  109. package/script/typescript/toPathTemplate.d.ts.map +1 -1
  110. package/script/typescript/toPathTemplate.js +114 -0
  111. package/script/typescript/withDescription.d.ts +119 -0
  112. package/script/typescript/withDescription.d.ts.map +1 -1
  113. package/script/typescript/withDescription.js +119 -0
@@ -1,3 +1,162 @@
1
+ /**
2
+ * Safely formats a key for use in object literals, adding quotes if needed.
3
+ *
4
+ * This function determines whether a property key needs to be quoted in JavaScript/TypeScript
5
+ * object literals based on identifier naming rules. Valid identifiers are left unquoted,
6
+ * while invalid identifiers (containing spaces, special characters, starting with numbers, etc.)
7
+ * are wrapped in single quotes.
8
+ *
9
+ * @param key - The property key to format
10
+ * @returns The key as-is if it's a valid identifier, otherwise wrapped in quotes
11
+ *
12
+ * @example Valid identifiers (no quotes needed)
13
+ * ```typescript
14
+ * import { handleKey } from '@skmtc/core';
15
+ *
16
+ * console.log(handleKey('name')); // 'name'
17
+ * console.log(handleKey('userName')); // 'userName'
18
+ * console.log(handleKey('_private')); // '_private'
19
+ * console.log(handleKey('$special')); // '$special'
20
+ * ```
21
+ *
22
+ * @example Invalid identifiers (quotes added)
23
+ * ```typescript
24
+ * console.log(handleKey('first-name')); // "'first-name'"
25
+ * console.log(handleKey('2nd-place')); // "'2nd-place'"
26
+ * console.log(handleKey('user name')); // "'user name'"
27
+ * console.log(handleKey('api-key')); // "'api-key'"
28
+ * console.log(handleKey('data.nested')); // "'data.nested'"
29
+ * ```
30
+ *
31
+ * @example Usage in object generation
32
+ * ```typescript
33
+ * class ObjectGenerator {
34
+ * generateObjectLiteral(properties: Record<string, string>) {
35
+ * const props = Object.entries(properties)
36
+ * .map(([key, value]) => `${handleKey(key)}: ${value}`)
37
+ * .join(', ');
38
+ *
39
+ * return `{ ${props} }`;
40
+ * }
41
+ * }
42
+ *
43
+ * const generator = new ObjectGenerator();
44
+ * const result = generator.generateObjectLiteral({
45
+ * 'name': 'string',
46
+ * 'first-name': 'string',
47
+ * 'age': 'number'
48
+ * });
49
+ *
50
+ * console.log(result);
51
+ * // { name: string, 'first-name': string, age: number }
52
+ * ```
53
+ *
54
+ * @example TypeScript interface generation
55
+ * ```typescript
56
+ * function generateInterface(name: string, properties: Record<string, string>) {
57
+ * const props = Object.entries(properties)
58
+ * .map(([key, type]) => ` ${handleKey(key)}: ${type};`)
59
+ * .join('\n');
60
+ *
61
+ * return `interface ${name} {\n${props}\n}`;
62
+ * }
63
+ *
64
+ * const userInterface = generateInterface('User', {
65
+ * 'id': 'string',
66
+ * 'first-name': 'string',
67
+ * 'last_name': 'string',
68
+ * '2fa-enabled': 'boolean'
69
+ * });
70
+ *
71
+ * console.log(userInterface);
72
+ * // interface User {
73
+ * // id: string;
74
+ * // 'first-name': string;
75
+ * // last_name: string;
76
+ * // '2fa-enabled': boolean;
77
+ * // }
78
+ * ```
79
+ */
1
80
  export declare const handleKey: (key: string) => string;
81
+ /**
82
+ * Safely formats property access, using dot notation or bracket notation as appropriate.
83
+ *
84
+ * This function generates the appropriate property access syntax for JavaScript/TypeScript
85
+ * code. Valid identifiers use dot notation (`parent.property`), while invalid identifiers
86
+ * use bracket notation (`parent['property']`).
87
+ *
88
+ * @param name - The property name to access
89
+ * @param parent - The parent object expression
90
+ * @returns Properly formatted property access expression
91
+ *
92
+ * @example Valid identifiers (dot notation)
93
+ * ```typescript
94
+ * import { handlePropertyName } from '@skmtc/core';
95
+ *
96
+ * console.log(handlePropertyName('name', 'user')); // 'user.name'
97
+ * console.log(handlePropertyName('firstName', 'user')); // 'user.firstName'
98
+ * console.log(handlePropertyName('_id', 'document')); // 'document._id'
99
+ * console.log(handlePropertyName('$meta', 'data')); // 'data.$meta'
100
+ * ```
101
+ *
102
+ * @example Invalid identifiers (bracket notation)
103
+ * ```typescript
104
+ * console.log(handlePropertyName('first-name', 'user')); // "user['first-name']"
105
+ * console.log(handlePropertyName('2nd-place', 'result')); // "result['2nd-place']"
106
+ * console.log(handlePropertyName('user name', 'form')); // "form['user name']"
107
+ * console.log(handlePropertyName('api-key', 'config')); // "config['api-key']"
108
+ * ```
109
+ *
110
+ * @example Usage in accessor generation
111
+ * ```typescript
112
+ * class PropertyAccessor {
113
+ * generateGetter(objectName: string, propertyPath: string[]) {
114
+ * return propertyPath.reduce((acc, prop) =>
115
+ * handlePropertyName(prop, acc), objectName
116
+ * );
117
+ * }
118
+ * }
119
+ *
120
+ * const accessor = new PropertyAccessor();
121
+ * const path1 = accessor.generateGetter('data', ['user', 'profile', 'firstName']);
122
+ * const path2 = accessor.generateGetter('config', ['api-settings', 'retry-count']);
123
+ *
124
+ * console.log(path1); // 'data.user.profile.firstName'
125
+ * console.log(path2); // "config['api-settings']['retry-count']"
126
+ * ```
127
+ *
128
+ * @example Complex object navigation
129
+ * ```typescript
130
+ * function generateObjectAccess(base: string, properties: string[]) {
131
+ * let result = base;
132
+ *
133
+ * for (const prop of properties) {
134
+ * result = handlePropertyName(prop, result);
135
+ * }
136
+ *
137
+ * return result;
138
+ * }
139
+ *
140
+ * const access1 = generateObjectAccess('response', ['data', 'user-info', 'name']);
141
+ * const access2 = generateObjectAccess('settings', ['ui', 'theme', 'darkMode']);
142
+ *
143
+ * console.log(access1); // "response.data['user-info'].name"
144
+ * console.log(access2); // "settings.ui.theme.darkMode"
145
+ * ```
146
+ *
147
+ * @example Function generation
148
+ * ```typescript
149
+ * function generatePropertyGetter(objName: string, propName: string) {
150
+ * const access = handlePropertyName(propName, objName);
151
+ * return `function get${propName.replace(/[^a-zA-Z0-9]/g, '')}() { return ${access}; }`;
152
+ * }
153
+ *
154
+ * const getter1 = generatePropertyGetter('user', 'firstName');
155
+ * const getter2 = generatePropertyGetter('config', 'api-key');
156
+ *
157
+ * console.log(getter1); // "function getfirstName() { return user.firstName; }"
158
+ * console.log(getter2); // "function getapikey() { return config['api-key']; }"
159
+ * ```
160
+ */
2
161
  export declare const handlePropertyName: (name: string, parent: string) => string;
3
162
  //# sourceMappingURL=identifiers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/typescript/identifiers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,MAEvC,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAEjE,CAAA"}
1
+ {"version":3,"file":"identifiers.d.ts","sourceRoot":"","sources":["../../src/typescript/identifiers.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,eAAO,MAAM,SAAS,GAAI,KAAK,MAAM,KAAG,MAEvC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAEjE,CAAA"}
@@ -2,10 +2,169 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlePropertyName = exports.handleKey = void 0;
4
4
  const helper_validator_identifier_1 = require("@babel/helper-validator-identifier");
5
+ /**
6
+ * Safely formats a key for use in object literals, adding quotes if needed.
7
+ *
8
+ * This function determines whether a property key needs to be quoted in JavaScript/TypeScript
9
+ * object literals based on identifier naming rules. Valid identifiers are left unquoted,
10
+ * while invalid identifiers (containing spaces, special characters, starting with numbers, etc.)
11
+ * are wrapped in single quotes.
12
+ *
13
+ * @param key - The property key to format
14
+ * @returns The key as-is if it's a valid identifier, otherwise wrapped in quotes
15
+ *
16
+ * @example Valid identifiers (no quotes needed)
17
+ * ```typescript
18
+ * import { handleKey } from '@skmtc/core';
19
+ *
20
+ * console.log(handleKey('name')); // 'name'
21
+ * console.log(handleKey('userName')); // 'userName'
22
+ * console.log(handleKey('_private')); // '_private'
23
+ * console.log(handleKey('$special')); // '$special'
24
+ * ```
25
+ *
26
+ * @example Invalid identifiers (quotes added)
27
+ * ```typescript
28
+ * console.log(handleKey('first-name')); // "'first-name'"
29
+ * console.log(handleKey('2nd-place')); // "'2nd-place'"
30
+ * console.log(handleKey('user name')); // "'user name'"
31
+ * console.log(handleKey('api-key')); // "'api-key'"
32
+ * console.log(handleKey('data.nested')); // "'data.nested'"
33
+ * ```
34
+ *
35
+ * @example Usage in object generation
36
+ * ```typescript
37
+ * class ObjectGenerator {
38
+ * generateObjectLiteral(properties: Record<string, string>) {
39
+ * const props = Object.entries(properties)
40
+ * .map(([key, value]) => `${handleKey(key)}: ${value}`)
41
+ * .join(', ');
42
+ *
43
+ * return `{ ${props} }`;
44
+ * }
45
+ * }
46
+ *
47
+ * const generator = new ObjectGenerator();
48
+ * const result = generator.generateObjectLiteral({
49
+ * 'name': 'string',
50
+ * 'first-name': 'string',
51
+ * 'age': 'number'
52
+ * });
53
+ *
54
+ * console.log(result);
55
+ * // { name: string, 'first-name': string, age: number }
56
+ * ```
57
+ *
58
+ * @example TypeScript interface generation
59
+ * ```typescript
60
+ * function generateInterface(name: string, properties: Record<string, string>) {
61
+ * const props = Object.entries(properties)
62
+ * .map(([key, type]) => ` ${handleKey(key)}: ${type};`)
63
+ * .join('\n');
64
+ *
65
+ * return `interface ${name} {\n${props}\n}`;
66
+ * }
67
+ *
68
+ * const userInterface = generateInterface('User', {
69
+ * 'id': 'string',
70
+ * 'first-name': 'string',
71
+ * 'last_name': 'string',
72
+ * '2fa-enabled': 'boolean'
73
+ * });
74
+ *
75
+ * console.log(userInterface);
76
+ * // interface User {
77
+ * // id: string;
78
+ * // 'first-name': string;
79
+ * // last_name: string;
80
+ * // '2fa-enabled': boolean;
81
+ * // }
82
+ * ```
83
+ */
5
84
  const handleKey = (key) => {
6
85
  return (0, helper_validator_identifier_1.isIdentifierName)(key) ? key : `'${key}'`;
7
86
  };
8
87
  exports.handleKey = handleKey;
88
+ /**
89
+ * Safely formats property access, using dot notation or bracket notation as appropriate.
90
+ *
91
+ * This function generates the appropriate property access syntax for JavaScript/TypeScript
92
+ * code. Valid identifiers use dot notation (`parent.property`), while invalid identifiers
93
+ * use bracket notation (`parent['property']`).
94
+ *
95
+ * @param name - The property name to access
96
+ * @param parent - The parent object expression
97
+ * @returns Properly formatted property access expression
98
+ *
99
+ * @example Valid identifiers (dot notation)
100
+ * ```typescript
101
+ * import { handlePropertyName } from '@skmtc/core';
102
+ *
103
+ * console.log(handlePropertyName('name', 'user')); // 'user.name'
104
+ * console.log(handlePropertyName('firstName', 'user')); // 'user.firstName'
105
+ * console.log(handlePropertyName('_id', 'document')); // 'document._id'
106
+ * console.log(handlePropertyName('$meta', 'data')); // 'data.$meta'
107
+ * ```
108
+ *
109
+ * @example Invalid identifiers (bracket notation)
110
+ * ```typescript
111
+ * console.log(handlePropertyName('first-name', 'user')); // "user['first-name']"
112
+ * console.log(handlePropertyName('2nd-place', 'result')); // "result['2nd-place']"
113
+ * console.log(handlePropertyName('user name', 'form')); // "form['user name']"
114
+ * console.log(handlePropertyName('api-key', 'config')); // "config['api-key']"
115
+ * ```
116
+ *
117
+ * @example Usage in accessor generation
118
+ * ```typescript
119
+ * class PropertyAccessor {
120
+ * generateGetter(objectName: string, propertyPath: string[]) {
121
+ * return propertyPath.reduce((acc, prop) =>
122
+ * handlePropertyName(prop, acc), objectName
123
+ * );
124
+ * }
125
+ * }
126
+ *
127
+ * const accessor = new PropertyAccessor();
128
+ * const path1 = accessor.generateGetter('data', ['user', 'profile', 'firstName']);
129
+ * const path2 = accessor.generateGetter('config', ['api-settings', 'retry-count']);
130
+ *
131
+ * console.log(path1); // 'data.user.profile.firstName'
132
+ * console.log(path2); // "config['api-settings']['retry-count']"
133
+ * ```
134
+ *
135
+ * @example Complex object navigation
136
+ * ```typescript
137
+ * function generateObjectAccess(base: string, properties: string[]) {
138
+ * let result = base;
139
+ *
140
+ * for (const prop of properties) {
141
+ * result = handlePropertyName(prop, result);
142
+ * }
143
+ *
144
+ * return result;
145
+ * }
146
+ *
147
+ * const access1 = generateObjectAccess('response', ['data', 'user-info', 'name']);
148
+ * const access2 = generateObjectAccess('settings', ['ui', 'theme', 'darkMode']);
149
+ *
150
+ * console.log(access1); // "response.data['user-info'].name"
151
+ * console.log(access2); // "settings.ui.theme.darkMode"
152
+ * ```
153
+ *
154
+ * @example Function generation
155
+ * ```typescript
156
+ * function generatePropertyGetter(objName: string, propName: string) {
157
+ * const access = handlePropertyName(propName, objName);
158
+ * return `function get${propName.replace(/[^a-zA-Z0-9]/g, '')}() { return ${access}; }`;
159
+ * }
160
+ *
161
+ * const getter1 = generatePropertyGetter('user', 'firstName');
162
+ * const getter2 = generatePropertyGetter('config', 'api-key');
163
+ *
164
+ * console.log(getter1); // "function getfirstName() { return user.firstName; }"
165
+ * console.log(getter2); // "function getapikey() { return config['api-key']; }"
166
+ * ```
167
+ */
9
168
  const handlePropertyName = (name, parent) => {
10
169
  return (0, helper_validator_identifier_1.isIdentifierName)(name) ? `${parent}.${name}` : `${parent}['${name}']`;
11
170
  };
@@ -1,3 +1,128 @@
1
1
  import type { Stringable } from '../dsl/Stringable.js';
2
+ /**
3
+ * Converts a properties object into a formatted TypeScript object literal string.
4
+ *
5
+ * This utility function takes a record of key-value pairs and generates a properly
6
+ * formatted TypeScript object literal. It automatically filters out empty values
7
+ * and handles proper spacing and comma placement. If all properties are empty,
8
+ * it returns the EMPTY constant instead of an empty object.
9
+ *
10
+ * The function is particularly useful for generating TypeScript interface properties,
11
+ * object type definitions, and literal object expressions in code generation scenarios.
12
+ *
13
+ * @param properties - Record of property names to their stringable values
14
+ * @returns Formatted object literal string or EMPTY if no valid properties
15
+ *
16
+ * @example Basic object generation
17
+ * ```typescript
18
+ * import { keyValues } from '@skmtc/core';
19
+ *
20
+ * const props = {
21
+ * name: { toString: () => 'string' },
22
+ * age: { toString: () => 'number' },
23
+ * email: { toString: () => 'string' }
24
+ * };
25
+ *
26
+ * const result = keyValues(props);
27
+ * console.log(result);
28
+ * // {name: string,
29
+ * // age: number,
30
+ * // email: string}
31
+ * ```
32
+ *
33
+ * @example With empty values filtered
34
+ * ```typescript
35
+ * const propsWithEmpty = {
36
+ * name: { toString: () => 'string' },
37
+ * description: { toString: () => '' }, // Empty, will be filtered
38
+ * age: { toString: () => 'number' },
39
+ * notes: { toString: () => 'EMPTY' } // EMPTY constant, will be filtered
40
+ * };
41
+ *
42
+ * const result = keyValues(propsWithEmpty);
43
+ * console.log(result);
44
+ * // {name: string,
45
+ * // age: number}
46
+ * ```
47
+ *
48
+ * @example All empty properties
49
+ * ```typescript
50
+ * const emptyProps = {
51
+ * description: { toString: () => '' },
52
+ * notes: { toString: () => 'EMPTY' }
53
+ * };
54
+ *
55
+ * const result = keyValues(emptyProps);
56
+ * console.log(result === EMPTY); // true
57
+ * ```
58
+ *
59
+ * @example TypeScript interface generation
60
+ * ```typescript
61
+ * class InterfaceGenerator {
62
+ * generateInterface(name: string, properties: Record<string, Stringable>) {
63
+ * const propsString = keyValues(properties);
64
+ *
65
+ * if (propsString === EMPTY) {
66
+ * return `interface ${name} {}`;
67
+ * }
68
+ *
69
+ * return `interface ${name} ${propsString}`;
70
+ * }
71
+ * }
72
+ *
73
+ * const generator = new InterfaceGenerator();
74
+ * const userInterface = generator.generateInterface('User', {
75
+ * id: { toString: () => 'string' },
76
+ * name: { toString: () => 'string' },
77
+ * age: { toString: () => 'number' }
78
+ * });
79
+ *
80
+ * console.log(userInterface);
81
+ * // interface User {id: string,
82
+ * // name: string,
83
+ * // age: number}
84
+ * ```
85
+ *
86
+ * @example Object literal generation
87
+ * ```typescript
88
+ * function generateObjectLiteral(values: Record<string, string>) {
89
+ * const stringableValues = Object.fromEntries(
90
+ * Object.entries(values).map(([k, v]) => [k, { toString: () => `'${v}'` }])
91
+ * );
92
+ *
93
+ * const result = keyValues(stringableValues);
94
+ * return result === EMPTY ? '{}' : result;
95
+ * }
96
+ *
97
+ * const config = generateObjectLiteral({
98
+ * apiUrl: 'https://api.example.com',
99
+ * timeout: '5000'
100
+ * });
101
+ *
102
+ * console.log(config);
103
+ * // {apiUrl: 'https://api.example.com',
104
+ * // timeout: '5000'}
105
+ * ```
106
+ *
107
+ * @example Conditional property inclusion
108
+ * ```typescript
109
+ * class ConditionalGenerator {
110
+ * generateObjectType(fields: Array<{name: string, type: string, optional?: boolean}>) {
111
+ * const properties: Record<string, Stringable> = {};
112
+ *
113
+ * fields.forEach(field => {
114
+ * if (field.type) { // Only include fields with types
115
+ * const optionalMarker = field.optional ? '?' : '';
116
+ * properties[field.name] = {
117
+ * toString: () => `${optionalMarker}: ${field.type}`
118
+ * };
119
+ * }
120
+ * });
121
+ *
122
+ * return keyValues(properties);
123
+ * }
124
+ * }
125
+ * ```
126
+ */
2
127
  export declare const keyValues: (properties: Record<string, Stringable>) => string;
3
128
  //# sourceMappingURL=keyValues.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"keyValues.d.ts","sourceRoot":"","sources":["../../src/typescript/keyValues.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAGtD,eAAO,MAAM,SAAS,GAAI,YAAY,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAAG,MAUlE,CAAA"}
1
+ {"version":3,"file":"keyValues.d.ts","sourceRoot":"","sources":["../../src/typescript/keyValues.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4HG;AACH,eAAO,MAAM,SAAS,GAAI,YAAY,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,KAAG,MAUlE,CAAA"}
@@ -2,7 +2,131 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.keyValues = void 0;
4
4
  const constants_js_1 = require("../dsl/constants.js");
5
- // Filter out properties with falsy or EMPTY values and return as joined string
5
+ /**
6
+ * Converts a properties object into a formatted TypeScript object literal string.
7
+ *
8
+ * This utility function takes a record of key-value pairs and generates a properly
9
+ * formatted TypeScript object literal. It automatically filters out empty values
10
+ * and handles proper spacing and comma placement. If all properties are empty,
11
+ * it returns the EMPTY constant instead of an empty object.
12
+ *
13
+ * The function is particularly useful for generating TypeScript interface properties,
14
+ * object type definitions, and literal object expressions in code generation scenarios.
15
+ *
16
+ * @param properties - Record of property names to their stringable values
17
+ * @returns Formatted object literal string or EMPTY if no valid properties
18
+ *
19
+ * @example Basic object generation
20
+ * ```typescript
21
+ * import { keyValues } from '@skmtc/core';
22
+ *
23
+ * const props = {
24
+ * name: { toString: () => 'string' },
25
+ * age: { toString: () => 'number' },
26
+ * email: { toString: () => 'string' }
27
+ * };
28
+ *
29
+ * const result = keyValues(props);
30
+ * console.log(result);
31
+ * // {name: string,
32
+ * // age: number,
33
+ * // email: string}
34
+ * ```
35
+ *
36
+ * @example With empty values filtered
37
+ * ```typescript
38
+ * const propsWithEmpty = {
39
+ * name: { toString: () => 'string' },
40
+ * description: { toString: () => '' }, // Empty, will be filtered
41
+ * age: { toString: () => 'number' },
42
+ * notes: { toString: () => 'EMPTY' } // EMPTY constant, will be filtered
43
+ * };
44
+ *
45
+ * const result = keyValues(propsWithEmpty);
46
+ * console.log(result);
47
+ * // {name: string,
48
+ * // age: number}
49
+ * ```
50
+ *
51
+ * @example All empty properties
52
+ * ```typescript
53
+ * const emptyProps = {
54
+ * description: { toString: () => '' },
55
+ * notes: { toString: () => 'EMPTY' }
56
+ * };
57
+ *
58
+ * const result = keyValues(emptyProps);
59
+ * console.log(result === EMPTY); // true
60
+ * ```
61
+ *
62
+ * @example TypeScript interface generation
63
+ * ```typescript
64
+ * class InterfaceGenerator {
65
+ * generateInterface(name: string, properties: Record<string, Stringable>) {
66
+ * const propsString = keyValues(properties);
67
+ *
68
+ * if (propsString === EMPTY) {
69
+ * return `interface ${name} {}`;
70
+ * }
71
+ *
72
+ * return `interface ${name} ${propsString}`;
73
+ * }
74
+ * }
75
+ *
76
+ * const generator = new InterfaceGenerator();
77
+ * const userInterface = generator.generateInterface('User', {
78
+ * id: { toString: () => 'string' },
79
+ * name: { toString: () => 'string' },
80
+ * age: { toString: () => 'number' }
81
+ * });
82
+ *
83
+ * console.log(userInterface);
84
+ * // interface User {id: string,
85
+ * // name: string,
86
+ * // age: number}
87
+ * ```
88
+ *
89
+ * @example Object literal generation
90
+ * ```typescript
91
+ * function generateObjectLiteral(values: Record<string, string>) {
92
+ * const stringableValues = Object.fromEntries(
93
+ * Object.entries(values).map(([k, v]) => [k, { toString: () => `'${v}'` }])
94
+ * );
95
+ *
96
+ * const result = keyValues(stringableValues);
97
+ * return result === EMPTY ? '{}' : result;
98
+ * }
99
+ *
100
+ * const config = generateObjectLiteral({
101
+ * apiUrl: 'https://api.example.com',
102
+ * timeout: '5000'
103
+ * });
104
+ *
105
+ * console.log(config);
106
+ * // {apiUrl: 'https://api.example.com',
107
+ * // timeout: '5000'}
108
+ * ```
109
+ *
110
+ * @example Conditional property inclusion
111
+ * ```typescript
112
+ * class ConditionalGenerator {
113
+ * generateObjectType(fields: Array<{name: string, type: string, optional?: boolean}>) {
114
+ * const properties: Record<string, Stringable> = {};
115
+ *
116
+ * fields.forEach(field => {
117
+ * if (field.type) { // Only include fields with types
118
+ * const optionalMarker = field.optional ? '?' : '';
119
+ * properties[field.name] = {
120
+ * toString: () => `${optionalMarker}: ${field.type}`
121
+ * };
122
+ * }
123
+ * });
124
+ *
125
+ * return keyValues(properties);
126
+ * }
127
+ * }
128
+ * ```
129
+ */
6
130
  const keyValues = (properties) => {
7
131
  const filteredEntries = Object.entries(properties)
8
132
  .map(([key, value]) => {