Skip to content

Commit fbb2be7

Browse files
add support UUID v6 v7 v8 (#124)
1 parent de16f17 commit fbb2be7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/schema/string/rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ export const postalCodeRule = createRule<
383383
/**
384384
* Validates the value to be a valid UUID
385385
*/
386-
export const uuidRule = createRule<{ version?: (1 | 2 | 3 | 4 | 5)[] } | undefined>(
386+
export const uuidRule = createRule<{ version?: (1 | 2 | 3 | 4 | 5 | 6 | 7 | 8)[] } | undefined>(
387387
function uuid(value, options, field) {
388388
if (!options || !options.version) {
389389
if (!helpers.isUUID(value as string)) {

tests/unit/rules/string.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,22 @@ test.group('String | uuid', () => {
12871287
rule: uuidRule({ version: [1, 4] }),
12881288
value: '71e4fbab-3498-447b-a97c-2c6060069678',
12891289
},
1290+
{
1291+
rule: uuidRule({ version: [6] }),
1292+
value: '1ec9414c-232a-6b00-b3c8-9e6bdeced846',
1293+
},
1294+
{
1295+
rule: uuidRule({ version: [7] }),
1296+
value: '017f22e2-79b0-7cc3-98c4-dc0c0c07398f',
1297+
},
1298+
{
1299+
rule: uuidRule({ version: [8] }),
1300+
value: '12345678-1234-8234-a234-123456789012',
1301+
},
1302+
{
1303+
rule: uuidRule({ version: [4, 6, 7, 8] }),
1304+
value: '71e4fbab-3498-447b-a97c-2c6060069678',
1305+
},
12901306
])
12911307
.run(stringRuleValidator)
12921308
})

0 commit comments

Comments
 (0)