@se-oss/assert 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shahrad Elahi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,108 @@
1
+ # @se-oss/assert
2
+
3
+ [![CI](https://github.com/shahradelahi/assert/actions/workflows/ci.yml/badge.svg?branch=main&event=push)](https://github.com/shahradelahi/assert/actions/workflows/ci.yml)
4
+ [![NPM Version](https://img.shields.io/npm/v/@se-oss/assert.svg)](https://www.npmjs.com/package/@se-oss/assert)
5
+ [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](/LICENSE)
6
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/@se-oss/assert)
7
+ [![Install Size](https://packagephobia.com/badge?p=@se-oss/assert)](https://packagephobia.com/result?p=@se-oss/assert)
8
+
9
+ _@se-oss/assert_ is a lightweight, type-safe assertion library for TypeScript and JavaScript, powered by [@se-oss/is](https://github.com/shahradelahi/is).
10
+
11
+ ---
12
+
13
+ - [Installation](#-installation)
14
+ - [Usage](#-usage)
15
+ - [Documentation](#-documentation)
16
+ - [Contributing](#-contributing)
17
+ - [License](#license)
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install @se-oss/assert
23
+ ```
24
+
25
+ <details>
26
+ <summary>Install using your favorite package manager</summary>
27
+
28
+ **pnpm**
29
+
30
+ ```bash
31
+ pnpm install @se-oss/assert
32
+ ```
33
+
34
+ **yarn**
35
+
36
+ ```bash
37
+ yarn add @se-oss/assert
38
+ ```
39
+
40
+ </details>
41
+
42
+ ## 📖 Usage
43
+
44
+ _@se-oss/assert_ provides a set of assertion functions that throw a `TypeError` if the condition is not met. It is powered by [@se-oss/is](https://github.com/shahradelahi/is), so all predicates from `is` are available as assertions.
45
+
46
+ ### Basic Example
47
+
48
+ ```typescript
49
+ import { assert } from '@se-oss/assert';
50
+
51
+ // Throws if not a string
52
+ assert.string('hello');
53
+
54
+ // Throws with a custom message
55
+ assert.string(123, 'Value must be a string');
56
+ // => TypeError: Value must be a string
57
+ ```
58
+
59
+ ### Common Assertions
60
+
61
+ ```typescript
62
+ // Numbers
63
+ assert.number(42);
64
+ assert.integer(42);
65
+ assert.positiveNumber(10);
66
+ assert.inRange(15, 'Not in range', [10, 20]);
67
+
68
+ // Objects & Arrays
69
+ assert.plainObject({ foo: 'bar' });
70
+ assert.array([1, 2, 3]);
71
+ assert.nonEmptyArray([1]);
72
+
73
+ // Strings
74
+ assert.nonEmptyString('hello');
75
+ assert.json('{"a":1}');
76
+ assert.ipv4('127.0.0.1');
77
+
78
+ // Logic
79
+ assert.truthy(true);
80
+ assert.falsy(false);
81
+ ```
82
+
83
+ ### Integration with TypeScript
84
+
85
+ The library is fully type-safe and provides type guards for your variables.
86
+
87
+ ```typescript
88
+ function process(value: unknown) {
89
+ assert.string(value);
90
+
91
+ // 'value' is now narrowed to string
92
+ console.log(value.toUpperCase());
93
+ }
94
+ ```
95
+
96
+ ## 📚 Documentation
97
+
98
+ For all configuration options, please see [the API docs](https://www.jsdocs.io/package/@se-oss/assert).
99
+
100
+ ## 🤝 Contributing
101
+
102
+ Want to contribute? Awesome! To show your support is to star the project, or to raise issues on [GitHub](https://github.com/shahradelahi/assert)
103
+
104
+ Thanks again for your support, it is much appreciated! 🙏
105
+
106
+ ## License
107
+
108
+ [MIT](/LICENSE) © [Shahrad Elahi](https://github.com/shahradelahi) and [contributors](https://github.com/shahradelahi/assert/graphs/contributors).
package/dist/index.cjs ADDED
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ assert: () => assert
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_is = __toESM(require("@se-oss/is"), 1);
37
+ var assert = new Proxy({}, {
38
+ get(_target, property) {
39
+ return (value, message, ...args) => {
40
+ const predicate = import_is.default[property];
41
+ if (typeof predicate !== "function") {
42
+ throw new Error(`Unknown assertion: ${property}`);
43
+ }
44
+ if (!predicate(value, ...args)) {
45
+ const defaultMessage = `Expected value to be ${property}, got ${typeof value}`;
46
+ throw new TypeError(message || defaultMessage);
47
+ }
48
+ };
49
+ }
50
+ });
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ assert
54
+ });
@@ -0,0 +1,9 @@
1
+ import is from '@se-oss/is';
2
+
3
+ type IsType = typeof is;
4
+ type Assert = {
5
+ [K in keyof IsType]: IsType[K] extends (value: any, ...args: infer A) => value is infer T ? (value: unknown, message?: string, ...args: A) => asserts value is T : IsType[K] extends (value: any, ...args: infer A) => boolean ? (value: unknown, message?: string, ...args: A) => void : never;
6
+ };
7
+ declare const assert: Assert;
8
+
9
+ export { type Assert, assert };
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ // src/index.ts
2
+ import is from "@se-oss/is";
3
+ var assert = new Proxy({}, {
4
+ get(_target, property) {
5
+ return (value, message, ...args) => {
6
+ const predicate = is[property];
7
+ if (typeof predicate !== "function") {
8
+ throw new Error(`Unknown assertion: ${property}`);
9
+ }
10
+ if (!predicate(value, ...args)) {
11
+ const defaultMessage = `Expected value to be ${property}, got ${typeof value}`;
12
+ throw new TypeError(message || defaultMessage);
13
+ }
14
+ };
15
+ }
16
+ });
17
+ export {
18
+ assert
19
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@se-oss/assert",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight, type-safe assertion library based on @se-oss/is.",
5
+ "keywords": [
6
+ "assert",
7
+ "assertion",
8
+ "validation",
9
+ "type-check",
10
+ "type-safe",
11
+ "is"
12
+ ],
13
+ "homepage": "https://github.com/shahradelahi/assert",
14
+ "repository": "github:shahradelahi/assert",
15
+ "license": "MIT",
16
+ "author": "Shahrad Elahi <shahrad@litehex.com> (https://github.com/shahradelahi)",
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "default": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "files": [
27
+ "dist/**",
28
+ "!**/*.d.cts"
29
+ ],
30
+ "scripts": {
31
+ "bench": "vitest bench --run",
32
+ "build": "pnpm typecheck && tsup",
33
+ "clean": "git clean -dfx node_modules dist .tsbuildinfo",
34
+ "dev": "tsup --watch",
35
+ "format": "prettier --write .",
36
+ "format:check": "prettier --check .",
37
+ "lint": "pnpm typecheck && eslint .",
38
+ "lint:fix": "eslint --fix .",
39
+ "prepublishOnly": "pnpm build && pnpm lint && pnpm format:check && pnpm test",
40
+ "test": "vitest --run",
41
+ "typecheck": "tsc --noEmit"
42
+ },
43
+ "prettier": "@shahrad/prettier-config",
44
+ "dependencies": {
45
+ "@se-oss/is": "^1.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@shahrad/eslint-config": "^1.0.1",
49
+ "@shahrad/prettier-config": "^1.2.2",
50
+ "@shahrad/tsconfig": "^1.2.0",
51
+ "@types/node": "^25.0.10",
52
+ "eslint": "^9.39.2",
53
+ "globals": "^17.1.0",
54
+ "prettier": "^3.8.1",
55
+ "tsup": "^8.5.1",
56
+ "typescript": "^5.9.3",
57
+ "vitest": "^4.0.18"
58
+ },
59
+ "packageManager": "pnpm@10.26.0+sha512.3b3f6c725ebe712506c0ab1ad4133cf86b1f4b687effce62a9b38b4d72e3954242e643190fc51fa1642949c735f403debd44f5cb0edd657abe63a8b6a7e1e402"
60
+ }