Gathering detailed insights and metrics for @shedevro/assert
Gathering detailed insights and metrics for @shedevro/assert
Gathering detailed insights and metrics for @shedevro/assert
Gathering detailed insights and metrics for @shedevro/assert
npm install @shedevro/assert
Typescript
Module System
Node Version
NPM Version
73.2
Supply Chain
98.9
Quality
77.1
Maintenance
100
Vulnerability
99.6
License
TypeScript (92.23%)
JavaScript (7.77%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
18,654
Last Day
14
Last Week
36
Last Month
331
Last Year
3,470
5 Stars
132 Commits
1 Watching
2 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.3.0
Package Id
@shedevro/assert@1.3.0
Unpacked Size
103.61 kB
Size
15.00 kB
File Count
26
NPM Version
lerna/4.0.0/node@v18.19.1+x64 (linux)
Node Version
18.19.1
Publised On
20 Mar 2024
Cumulative downloads
Total Downloads
Last day
-41.7%
14
Compared to previous day
Last week
-72.1%
36
Compared to previous week
Last month
36.2%
331
Compared to previous month
Last year
-63.8%
3,470
Compared to previous year
1
1
Library provides assertion utility for better and safe coding.
Features:
Right assertion return types:
Assert.someFn(value): asserts value is string
or Assert.is.someFn(value): value is string
etc.
Assert functions can be chained with operators (is
, all
, nullOr
, not
)
throws WebUtilsAssertionError (extends from Error). Provides right stacktrace (especialy helpfull then coding with Angular to see links to .ts files)
1npm i @shedevro/assert --save
First you should import the library
1import { Assert } from '@shedevro/assert';
Each function can be customized with you own error message.
Error message supports params injecting of assert functions arguments like input or expected values etc.
Most often the order of params matches the function arguments order.
For example:
1const someValue = 3; 2Assert.greaterThan(someValue, 10, 'This value should be greater than {2}, but got {1}'); 3// throw error with message 'This value should be greater than 10, but got 3';
Then you can choice needed function.
Almost all functions can be chained with different operators.
Moreover, you can combine them each other.
is
– modifies assert functions to return true
or false
as a resultall
– applies an assert function to a provided arraynullOr
– runs assertion only if input value is definednot
– inverts assertion actionFor example:
1// is 2const someNumber = 10; 3if (Assert.is.range(someNumber, 10, 15)) { 4 ... 5} 6 7 8// all 9class User { 10 id: number; 11 name: string; 12} 13 14const someArray = [new User(), new User]; 15Assert.all.instanceOf(someArray, User); 16 17// ...futher actions 18 19 20// nullOr 21const someBoolean = null; // or undefined 22Assert.nullOr.boolean(someBoolean); 23// ...futher actions 24 25 26// not 27const someFunction = () => 123; 28Assert.not.throws(someFunction, TypeError); 29 30 31// combinations 32Assert.is.nullOr.not.emptyString('some string'); 33Assert.not.endsWith('str', 'some suffix'); 34Assert.nullOr.all.greaterThan([10, 11, 12, 13], 5); 35// ...and so on
Method | Description |
---|---|
string(value, message?: string) | Ensures that value is a string |
emptyString(value, message?: string) | Ensures that value is an empty string |
contains(value, subString: string, message?: string) | Ensures that value contains substring |
startsWith(value, prefix: string, message?: string) | Ensures that value starts with some prefix |
endsWith(value, suffix: string, message?: string) | Ensures that value ends with some suffix |
`oneOf(value, values, message?: string | Ensures that value is one of values (string /number array) |
Method | Description |
---|---|
number(value, message?: string) | Ensures that value is a number |
natural(value, message?: string) | Ensures that value is a natural number |
greaterThan(value, limit: number, message?: string) | Ensures that value is greater than limit |
greaterThanOrEqual(value, limit: number, message?: string) | Ensures that value is greater or equal to limit |
lessThan(value, limit: number, message?: string) | Ensures that value is less than limit |
lessThanOrEqual(value, limit: number, message?: string) | Ensures that value is less or equal to limit |
range(value, min: number, max: number, message?: string) | Ensures that value is in range of min and max |
Method | Description |
---|---|
boolean(value, message?: string) | Ensures that value is a boolean |
true(value, message?: string) | Ensures that value is true |
false(value, message?: string) | Ensures that value is false |
Method | Description |
---|---|
object(value, message?: string) | Ensures that value is an object ({} , not Array or null ) |
Method | Description |
---|---|
function(value, message?: string) | Ensures that value is a function |
Method | Description |
---|---|
array(value, message?: string) | Ensures that value is an array |
arrayLength(value, expectedLength: number, message?: string) | Ensures that array length is equal to number |
arrayMinLength(value, limit: number, message?: string) | Ensures that array length is not less than limit |
arrayMaxLength(value, limit: number, message?: string) | Ensures that array length is not greater than limit |
arrayLengthBetween(value, min: number, max: number, message?: string) | Ensures that array length is inside a min and max |
Method | Description |
---|---|
instanceOf(value, instanceClass, message?: string) | Ensures that value is an instance of some class |
instanceOfAny(value, instanceClasses, message?: string) | Ensures that value is an instance of any class |
Method | Description |
---|---|
match(value, regExp: RegExp, message?: string) | Ensures that value is match a regular expression |
Method | Description |
---|---|
defined(value, message?: string) | Ensures that value is defined (not null , undefined or NaN ) |
equal(value, expect, message?: string) | Ensures that value is equal to expec (value === expect ) |
throws(expression: () => any, errorClass?, message?: string) | Ensures that expression throws some error |
All credits for great idea to @webmozart with his webmozart/assert for PHP!
If you have ideas on how to improve this library, you are welcome!
Please read readme of root project directory.
The content of this package is licensed under the MIT license.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/28 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
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
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
13 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-03
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