Simple, lightweight at-runtime type checking functions, with full TypeScript support

Overview

pheno

Simple, lightweight at-runtime type checking functions, with full TypeScript support

Features

  • Full TypeScript integration: TypeScript understands that assertType and isOfType narrow the types of things, and will refine them accordingly
  • Simple: Type validators are just functions that return booleans.
  • Effective: There's lots of utility functions that help you represent all the various types you'd care about in your code.
  • Lightweight: The whole library is 10.5K minified (3K gzipped), but it's also fully tree-shakeable, so only the type validators you use end up in your bundle.

Usage Example

import * as types from "pheno";

function something(first: unknown, second: unknown) {
  // Throws an error if `first` is not a string
  types.assertType(first, types.string);

  // Throws an error if `second` is not `string | number`
  types.assertType(second, types.union(types.string, types.number));

  // Typescript now knows that `first` is a string and `second` is `string | number`
  return first + " " + String(second);
}

List of types and type builder functions

  • and
  • any
  • anyArray
  • anyFunction
  • anyMap
  • anyObject
  • anySet
  • array
  • arrayOf
  • arrayOfAny
  • arrayOfUnknown
  • assertType
  • asType
  • boolean
  • Error_
  • exactNumber
  • exactString
  • false_
  • falsy
  • hasClassName
  • Infinity_
  • instanceOf
  • integer
  • intersection
  • isOfType
  • map
  • mapOf
  • mappingObjectOf
  • maybe
  • NaN_
  • NegativeInfinity
  • never
  • nonNullOrUndefined
  • null_
  • nullish
  • number
  • numberIncludingNanAndInfinities
  • object
  • objectWithOnlyTheseProperties
  • objectWithProperties
  • or
  • partialObjectWithProperties
  • record
  • set
  • setOf
  • string
  • stringMatching
  • Symbol_
  • symbolFor
  • true_
  • truthy
  • tuple
  • undefined_
  • union
  • unknown
  • unknownFunction
  • unknownMap
  • unknownObject
  • unknownSet

Please see the TypeScript types for each of these in either your editor's autocomplete or pheno's source code for more information.

License

MIT

You might also like...

Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Nov 2, 2022

Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.

Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.

Functions Recipes Introduction Salesforce Functions lets you use the Salesforce Platform for building event-driven, elastically scalable apps and expe

Dec 29, 2022

🔥 A Powerful JavaScript Module for Generating and Checking Discord Nitro 🌹

🔥 A Powerful JavaScript Module for Generating and Checking Discord Nitro 🌹

DANG: Dreamy's Awesome Nitro Generator Join Our Discord Getting Started Before, We start please follow these Steps: Required* ⭐ Give a Star to this dr

Jan 5, 2023

Babel-plugin-amd-checker - Module format checking plugin for Babel usable in both Node.js the web browser environments.

babel-plugin-amd-checker A Babel plugin to check the format of your modules when compiling your code using Babel. This plugin allows you to abort the

Jan 6, 2022

This package is for developers to be able to easily integrate bad word checking into their projects.\r This package can return bad words in array or regular expression (regex) form.

Vietnamese Bad Words This package is for developers to be able to easily integrate bad word checking into their projects. This package can return bad

Nov 3, 2022

The ultimate parity checking as-a-service platform.

Astro Starter Kit: Minimal npm create astro@latest -- --template minimal 🧑‍🚀 Seasoned astronaut? Delete this file. Have fun! 🚀 Project Structure I

Nov 28, 2022

Snipes Test Flight apps. Configurable & has the ability to use a burner account for checking the status to avoid bans.

Snipes Test Flight apps. Configurable & has the ability to use a burner account for checking the status to avoid bans.

TestFlight Sniper Snipes TestFlight beta apps. Configurable & has the ability to use a burner account for checking the status to avoid bans. Features

Dec 20, 2022

Runtime object parsing and validation with static TypeScript typing.

TypeParse Runtime object transformation, parsing and validation with inferred static TypeScript typing. Install Using npm npm install typeparse Using

May 5, 2022

A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.

A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects.

🌍 typesafe-i18n A fully type-safe and lightweight internationalization library for all your TypeScript and JavaScript projects. Advantages 🐤 lightwe

Jan 4, 2023
Owner
Lily Scott
Former Prettier Core Team member, Former Babel team member. Interested in JavaScript, Rust, Unity, VR, Dev Tooling, Dev Experience, React, and more.
Lily Scott
Runtime type checking in pure javascript.

Install npm install function-schema Usage import { signature } from 'function-schema'; const myFunction = signature(...ParamTypeChecks)(ReturnValueCh

Jeysson Guevara 3 May 30, 2022
A type speed checking website which lets you check your typing speed and shows the real-tme leaderboards with mongodb as DB and express as backend

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Sreehari jayaraj 8 Mar 27, 2022
A library to create pipelines with contexts and strong type checking.

TypePipe A library to create pipelines with contexts and strong type checking. Installation With Node.js and npm installed in your computer run: npm i

Alvaro Fresquet 16 Jun 11, 2022
TypeScript type definitions for Bun's JavaScript runtime APIs

Bun TypeScript type definitions These are the type definitions for Bun's JavaScript runtime APIs. Installation Install the bun-types npm package: # ya

Oven 73 Dec 16, 2022
🐬 A simplified implementation of TypeScript's type system written in TypeScript's type system

?? HypeScript Introduction This is a simplified implementation of TypeScript's type system that's written in TypeScript's type annotations. This means

Ronen Amiel 1.8k Dec 20, 2022
Zero runtime type-safe CSS in the same file as components

macaron comptime-css is now called macaron! macaron is a zero-runtime and type-safe CSS-in-JS library made with performance in mind Powered by vanilla

Mokshit Jain 205 Jan 4, 2023
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
A type programming language which compiles to and interops with type-level TypeScript

Prakaar Prakaar (hindi for "type") is a type programming language which compiles to and interops with type-level TypeScript. Prakaar itself is also a

Devansh Jethmalani 17 Sep 21, 2022
A transpiler from golang's type to typescript's type for collaboration between frontend & backend.

go2type go2type.vercel.app (backup site) A typescript transpiler that convert golang's type to typescript's type. Help front-end developer to work fas

Oanakiaja 8 Sep 26, 2022
ToDo list app is a simple web app that helps you organize your day, by adding, checking and deleting daily tasks

TODO List App "To-do list" is a WebApp tool that helps to organize your day. It simply lists the tasks that you need to do and allows you to mark them

Adel Guitoun 8 Oct 18, 2022