Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jeroenpeeters/assert-errors

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jeroenpeeters/assert-errors - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

7

CHANGELOG.md
# Changelog
## [1.0.2](https://github.com/jeroenptrs/assert-errors/compare/v1.0.1...v1.0.2) (2023-08-29)
### Bug Fixes
* bundle and only build esm ([fd119c1](https://github.com/jeroenptrs/assert-errors/commit/fd119c1554de3b6df20c7ebf166084310262a9d5))
## [1.0.1](https://github.com/jeroenptrs/assert-errors/compare/v1.0.0...v1.0.1) (2023-08-29)

@@ -4,0 +11,0 @@

57

dist/index.d.ts

@@ -1,8 +0,57 @@

export { E as ErrorClass } from "./utilTypes-5f4d643d.js";
export { assertErrors, assertErrorsCurry, assertErrorsOnce } from "./assertErrorsSync.js";
import { Class } from "type-fest/source/basic";
type Args = unknown[];
type AssertErrorReturnType<ExpectedError extends ErrorClass, Result> =
| readonly [Result, undefined]
| readonly [undefined, ExpectedError];
type ErrorClass = Class<Error>;
type AssertErrors = <ExpectedError extends ErrorClass, Result, Arguments extends Args>(
expectedErrors: ExpectedError | Array<ExpectedError>,
f: (...args: Arguments) => Result
) => (...args: Arguments) => AssertErrorReturnType<ExpectedError, Result>;
declare const assertErrors: AssertErrors;
type AssertErrorsCurry = <ExpectedError extends ErrorClass>(
expectedErrors: ExpectedError | Array<ExpectedError>
) => <Result, Arguments extends Args>(
f: (...args: Arguments) => Result
) => (...args: Arguments) => AssertErrorReturnType<ExpectedError, Result>;
declare const assertErrorsCurry: AssertErrorsCurry;
type AssertErrorsOnce = <ExpectedError extends ErrorClass, Result, Arguments extends unknown[]>(
expectedError: ExpectedError,
f: (...args: Arguments) => Result,
...args: Arguments
) => AssertErrorReturnType<ExpectedError, Result>;
declare const assertErrorsOnce: AssertErrorsOnce;
type AssertErrorsAsync = <ExpectedError extends ErrorClass, Result, Arguments extends Args>(
expectedErrors: ExpectedError | Array<ExpectedError>,
f: (...args: Arguments) => Promise<Result>
) => (...args: Arguments) => Promise<AssertErrorReturnType<ExpectedError, Result>>;
declare const assertErrorsAsync: AssertErrorsAsync;
type AssertErrorsCurryAsync = <ExpectedError extends ErrorClass>(
expectedErrors: ExpectedError | Array<ExpectedError>
) => <Result, Arguments extends Args>(
f: (...args: Arguments) => Promise<Result>
) => (...args: Arguments) => Promise<AssertErrorReturnType<ExpectedError, Result>>;
declare const assertErrorsCurryAsync: AssertErrorsCurryAsync;
type AssertErrorsOnceAsync = <
ExpectedError extends ErrorClass,
Result,
Arguments extends unknown[],
>(
expectedError: ExpectedError,
f: (...args: Arguments) => Promise<Result>,
...args: Arguments
) => Promise<AssertErrorReturnType<ExpectedError, Result>>;
declare const assertErrorsOnceAsync: AssertErrorsOnceAsync;
export {
ErrorClass,
assertErrors,
assertErrorsAsync,
assertErrorsCurry,
assertErrorsCurryAsync,
assertErrorsOnce,
assertErrorsOnceAsync,
} from "./assertErrorsAsync.js";
import "type-fest/source/basic";
};

@@ -1,7 +0,62 @@

import { assertErrors, assertErrorsCurry, assertErrorsOnce } from "./assertErrorsSync";
import {
assertErrorsAsync,
assertErrorsCurryAsync,
assertErrorsOnceAsync,
} from "./assertErrorsAsync";
// src/UnknownError.ts
var UnknownError = class extends Error {
constructor(originalError) {
super("An unknown error has been detected, find it in error.originalError");
this.originalError = originalError;
const actualProto = new.target.prototype;
if (Object.setPrototypeOf) {
Object.setPrototypeOf(this, actualProto);
} else {
this.__proto__ = actualProto;
}
}
};
// src/isExpectedError.ts
function isExpectedError(expectedError, error) {
return error instanceof expectedError;
}
// src/returnIfMatchedError.ts
function returnIfMatchedError(expectedErrors, e) {
if (Array.isArray(expectedErrors)) {
for (const expectedError of expectedErrors) {
if (isExpectedError(expectedError, e)) {
return [void 0, e];
}
}
} else if (isExpectedError(expectedErrors, e)) {
return [void 0, e];
}
throw new UnknownError(e);
}
// src/assertErrorsSync.ts
var assertErrors =
(expectedErrors, f) =>
(...args) => {
try {
const result = f(...args);
return [result, void 0];
} catch (e) {
return returnIfMatchedError(expectedErrors, e);
}
};
var assertErrorsCurry = (expectedError) => (f) => assertErrors(expectedError, f);
var assertErrorsOnce = (expectedError, f, ...args) => assertErrors(expectedError, f)(...args);
// src/assertErrorsAsync.ts
var assertErrorsAsync =
(expectedErrors, f) =>
async (...args) => {
try {
const result = await f(...args);
return [result, void 0];
} catch (e) {
return returnIfMatchedError(expectedErrors, e);
}
};
var assertErrorsCurryAsync = (expectedError) => (f) => assertErrorsAsync(expectedError, f);
var assertErrorsOnceAsync = (expectedError, f, ...args) =>
assertErrorsAsync(expectedError, f)(...args);
export {

@@ -8,0 +63,0 @@ assertErrors,

6

package.json
{
"name": "@jeroenpeeters/assert-errors",
"version": "1.0.1",
"version": "1.0.2",
"private": false,

@@ -8,3 +8,3 @@ "type": "module",

"repository": "jeroenptrs/assert-errors",
"main": "dist/index.cjs",
"main": "dist/index.js",
"module": "dist/index.js",

@@ -30,3 +30,3 @@ "types": "dist/index.d.ts",

"lint": "tsc --noEmit && eslint . --fix",
"lint:dist": "eslint dist --fix \"dist/**.{cjs, js, ts}\"",
"lint:dist": "eslint dist --fix \"dist/**.{js, ts}\"",
"test": "jest",

@@ -33,0 +33,0 @@ "test:code": "jest",

import { type Options } from "tsup";
// Set true if needed for library
const splitting = true;
const splitting = false;
export const tsup: Options = {
format: ["cjs", "esm"],
format: ["esm"],
splitting,
bundle: false,
bundle: true,
entry: splitting ? ["src/**/*[^.test].ts"] : ["src/index.ts"],

@@ -11,0 +11,0 @@ clean: true,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc