Skip to content

Commit 297bafe

Browse files
authoredJun 9, 2023
fix: handle numbers and some puncuation in enum values (#89)
1 parent c56164b commit 297bafe

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
 

‎src/__tests__/markdown-helpers.spec.ts

+28
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,34 @@ def fn():
170170
expect(values[1].value).toBe('b_c');
171171
expect(values[2].value).toBe('d');
172172
});
173+
174+
it('should extract an enum with fullstops in the values', () => {
175+
const values = extractStringEnum('Values includes `a`, `b.c` and `d`')!;
176+
expect(values).not.toBe(null);
177+
expect(values).toHaveLength(3);
178+
expect(values[0].value).toBe('a');
179+
expect(values[1].value).toBe('b.c');
180+
expect(values[2].value).toBe('d');
181+
});
182+
183+
it('should extract an enum with colons in the values', () => {
184+
const values = extractStringEnum('Values includes `a`, `https:` and `d`')!;
185+
expect(values).not.toBe(null);
186+
expect(values).toHaveLength(3);
187+
expect(values[0].value).toBe('a');
188+
expect(values[1].value).toBe('https:');
189+
expect(values[2].value).toBe('d');
190+
});
191+
192+
it('should extract an enum with numbers in the values', () => {
193+
const values = extractStringEnum('Can be `tls1`, `tls1.1`, `tls1.2` or `tls1.3`.')!;
194+
expect(values).not.toBe(null);
195+
expect(values).toHaveLength(4);
196+
expect(values[0].value).toBe('tls1');
197+
expect(values[1].value).toBe('tls1.1');
198+
expect(values[2].value).toBe('tls1.2');
199+
expect(values[3].value).toBe('tls1.3');
200+
});
173201
});
174202

175203
describe('with single quotes', () => {

‎src/markdown-helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,11 @@ export enum StripReturnTypeBehavior {
456456
export const extractStringEnum = (description: string): PossibleStringValue[] | null => {
457457
const possibleValues: PossibleStringValue[] = [];
458458

459-
const inlineValuesPattern = /(?:can be|values? includes?) ((?:(?:[`|'][a-zA-Z-_]+[`|'])(?:(, | )?))*(?:(?:or|and) [`|'][a-zA-Z-_]+[`|'])?)/i;
459+
const inlineValuesPattern = /(?:can be|values? includes?) ((?:(?:[`|'][a-zA-Z0-9-_\.:]+[`|'])(?:(, | )?))*(?:(?:or|and) [`|'][a-zA-Z0-9-_\.:]+[`|'])?)/i;
460460
const inlineMatch = inlineValuesPattern.exec(description);
461461
if (inlineMatch) {
462462
const valueString = inlineMatch[1];
463-
const valuePattern = /[`|']([a-zA-Z-_]+)[`|']/g;
463+
const valuePattern = /[`|']([a-zA-Z0-9-_\.:]+)[`|']/g;
464464
let value = valuePattern.exec(valueString);
465465

466466
while (value) {

0 commit comments

Comments
 (0)
Please sign in to comment.