ajsc 5.0.0 → 5.0.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 (2) hide show
  1. package/README.md +57 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -102,11 +102,23 @@ console.log(converter.irNode);
102
102
  The package includes a TypeScript language plugin that converts the IRNode into TypeScript type definitions.
103
103
 
104
104
  - Constructor:
105
- `new TypescriptConverter(schema: object, options?: { inlineTypes?: boolean })`
105
+ `new TypescriptConverter(schema: object, options?: TypescriptConverterOpts)`
106
106
  - Properties:
107
107
  - code: A string containing the generated TypeScript code.
108
108
 
109
- Usage Example:
109
+ #### Options
110
+
111
+ | Option | Type | Default | Description |
112
+ |--------|------|---------|-------------|
113
+ | `inlineTypes` | `boolean` | `false` | If true, object types are inlined instead of extracted as named type aliases. |
114
+ | `depluralize` | `boolean` | `true` | Singularize array item type names. Handles irregular plurals (e.g. `entries` → `Entry`, `people` → `Person`). |
115
+ | `arrayItemNaming` | `string \| false` | `false` | Controls the postfix for array item type names. `false` = no postfix, `string` = custom postfix (e.g. `"Item"` → `ContactItem`). |
116
+ | `enumStyle` | `"union" \| "enum"` | `"union"` | `"union"` emits `"a" \| "b"`, `"enum"` emits `export enum`. Only applies when `inlineTypes` is false and all values are strings. |
117
+ | `uncountableWords` | `string[]` | `undefined` | Additional words that should not be singularized (built-in: `"data"`, `"metadata"`). |
118
+
119
+ #### Usage Examples
120
+
121
+ Default behavior — array item types are automatically singularized:
110
122
 
111
123
  ```javascript
112
124
  import { TypescriptConverter } from "ajsc";
@@ -137,14 +149,50 @@ const schema = {
137
149
  required: ["name", "age"],
138
150
  };
139
151
 
152
+ const tsConverter = new TypescriptConverter(schema);
153
+ console.log(tsConverter.code);
154
+
155
+ // Output:
156
+ // export type Contact = { email: string; };
157
+ // export type Profile = { email: string; };
158
+ //
159
+ // export type Root = { name: string; age: number; contacts?: Array<Contact>; profile?: Profile; };
160
+ ```
161
+
162
+ Inline types (no extracted type aliases):
163
+
164
+ ```javascript
140
165
  const tsConverter = new TypescriptConverter(schema, { inlineTypes: true });
141
166
  console.log(tsConverter.code);
142
167
 
143
- // Expected output (formatted):
144
- // {
145
- // name: string;
146
- // age: number;
147
- // contacts?: Array<{ email: string; }>;
148
- // profile?: { email: string; };
149
- // }
168
+ // Output:
169
+ // { name: string; age: number; contacts?: Array<{ email: string; }>; profile?: { email: string; }; }
170
+ ```
171
+
172
+ Enum style:
173
+
174
+ ```javascript
175
+ const enumSchema = {
176
+ type: "object",
177
+ properties: {
178
+ status: { type: "string", enum: ["active", "inactive", "pending"] },
179
+ },
180
+ };
181
+
182
+ const tsConverter = new TypescriptConverter(enumSchema, { enumStyle: "enum" });
183
+ console.log(tsConverter.code);
184
+
185
+ // Output:
186
+ // export enum Status { Active = "active", Inactive = "inactive", Pending = "pending" }
187
+ //
188
+ // export type Root = { status?: Status; };
189
+ ```
190
+
191
+ Custom uncountable words:
192
+
193
+ ```javascript
194
+ const tsConverter = new TypescriptConverter(schema, {
195
+ uncountableWords: ["criteria", "alumni"],
196
+ });
197
+ // "criteria" array items will produce type "Criteria", not "Criterium"
150
198
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ajsc",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "description": "Another Json-Schema Converter",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",