surimi

surimi.dev - reference

surimi reference

This page is a reference for the Surimi library, which provides a set of mixins and functions for validating Sass variables against defined schemas.

Content:


Validation

validate

Signature: s.validate($schema, $value, $label: null, $throw: true, $prefix: 'surimi')

Validate a given value against a schema.

If a label is provided, it will be used in error messages (if the schema did not provide one.). Otherwise, a default label will be used based on the schema type.

If $throw is set to true, an error will be thrown if the value does not match the schema. If false, will show warnings instead.

Example:

$schema: s.list(s.number($min: 0, $max: 100), $unique: true);

@include s.validate($schema, [10, 20, 30] );

validate-fn

Signature: validate-fn($schema, $value, $label: null, $throw: true, $warn: false, $prefix: 'surimi')

Validate a given value against a schema.

If a label is provided, it will be used in error messages (if the schema did not provide one.). Otherwise, a default label will be used based on the schema type.

If $throw is set to true, an error will be thrown if the value does not match the schema. If false, will return the list of errors! This is different from s.validate, which will show warnings in that case. To show warnings instead of errors, set $warn to true.

Example:

$schema: s.list(s.number($min: 0, $max: 100), $unique: true);

@include s.validate($schema, [10, 20, 30] );

Schema functions

All schemas validate the value input type by default. So a number schema will only accept numbers, passing a string will result in an error.

number

Signature: s.number($label: null, $args...)

Example:

$schema: s.number(
  $min: 0,
  $max: 100,
);

Available validators:

Aliases:


string

Signature: s.string($label: null, $args...)

Example:

$schema: s.string(
  $min-length: 0,
  $max-length: 100,
);

Available validators:

Aliases:


map

Signature: s.map($schema, $label: null, $args...)

Example:

$schema: s.map((
  'key1': s.string($min-length: 1),
  'key2': s.number($min: 0, $max: 100),
  )
);

Available validators:

Aliases:


list

Example:

$schema: s.list(s.number($min: 0, $max: 100), $unique: true);

Available validators:

Aliases: