String schema
A function which creates a parsing rule to ensure that a given value is a string.
Arguments
modifiers?- A list of modifiersmin: Learn moremax: Learn moreemail: Learn moreenumerator: Learn morecustom: Learn moreurl: Learn moreuuid: Learn morephone: Learn moreip: Learn morecreditCard: Learn moretrim: Learn moreincludes: Learn morestartsWith: Learn moreendsWith: Learn moreslug: Learn morepattern: Learn more
message?- A custom object with error messages to be displayed when validation fails or there are type errors
Examples
import { string } from '@nordic-ui/validathor';
 
const stringRule = string();
 
try {
  const parsedValue = stringRule.parse('Hello world');
  console.log('Parsed value:', parsedValue);
} catch (error) {
  console.error('Parsing failed:', error.message);
}TypeScript
To get the type of a schema, you can do the following:
const stringRule = string();
 
type StringSchema = ReturnType<typeof stringRule.parse>; // string