strngle
TypeScript icon, indicating that this package has built-in type declarations

0.1.6 • Public • Published

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')]);

/strngle/

    Package Sidebar

    Install

    npm i strngle

    Weekly Downloads

    1

    Version

    0.1.6

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    26

    Last publish

    Collaborators

    • jackchapman11101