File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -296,6 +296,23 @@ uuidValidate('not a UUID'); // ⇨ false
296
296
uuidValidate (' 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b' ); // ⇨ true
297
297
```
298
298
299
+ Using ` validate ` and ` version ` together it is possible to do per-version validation, e.g. validate for only v4 UUIds.
300
+
301
+ ``` javascript
302
+ import { version as uuidVersion } from ' uuid' ;
303
+ import { validate as uuidValidate } from ' uuid' ;
304
+
305
+ function uuidValidateV4 (uuid ) {
306
+ return uuidValidate (uuid) && uuidVersion (uuid) === 4 ;
307
+ }
308
+
309
+ const v1Uuid = ' d9428888-122b-11e1-b85c-61cd3cbb3210' ;
310
+ const v4Uuid = ' 109156be-c4fb-41ea-b1b4-efe1671c5836' ;
311
+
312
+ uuidValidateV4 (v4Uuid); // ⇨ true
313
+ uuidValidateV4 (v1Uuid); // ⇨ false
314
+ ```
315
+
299
316
### uuid.version(str)
300
317
301
318
Detect RFC version of a UUID
Original file line number Diff line number Diff line change @@ -302,6 +302,23 @@ uuidValidate('not a UUID'); // RESULT
302
302
uuidValidate (' 6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b' ); // RESULT
303
303
```
304
304
305
+ Using ` validate ` and ` version ` together it is possible to do per-version validation, e.g. validate for only v4 UUIds.
306
+
307
+ ``` javascript --run
308
+ import { version as uuidVersion } from ' uuid' ;
309
+ import { validate as uuidValidate } from ' uuid' ;
310
+
311
+ function uuidValidateV4 (uuid ) {
312
+ return uuidValidate (uuid) && uuidVersion (uuid) === 4 ;
313
+ }
314
+
315
+ const v1Uuid = ' d9428888-122b-11e1-b85c-61cd3cbb3210' ;
316
+ const v4Uuid = ' 109156be-c4fb-41ea-b1b4-efe1671c5836' ;
317
+
318
+ uuidValidateV4 (v4Uuid); // RESULT
319
+ uuidValidateV4 (v1Uuid); // RESULT
320
+ ```
321
+
305
322
### uuid.version(str)
306
323
307
324
Detect RFC version of a UUID
You can’t perform that action at this time.
0 commit comments