mirror of
https://github.com/swc-project/swc.git
synced 2024-12-29 16:42:28 +03:00
22 lines
701 B
TypeScript
22 lines
701 B
TypeScript
// Loaded from https://deno.land/x/segno@v1.1.0/lib/validations/isUUID.ts
|
|
|
|
|
|
// @ts-ignore allowing typedoc to build
|
|
import { assertString } from '../helpers/assertString.ts';
|
|
|
|
/**
|
|
* @ignore
|
|
*/
|
|
const uuid = {
|
|
3: /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
4: /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
5: /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,
|
|
all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
|
};
|
|
|
|
export const isUUID = (str: string, version: 3 | 4 | 5 | 'all' = 'all') => {
|
|
assertString(str);
|
|
const pattern = (uuid as any)[version];
|
|
return pattern && pattern.test(str);
|
|
};
|