Heap.String
Declares a field of type string
(a string in UTF-8 encoding).
Usage / Signature
import { Heap } from '@app/heap'
Heap.String(options)
Arguments
-
<b id="options">options</b>:
{
default, minLength, maxLength, format, pattern}
An object with additional optional parameters for the field.-
<b id="default">default</b>:
string
The default value for this field. For more information on how default values work, see Guide / Heap / Default Values -
<b id="minLength">minLength</b>:
number
The minimum length of the string. -
<b id="maxLength">maxLength</b>:
number
The maximum length of the string. -
<b id="format">format</b>:
"date-time" | "email"
Built-in string format validator according to the JSON-schema specification. Only 2 formats are supported:date-time
andemail
. -
<b id="pattern">pattern</b>:
string
A regular expression that the string must match. The expression should be represented as a plain string, not an instance of the RegExp class, without slashes at the beginning and end and without flags. Regular expression flags (e.g.,i
- ignore case) are not supported by the validator. Only theu
flag - Unicode support is applied during validation.
-
Return Value
JSON Schema for the string field.
Examples
Any string
const orgs = Heap.Table('orgs', {
name: Heap.String(),
})
Any valid email address
const customers = Heap.Table('customers', {
email: Heap.String({ format: 'email' }),
})
A string consisting only of lowercase Latin letters with exactly 32 characters
const products = Heap.Table('products', {
partno: Heap.String({
pattern: '^[a-z]*$',
minLength: 32,
maxLength: 32,
}),
})