Socket
Socket
Sign inDemoInstall

defekt

Package Overview
Dependencies
0
Maintainers
5
Versions
49
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.0 to 8.1.0

2

build/lib/defekt.js

@@ -15,3 +15,3 @@ "use strict";

messageOrMetadata :
(_b = (_a = messageOrMetadata.message) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : `${formatErrorMessage_1.formatErrorMessage({ code })}`,
(_b = (_a = messageOrMetadata.message) !== null && _a !== void 0 ? _a : defaultMessage) !== null && _b !== void 0 ? _b : `${(0, formatErrorMessage_1.formatErrorMessage)({ code })}`,
cause: typeof messageOrMetadata === 'string' ? undefined : messageOrMetadata.cause,

@@ -18,0 +18,0 @@ data: typeof messageOrMetadata === 'string' ? undefined : messageOrMetadata.data

@@ -5,4 +5,3 @@ "use strict";

const formatErrorMessage = function ({ code }) {
const almostFormattedErrorMessage = code.
split('').
const almostFormattedErrorMessage = [...code].
map((character, index) => {

@@ -9,0 +8,0 @@ if (index === 0) {

@@ -7,4 +7,4 @@ import { CustomError } from './CustomError';

import { isResult } from './isResult';
import { error, Result, value } from './Result';
export { CustomError, defekt, error, isCustomError, isError, isResult, value };
import { error, Result, ResultDoesNotContainError, value } from './Result';
export { CustomError, defekt, error, isCustomError, isError, isResult, ResultDoesNotContainError, value };
export type { CustomErrorConstructor, Result };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.value = exports.isResult = exports.isError = exports.isCustomError = exports.error = exports.defekt = exports.CustomError = void 0;
exports.value = exports.ResultDoesNotContainError = exports.isResult = exports.isError = exports.isCustomError = exports.error = exports.defekt = exports.CustomError = void 0;
const CustomError_1 = require("./CustomError");

@@ -16,2 +16,3 @@ Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return CustomError_1.CustomError; } });

Object.defineProperty(exports, "error", { enumerable: true, get: function () { return Result_1.error; } });
Object.defineProperty(exports, "ResultDoesNotContainError", { enumerable: true, get: function () { return Result_1.ResultDoesNotContainError; } });
Object.defineProperty(exports, "value", { enumerable: true, get: function () { return Result_1.value; } });

@@ -7,3 +7,3 @@ "use strict";

const isCustomError = function (ex, errorType) {
return (isError_1.isError(ex) &&
return ((0, isError_1.isError)(ex) &&
ex instanceof CustomError_1.CustomError &&

@@ -10,0 +10,0 @@ (errorType === undefined || (ex.code === errorType.code)));

@@ -6,3 +6,3 @@ "use strict";

return typeof value === 'object' && value !== null &&
Object.keys(value).length === 6 &&
Object.keys(value).length === 7 &&
('error' in value || 'value' in value) &&

@@ -13,4 +13,5 @@ 'hasError' in value && typeof value.hasError === 'function' &&

'unwrapOrElse' in value && typeof value.unwrapOrElse === 'function' &&
'unwrapOrDefault' in value && typeof value.unwrapOrDefault === 'function';
'unwrapOrDefault' in value && typeof value.unwrapOrDefault === 'function' &&
'unwrapErrorOrThrow' in value && typeof value.unwrapErrorOrThrow === 'function';
};
exports.isResult = isResult;

@@ -0,1 +1,4 @@

declare const ResultDoesNotContainError_base: import("./CustomErrorConstructor").CustomErrorConstructor<"ResultDoesNotContainError">;
declare class ResultDoesNotContainError extends ResultDoesNotContainError_base {
}
interface ResultBase<TValue, TError extends Error> {

@@ -7,2 +10,3 @@ hasError: () => this is ResultError<TValue, TError>;

unwrapOrDefault: (defaultValue: TValue) => TValue;
unwrapErrorOrThrow: () => TError;
}

@@ -22,2 +26,2 @@ interface ResultError<TValue, TError extends Error> extends ResultBase<TValue, TError> {

export type { ResultValue, ResultError, Result };
export { value, error };
export { ResultDoesNotContainError, value, error };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.error = exports.value = void 0;
exports.error = exports.value = exports.ResultDoesNotContainError = void 0;
const defekt_1 = require("./defekt");
class ResultDoesNotContainError extends (0, defekt_1.defekt)({ code: 'ResultDoesNotContainError' }) {
}
exports.ResultDoesNotContainError = ResultDoesNotContainError;
const error = function (err) {

@@ -25,2 +29,5 @@ return {

},
unwrapErrorOrThrow() {
return err;
},
error: err

@@ -47,2 +54,5 @@ };

},
unwrapErrorOrThrow() {
throw new ResultDoesNotContainError();
},
value: val

@@ -49,0 +59,0 @@ };

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

# [8.1.0](https://github.com/thenativeweb/defekt/compare/8.0.0...8.1.0) (2022-01-17)
### Features
* Add `unwrapErrorOrThrow`. ([#350](https://github.com/thenativeweb/defekt/issues/350)) ([8e0cafd](https://github.com/thenativeweb/defekt/commit/8e0cafd43ce34d0a861f31d8226b0d59f7581833)), closes [#349](https://github.com/thenativeweb/defekt/issues/349)
# [8.0.0](https://github.com/thenativeweb/defekt/compare/7.3.3...8.0.0) (2021-08-24)

@@ -2,0 +9,0 @@

const formatErrorMessage = function ({ code }: {
code: string;
}): string {
const almostFormattedErrorMessage = code.
split('').
const almostFormattedErrorMessage = [ ...code ].
map((character: string, index: number): string => {

@@ -7,0 +6,0 @@ if (index === 0) {

@@ -7,3 +7,3 @@ import { CustomError } from './CustomError';

import { isResult } from './isResult';
import { error, Result, value } from './Result';
import { error, Result, ResultDoesNotContainError, value } from './Result';

@@ -17,2 +17,3 @@ export {

isResult,
ResultDoesNotContainError,
value

@@ -19,0 +20,0 @@ };

@@ -5,3 +5,3 @@ import { Result } from './Result';

return typeof value === 'object' && value !== null &&
Object.keys(value).length === 6 &&
Object.keys(value).length === 7 &&
('error' in value || 'value' in value) &&

@@ -12,3 +12,4 @@ 'hasError' in value && typeof value.hasError === 'function' &&

'unwrapOrElse' in value && typeof value.unwrapOrElse === 'function' &&
'unwrapOrDefault' in value && typeof value.unwrapOrDefault === 'function';
'unwrapOrDefault' in value && typeof value.unwrapOrDefault === 'function' &&
'unwrapErrorOrThrow' in value && typeof value.unwrapErrorOrThrow === 'function';
};

@@ -15,0 +16,0 @@

@@ -0,1 +1,5 @@

import { defekt } from './defekt';
class ResultDoesNotContainError extends defekt({ code: 'ResultDoesNotContainError' }) {}
interface ResultBase<TValue, TError extends Error> {

@@ -8,2 +12,4 @@ hasError: () => this is ResultError<TValue, TError>;

unwrapOrDefault: (defaultValue: TValue) => TValue;
unwrapErrorOrThrow: () => TError;
}

@@ -36,2 +42,5 @@

},
unwrapErrorOrThrow (): TError {
return err;
},
error: err

@@ -65,2 +74,5 @@ };

},
unwrapErrorOrThrow (): TError {
throw new ResultDoesNotContainError();
},
value: val

@@ -79,4 +91,6 @@ };

export {
ResultDoesNotContainError,
value,
error
};
{
"name": "defekt",
"version": "8.0.0",
"version": "8.1.0",
"description": "defekt is custom errors made simple.",

@@ -36,4 +36,4 @@ "contributors": [

"devDependencies": {
"assertthat": "6.3.13",
"roboter": "12.1.2",
"assertthat": "6.3.14",
"roboter": "12.6.1",
"semantic-release-configuration": "2.0.5"

@@ -40,0 +40,0 @@ },

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc