Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@samual/assert

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@samual/assert - npm Package Compare versions

Comparing version
0.0.1-655a111
to
0.0.1-adff9aa
+18
-1
default.d.ts

@@ -10,3 +10,3 @@ import type { Falsy, NonFalsy } from "@samual/types";

*/
export declare function assert<T>(value: T, message?: string | MessageFn<T & Falsy>): asserts value is NonFalsy<T>;
export declare function assert<T>(value: T, message?: string | MessageFn<T & Falsy>): asserts value;
/**

@@ -18,2 +18,19 @@ * Assertion function that ensures value is not [nullish](https://developer.mozilla.org/en-US/docs/Glossary/Nullish).

/**
* An alias for {@linkcode assert()} but with a type signature that explicitly narrows with {@linkcode NonFalsy<>}.
*
* This is useful because in this code:
* ```ts
* function foo<T>(value: T) {
* assert(value)
*
* value
* // ^? (parameter) value: NonNullable<T>
* }
* ```
*
* TypeScript incorrectly narrows the type of `value` with `NonNullable<>` when it should be using something like
* {@linkcode NonFalsy<>}.
*/
export declare const assertNonFalsy: <T>(value: T, message?: string | MessageFn<T & Falsy>) => asserts value is NonFalsy<T>;
/**
* Assertion function that ensures value is not [nullish](https://developer.mozilla.org/en-US/docs/Glossary/Nullish).

@@ -20,0 +37,0 @@ * @throws If value is nullish.

+4
-3

@@ -9,3 +9,4 @@ var AssertError = class extends Error {}

}
const expect = (value, message = "Expectation failed") => {
const assertNonFalsy = assert,
expect = (value, message = "Expectation failed") => {
assertNonNull(value, message)

@@ -15,5 +16,5 @@ return value

expectTruthy = (value, message = "Truthy expectation failed") => {
assert(value, message)
assertNonFalsy(value, message)
return value
}
export { AssertError, assert, assertNonNull, expect, expectTruthy }
export { AssertError, assert, assertNonFalsy, assertNonNull, expect, expectTruthy }
{
"name": "@samual/assert",
"version": "0.0.1-655a111",
"description": "Assertion library. ",
"version": "0.0.1-adff9aa",
"description": "Assertion library.",
"keywords": [

@@ -6,0 +6,0 @@ "assertions",

@@ -18,5 +18,5 @@ # Samual's Assertion Library

---
This package is also [available on JSR](jsr).
This package is also [available on JSR][jsr].
[npm]: https://www.npmjs.com/package/@samual
[jsr]: https://jsr.io/@sn