# nanoassert

> Nanoscale assertion module

Latest version **3.1.0** (published 2026-03-12) · ISC license · 780.8K weekly downloads

## Install

```sh
npm install nanoassert
pnpm add nanoassert
yarn add nanoassert
bun add nanoassert
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: moderate downloads; has types; no vulnerabilities; high quality score.

Warnings: no esm support.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2026-03-12 |
| First published | 2017-06-08 |
| Weekly downloads | 780.8K |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 33 |
| Author | Emil Bay |
| Maintainers | emilbayes |
| Keywords | assert, unassert, power-assert, tiny, nano, pico |

## Links

- npm: https://www.npmjs.com/package/nanoassert
- Repository: https://github.com/emilbayes/nanoassert
- Homepage: https://github.com/emilbayes/nanoassert#readme
- Issues: https://github.com/emilbayes/nanoassert/issues
- npm.io page: https://npm.io/package/nanoassert

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads
- [recordrtc](https://npm.io/package/recordrtc.md) — 266.3K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2026-03-12
- 3.0.1 — 2025-06-28
- 3.0.0 — 2025-06-28
- 2.0.0 — 2019-01-21
- 1.1.0 — 2017-07-24
- 1.0.0 — 2017-06-08

## README

# `nanoassert`

[![NPM](https://github.com/emilbayes/nanoassert/actions/workflows/npm.yml/badge.svg)](https://github.com/emilbayes/nanoassert/actions/workflows/npm.yml)

> Nanoscale assertion module

## Usage

```js
const assert = require('nanoassert')

assert(a !== b, `${a} !== ${b}`)
```

## API

### `assert(predicate, [message])`

Assert that `predicate` is truthy, otherwise throw `AssertionError` with
optional `message`. In Javascript runtimes that support `Error.captureStackTrace`, you will get a nicer
stack trace with this error.
If you want friendlier messages you can use template strings to show the
assertion made like in the example above.

## Why

I like to write public facing code very defensively, but have reservations about
the size incurred by the `assert` module. I only use the top-level `assert`
method anyway.

## `nanoassert@^1.1.0`

Docs for the previous version, which is used by many modules on npm, can be
[found here](https://github.com/emilbayes/nanoassert/tree/v1.1.0)

## `nanoassert@^3.0.0`

Modernise `nanoassert` some, and add the small type definition from `DefinitelyTyped`. Functionally there should be no changes for most users, but the `name` property of the `AssertionError` is no longer set on the prototype, and newer syntax is employed, which might break some downstream modules.

Thank you to the folks that created and maintained the original type definitions.

## Install

```sh
npm install nanoassert
```

## License

[ISC](LICENSE)

---
_Source: https://npm.io/package/nanoassert · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
