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

10.2.2 • Public • Published

📐rulr

Validation and unit conversion errors in TypeScript at compile-time.

License: MIT Uses Semantic Release to correctly bump versions especially for breaking changes Uses Renovate to keep dependencies updated Master branch coverage percentage from Codecov Package size from BundlePhobia
// Install it with `npm i rulr`
import * as rulr from 'rulr'

// Compile-time error.
const positiveNumber1: rulr.PositiveNumber = -1

// Run-time error.
const positiveNumber2 = rulr.positiveNumber(-1)

// Convenient rules and guards like `object`.
const example = rulr.object({
	required: {
		price: rulr.positiveNumber,
	},
})

// Turn rules into types to avoid duplicating information.
type Example = rulr.Static<typeof example>

// Turn rules into guards to avoid duplicating code.
const isExample = rulr.guard(example)

// Use rules and/or guards to guarantee your data is valid.
const myExample: Example = example({ price: 12.34 })
if (isExample(myExample)) {
	console.log(myExample.price)
}

Getting Started ✨

To save you some time, Rulr comes with the following rules.

Sized Strings

Since it's quite common to want to restrict the size of strings, Rulr comes with some convenient rules for doing just that.

Constraining Strings

Rulr also comes with a growing list of convenient rules for constraining strings that are mostly built on Chris O'Hara's extensive and much loved validator package.

Constraining Non-Strings

In addition to the constrained strings, Rulr also comes with a few convenient rules to help you quickly validate non-string values.

Sanitization Rules

Finally, Rulr is starting to provide rules that sanitize inputs from HTTP headers and URL params.

Frequently Awesome Questions 🤘

Background

Rulr was started in 2016 and first publicised in 2020. It continues to be maintained to save us time writing validation logic and correcting data by returning as many validation errors as possible in one function call.

Rulr has been influenced by Tom Crockett in RunTypes and more recently Colin McDonnell in Zod. It's hoped that if nothing else, publicising Rulr will influence existing and future validation packages for the better.

Readme

Keywords

none

Package Sidebar

Install

npm i rulr

Weekly Downloads

1,395

Version

10.2.2

License

MIT

Unpacked Size

332 kB

Total Files

109

Last publish

Collaborators

  • ryansmith94