mirror of
https://github.com/directus/directus.git
synced 2026-02-14 13:04:57 -05:00
Include schema package
This commit is contained in:
14
packages/schema/src/utils/extract-max-length.ts
Normal file
14
packages/schema/src/utils/extract-max-length.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Extracts the length value out of a given datatype
|
||||
* For example: `varchar(32)` => 32
|
||||
*/
|
||||
export default function extractMaxLength(type: string): null | number {
|
||||
const regex = /\(([^)]+)\)/;
|
||||
const matches = regex.exec(type);
|
||||
|
||||
if (matches && matches.length > 0 && matches[1]) {
|
||||
return Number(matches[1]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user