Gathering detailed insights and metrics for @brillout/libassert
Gathering detailed insights and metrics for @brillout/libassert
Gathering detailed insights and metrics for @brillout/libassert
Gathering detailed insights and metrics for @brillout/libassert
npm install @brillout/libassert
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
2 Stars
114 Commits
1 Forks
5 Watching
1 Branches
1 Contributors
Updated on 16 Oct 2021
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
5.1%
1,018
Compared to previous day
Last week
33.1%
5,584
Compared to previous week
Last month
15.7%
22,030
Compared to previous month
Last year
201.3%
165,437
Compared to previous year
2
@brillout/libassert
Tiny zero-dependency tool for library authors to create assertion functions with clean strack traces.
Error.stackTraceLimit = Infinity;
only for assertion errors.)1import { newError } from "@brillout/libassert";
2
3export { assert };
4
5function assert(condition: unknown): asserts condition {
6 if (condition) {
7 return;
8 }
9
10 const err = newError(
11 `[${libName}][Internal Error] Something unexpected happened, please open a GitHub issue.`;
12 );
13
14 throw err;
15}
Calling newError(errorMessage)
is the same than new Error(errorMessage)
except that:
errorMessage
is forbidden to contain new lines.You can create all kinds of assertion functions, such as assertUsage
or assertWarning
:
1import { newError } from "@brillout/libassert";
2
3export { assert, assertUsage, assertWarning };
4
5const libName = "My Awesome Library";
6
7// Assertions that are expected to always be true (also known as "invariants")
8function assert(condition: unknown): asserts condition {
9 if (condition) {
10 return;
11 }
12
13 const err = newError(
14 `[${libName}][Internal Error] Something unexpected happened, please open a GitHub issue.`;
15 );
16
17 throw err;
18}
19
20// Wrong usage of your library
21function assertUsage(
22 condition: unknown,
23 errorMessage: string
24): asserts condition {
25 if (condition) {
26 return;
27 }
28
29 const err = newError(prefix: `[${libName}][Wrong Usage] ${errorMessage}`);
30
31 throw err;
32}
33
34// Something unexpected happened but it is non-critical and doesn't
35// warrant interrupting code execution.
36function assertWarning(condition: unknown, errorMessage: string): void {
37 if (condition) {
38 return;
39 }
40
41 const err = newError(`[${libName}][Warning] ${errorMessage}`);
42
43 console.warn(err);
44}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More