0.1.6 • Published 4 years ago

strngle v0.1.6

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Strngle

Composable string validation!

A pretty neat way to validate the content of strings. Use the validators Strngle comes with, or add your own. Strngle is written in Typescript and comes with full type definitions.

Docs will be added eventually.

Installation

npm:

npm i strngle

yarn:

yarn add strngle

Basic usage

import { validate, required, hasMinMax } from 'strngle';

const { valid, message } = validate(someUnknownValue, [
  required(),
  hasMinMax({ min: 5, max: 10 }),
]);

if (!valid) {
  console.error(`The input is invalid: ${message}!`);
}

Adding your own validators

import { validate } from 'strngl';

const startsWith = (character) => {
  return {
    validator(value) {
      if (value.charAt(0) !== character) {
        return {
          valid: false,
          message: `Must begin with ${character}`,
        };
      }
      return {
        valid: true,
      };
    },
  };
};

const { valid } = validate(someString, [startsWith('A')]);
0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.2

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago