Skip to content

Ducto.js is a collection of functions for validation and modification of data throught pipelining.

License

Notifications You must be signed in to change notification settings

mathiasgheno/ducto

Repository files navigation

Ducto

Ducto.js is a collection of functions for validation and modification of data throught pipelining.

  • ✅ Functional API
  • ✅ Support for ECMAScript Pipeline Operator (see docs)

Install

npm install @ducto/core @ducto/validators

How to Use

In ducto you can provide multiples validators and if one of them fails, the whole pipeline fails. This approach is very useful when you want to validate a pipeline step by step.

import { ducto } from '@ducto/core';
import {
  isString,
  isNotNull,
  hasLessCharactersThan,
  hasMoreCharactersThan,
} from '@ducto/validators';

const validator = ducto(
  isNotNull,
  isString,
  hasLessCharactersThan(100),
  hasMoreCharactersThan(10),
)

try {
  validator('mathiasgheno');
  console.log('all ok');
} catch (e) {
  console.log(e.message);
}

try {
  validator('mathias');
} catch (e) {
  console.log(e.message);
  console.log(e.debug);
}

You can alse use it with the Pipeline Operator. Please see the docs.

import {
  isString,
  isNotNull,
  hasLessCharactersThan,
  hasMoreCharactersThan,
} from '@ducto/validators';

'mathiasgheno'
  |> isNotNull(#)
  |> isString(#)
  |> hasLessCharactersThan(100)(#)
  |> hasMoreCharactersThan(10)(#)

General Documentation

About

Ducto.js is a collection of functions for validation and modification of data throught pipelining.

Topics

Resources

License

Stars

Watchers

Forks