Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
http-assert-plus
Advanced tools
Readme
More assertions with status codes.
import assert from 'http-assert-plus';
// or
const assert = require('http-assert-plus');
const username = 'jdrydn';
assert(username === 'not-jdrydn', 403, 'Authorization failed', {
code: 'NOT_AUTHORIZED',
username,
});
// Error: Authorization failed
// at http-assert-plus/README.md:22:1 {
// code: 'NOT_AUTHORIZED',
// statusCode: 403,
// status: 403,
// statusText: 'Forbidden',
// username: 'jdrydn'
// }
$ npm install --save http-assert-plus
This API matches the built-in assert
module, and builds upon the success of http-assert
, with a few differences:
Error
when the assertion fails.assert(value, [status], [message], [props])
Tests if value
is truthy, and throws an Error
if falsey.
assert.ok(value, [status], [message], [props])
Alias for above, tests if value
is truthy, and throws an Error
if falsey.
assert.fail([status], [message], [props])
Always throws an Error
with the provided status/message/props.
assert.equal(a, b, [status], [message], [props])
Tests shallow, coercive equality between a
& b
using ==
.
assert.notEqual(a, b, [status], [message], [props])
Tests shallow, coercive inequality between a
& b
using !=
.
assert.strictEqual(a, b, [status], [message], [props])
Tests strict equality between a
& b
using ===
.
assert.notStrictEqual(a, b, [status], [message], [props])
Tests strict inequality between a
& b
using !==
.
assert.includes(a, b, [status], [message], [props])
Tests whether a
includes b
- where a
has a method call includes
.
assert.notIncludes(a, b, [status], [message], [props])
Tests whether a
does not include b
- where a
has a method includes
.
If you're looking for deep equality checks, check out deep-equal
:
import assert from 'http-assert-plus';
import deepEqual from 'deep-equal';
assert(deepEqual(a, b), 400, 'These two are not entirely equal');
assert(deepEqual(a, b, { strict: true }), 400, 'These two are not entirely equal');
// Error: Array does not strict-equal
// at http-assert-plus/README.md:72:1 {
// statusCode: 400,
// status: 400,
// statusText: 'Bad Request'
// }
Yes! Not all browsers support Error.captureStackTrace
so this library checks if it is present in the current environment - if it isn't available the only behaviour you'll likely want to change is to pre-construct Error
arguments to preserve a proper stack trace, like so:
const { origin } = window.location;
// In browsers, do this:
assert(origin.startsWith('https://'), new Error('Expected origin to start with https://'), { origin });
// Error: Expected origin to start with https://
// at http-assert-plus/README.md:99:39 {
// origin: 'http://localhost:4000',
// }
// Not this
assert(origin.startsWith('https://'), 'Expected origin to start with https://');
// Error: Expected origin to start with https://
// at node_modules/http-assert-plus/index.cjs:56:38 {
// at http-assert-plus/README.md:107:1 {
// origin: 'http://localhost:4000',
// }
If you don't use a construct such as new Error
, when reading stacktraces just ignore the first line as it'll always be the assert
function :wink:
FAQs
More assertions with status codes
The npm package http-assert-plus receives a total of 74 weekly downloads. As such, http-assert-plus popularity was classified as not popular.
We found that http-assert-plus demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.