KeySchemaclass
new KeySchema({ one = "key", title = "Key", min = 1, max = 32, ...options }: StringSchemaOptions)| Param | Type | |
|---|---|---|
options | StringSchemaOptions | Options for StringSchema. required |
.value | string | Default string value used when the input is undefined. Defaults to "" readonly |
.min | number | Minimum allowed character length. Defaults to 0 readonly |
.max | number | Maximum allowed character length. Defaults to Number.POSITIVE_INFINITY readonly |
.rows | number | Number of rows; more than one enables multiline sanitization. Defaults to 1 readonly |
.match | RegExp | Regular expression the sanitized string must match. readonly |
.case | "upper""lower" | Force the result to "upper" or "lower" case. readonly |
.input | StringInputType | HTML <input /> type="" hint for downstream UIs. Defaults to "text" readonly |
| Return | |
|---|---|
KeySchema | Schema that validates a database key string, stripping any non-alphanumeric characters. |
Schema that validates a database key string, stripping any non-alphanumeric characters.
- Characters that are not a-z, A-Z, 0-9 are removed.
- Default minimum key length is 1 character.
- Default maximum key length is 32 characters.
- 32 characters is enough for UUIDs, as the 4
-hyphens are removed.
Examples
const schema = new KeySchema({});
schema.validate("a1b2-c3d4"); // "a1b2c3d4"