Skip to content

Commit 21a125c

Browse files
committed
💄 style: pass linter issues
1 parent 7859edb commit 21a125c

File tree

5 files changed

+64
-53
lines changed

5 files changed

+64
-53
lines changed

src/__demos__/map-demo.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,41 @@ console.log(JSON.stringify(basicMap, null, 2));
1616
// Map with custom key tokens and values
1717
console.log('\n2. Map with custom user IDs and profile data:');
1818
const userMap = TemplateJson.gen([
19-
'map',
20-
['list', 'user_', ['pick', '001', '002', '003', '004', '005']],
21-
[
22-
'obj',
23-
[
24-
['name', ['str', ['list', ['pick', 'John', 'Jane', 'Bob', 'Alice'], ' ', ['pick', 'Doe', 'Smith', 'Johnson']]]],
25-
['age', ['int', 18, 65]],
26-
['active', 'bool'],
27-
],
28-
],
29-
2,
30-
4,
19+
'map',
20+
['list', 'user_', ['pick', '001', '002', '003', '004', '005']],
21+
[
22+
'obj',
23+
[
24+
['name', ['str', ['list', ['pick', 'John', 'Jane', 'Bob', 'Alice'], ' ', ['pick', 'Doe', 'Smith', 'Johnson']]]],
25+
['age', ['int', 18, 65]],
26+
['active', 'bool'],
27+
],
28+
],
29+
2,
30+
4,
3131
]);
3232
console.log(JSON.stringify(userMap, null, 2));
3333

3434
// Map with complex nested structures
3535
console.log('\n3. Map with API endpoints and their configurations:');
3636
const apiMap = TemplateJson.gen([
37-
'map',
38-
['list', 'api/', ['pick', 'users', 'posts', 'comments', 'auth']],
39-
[
40-
'obj',
41-
[
42-
['method', ['str', ['pick', 'GET', 'POST', 'PUT', 'DELETE']]],
43-
['timeout', ['int', 1000, 5000]],
44-
['retries', ['int', 0, 3]],
45-
['auth_required', 'bool'],
46-
],
47-
],
48-
3,
49-
3,
37+
'map',
38+
['list', 'api/', ['pick', 'users', 'posts', 'comments', 'auth']],
39+
[
40+
'obj',
41+
[
42+
['method', ['str', ['pick', 'GET', 'POST', 'PUT', 'DELETE']]],
43+
['timeout', ['int', 1000, 5000]],
44+
['retries', ['int', 0, 3]],
45+
['auth_required', 'bool'],
46+
],
47+
],
48+
3,
49+
3,
5050
]);
5151
console.log(JSON.stringify(apiMap, null, 2));
5252

5353
// Map with guaranteed size
5454
console.log('\n4. Map with exactly 2 entries:');
55-
const fixedMap = TemplateJson.gen([
56-
'map',
57-
['pick', 'key1', 'key2', 'key3'],
58-
['or', 'str', 'int', 'bool'],
59-
2,
60-
2,
61-
]);
55+
const fixedMap = TemplateJson.gen(['map', ['pick', 'key1', 'key2', 'key3'], ['or', 'str', 'int', 'bool'], 2, 2]);
6256
console.log(JSON.stringify(fixedMap, null, 2));

src/string.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ export function randomString(token: Token): string {
5858
}
5959
return str;
6060
}
61-
case 'list':
61+
case 'list': {
6262
const [, ...every] = token;
6363
return every.map(randomString).join('');
64+
}
6465
default:
6566
throw new Error('Invalid token type');
6667
}

src/structured/TemplateJson.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
import {int} from "../number";
2-
import {randomString} from "../string";
3-
import {clone} from "../util";
4-
import * as templates from "./templates";
5-
import type {ArrayTemplate, BooleanTemplate, FloatTemplate, IntegerTemplate, LiteralTemplate, MapTemplate, NumberTemplate, ObjectTemplate, OrTemplate, StringTemplate, Template, TemplateNode, TemplateShorthand} from "./types";
1+
import {int} from '../number';
2+
import {randomString} from '../string';
3+
import {clone} from '../util';
4+
import * as templates from './templates';
5+
import type {
6+
ArrayTemplate,
7+
BooleanTemplate,
8+
FloatTemplate,
9+
IntegerTemplate,
10+
LiteralTemplate,
11+
MapTemplate,
12+
NumberTemplate,
13+
ObjectTemplate,
14+
OrTemplate,
15+
StringTemplate,
16+
Template,
17+
TemplateNode,
18+
TemplateShorthand,
19+
} from './types';
620

721
export interface TemplateJsonOpts {
822
/**
@@ -23,7 +37,10 @@ export class TemplateJson {
2337
protected nodes: number = 0;
2438
protected maxNodes: number;
2539

26-
constructor(public readonly template: Template = templates.nil, public readonly opts: TemplateJsonOpts = {}) {
40+
constructor(
41+
public readonly template: Template = templates.nil,
42+
public readonly opts: TemplateJsonOpts = {},
43+
) {
2744
this.maxNodes = opts.maxNodes ?? 100;
2845
}
2946

@@ -115,7 +132,7 @@ export class TemplateJson {
115132
}
116133

117134
protected generateNumber([, min, max]: NumberTemplate): number {
118-
if (Math.random() > .5) return this.generateInteger(['int', min, max]);
135+
if (Math.random() > 0.5) return this.generateInteger(['int', min, max]);
119136
else return this.generateFloat(['float', min, max]);
120137
}
121138

src/structured/__tests__/TemplateJson.spec.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,17 +319,19 @@ describe('TemplateJson', () => {
319319
});
320320

321321
test('handles complex nested templates', () => {
322-
const map = deterministic(12345789, () => TemplateJson.gen([
323-
'map',
324-
['list', 'user_', ['pick', '1', '2', '3']],
325-
[
326-
'obj',
322+
const map = deterministic(12345789, () =>
323+
TemplateJson.gen([
324+
'map',
325+
['list', 'user_', ['pick', '1', '2', '3']],
327326
[
328-
['name', 'str'],
329-
['age', 'int'],
327+
'obj',
328+
[
329+
['name', 'str'],
330+
['age', 'int'],
331+
],
330332
],
331-
],
332-
])) as Record<string, unknown>;
333+
]),
334+
) as Record<string, unknown>;
333335
expect(typeof map).toBe('object');
334336
const keys = Object.keys(map);
335337
for (const key of keys) {

src/structured/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import type {Token} from '../string';
33
/**
44
* Schema (template) for random JSON generation.
55
*/
6-
export type Template =
7-
| TemplateShorthand
8-
| TemplateNode
9-
| TemplateRecursiveReference;
6+
export type Template = TemplateShorthand | TemplateNode | TemplateRecursiveReference;
107

118
export type TemplateNode =
129
| LiteralTemplate

0 commit comments

Comments
 (0)