via-type

Basic types for via.

Usage no npm install needed!

<script type="module">
  import viaType from 'https://cdn.skypack.dev/via-type';
</script>

README

Via-Type

Description

Simple type interfaces.

Install

npm install
gulp build.node

API

String

new StringType(options: DocumentOptions);
export interface StringOptions {
  regex?: RegExp; // null
  lowerCase?: boolean; // false
  trimmed?: boolean; // false
  minLength?: number; // null
  maxLength?: number; // null
  
  looseTest?: boolean; // false
}

looseTest: The test returns true if the only errors found can be fixed with .normalize.

.test(options: StringOptions)

Tests whether a string is valid or not according to the options.

Document

new DocumentType(options: DocumentOptions);

Creates a new type to match against documents. This type ensures that the defined properties are set, enumerable and valid.

DocumentOptions:

  • properties: Dictionary<PropertyDescriptor>: Each key is used as the property name and the associated behaviour is determined by the associated PropertyDescriptor. If the value is null, then the property is deleted (ignored) - usefull when extending the DocumentOptions.

    PropertyDescriptor:

    • type: Type: the type of the property (soon: If the type is null -> allow any value, requires manual read/write)

    • optional: boolean: Allows the value to be null

  • additionalProperties: boolean: Allow (and ignore) additional properties when doing tests

.diff

interface DiffResult {
    $set: Dictionary<jsonValues>;
    $update: Dictionary<Diff>;
    $unset: Dictionary<jsonValues>;
}