@bicknese/gater
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

Gater

[!IMPORTANT]
This is a tech demo, please use a vetted library like zod for your production applications.

the gater mascot alligator

Gater is a simple, modern and secure object validator for JavaScript and TypeScript.

Features

  • Validates values against schema's during runtime. Quickly know if external input matches the expected shape.
  • Utilizes TypeScript to type check known object shapes against the schema in build time.
  • Create re-usable validators, removing the need to pass the schema each time.

Usage

Run a one-off validation to determine whether an object is valid

isValid(
    { prey: "string", eaten: "boolean" },
    { prey: "fish", eaten: false } // Gater doesn't eat friends
);
// ✅ `true`, given value is valid

Create the validator in advance and validate multiple values

const isFood = isValid({ prey: "string", eaten: "boolean" });

isFood({ prey: "frog", eaten: false });
// ✅ `true`, checks out
isFood({ prey: "seaweed", eaten: 5 });
// ❌ `false`, 5 is not a boolean

Use it to early catch issues with user input

const isFood = isValid({ prey: "string" });

function onSubmit(food) {
    assert(isFood(food));
    // ... safely rely on food being food
}

Node

Install from npmjs

npm i --save @bicknese/gater

And import the isValid function

import { isValid } from '@bicknese/gater';

Deno

Import directly through npm support

import { isValid } from 'npm:@bicknese/gater';

Package Sidebar

Install

npm i @bicknese/gater

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.73 kB

Total Files

4

Last publish

Collaborators

  • mbicknese