Skip to content

muze-nl/assert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub License GitHub package.json version NPM Version npm bundle size Project stage: Development

Assert: optional assertion checking

import { assert, enable, Optional, Required, oneOf, validURL } from '@muze-nl/assert/core'

enable()

function registerClient(metadata) {
	assert(metadata, {
		redirect_uris: Required([validURL]),
		application_type: Optional(oneOf('web', 'native')),
		client_name: Optional(String)
	})

	// continue with metadata known to match the expected shape
}

Table of Contents

  1. Introduction
  2. Usage
  3. Documentation
  4. License

Introduction

Assert is a lightweight library for optional runtime checks. It is meant for code that benefits from explicit developer feedback during development, but should not spend time validating assumptions in production unless you ask it to.

Assertions are disabled by default. assert() returns immediately until you call enable(). When enabled, failed assertions throw an error with path-aware details. If you always want to validate and handle failures yourself, use fails() or issues() directly.

This style is useful for design-by-contract checks, protocol implementations, middleware preconditions, mock servers, and other places where executable requirements make code easier to understand.

Usage

Install with npm:

npm install @muze-nl/assert

Use the side-effect-free entry point when you want tree-shaking:

import { assert, enable, Required, validURL } from '@muze-nl/assert/core'

The package root exports the same API and also assigns it to globalThis.assert for compatibility:

import * as assert from '@muze-nl/assert'

In the browser, using a CDN:

<script src="https://cdn.jsdelivr.net/npm/@muze-nl/assert/dist/assert.min.js" crossorigin="anonymous"></script>

This loads the API as window.assert.

Documentation

License

This software is licensed under the MIT open source license. See the License file.

About

lightweight optional assertion checking

Resources

License

Stars

0 stars

Watchers

2 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors