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

blork

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blork - npm Package Compare versions

Comparing version 4.4.0 to 4.4.1

test/errors/ValueError.test.js

2

lib/errors/BlorkError.js

@@ -11,6 +11,4 @@ const ValueError = require("./ValueError");

class BlorkError extends ValueError {}
BlorkError.name = "BlorkError";
BlorkError.message = "Incorrect Blork configuration";
// Exports.
module.exports = BlorkError;

@@ -17,14 +17,18 @@ const format = require("../functions/format");

*/
constructor(message, value = format.UNDEF, prefix = format.UNDEF) {
// Save message as normal.
super(format(message, value, prefix));
constructor(message = "Invalid value", value = undefined, prefix = "") {
// Save message through TypeError.
// We format immediately (rather than in toString) because Jest (and presumably others) call .message directly.
super(arguments.length > 1 ? format(message, value, prefix) : message);
// Save value separately.
if (value !== format.UNDEF) this.value = value;
// Save parts separately.
this.prefix = prefix;
this.reason = message;
if (arguments.length > 1) this.value = value;
// Save name as constructor name (e.g. ValueError).
this.name = this.constructor.name;
}
}
ValueError.name = "ValueError";
ValueError.message = "Invalid value";
// Exports.
module.exports = ValueError;
const debug = require("./debug");
// Constants.
const UNDEF = Symbol("UNDEF");
/**

@@ -15,3 +12,3 @@ * Format an error message.

*/
function format(message, value = UNDEF, prefix = UNDEF) {
function format(message, value, prefix) {
// e.g. MyPrefix: Must be string (received 123)

@@ -21,3 +18,3 @@ return (

message +
(value !== UNDEF ? ` (received ${debug(value)})` : "")
(arguments.length > 1 ? ` (received ${debug(value)})` : "")
);

@@ -28,2 +25,1 @@ }

module.exports = format;
module.exports.UNDEF = UNDEF;
{
"name": "blork",
"description": "Blork! Mini runtime type checking in Javascript",
"version": "4.4.0",
"version": "4.4.1",
"license": "0BSD",

@@ -6,0 +6,0 @@ "author": "Dave Houlbrooke <dave@shax.com>",

@@ -5,11 +5,25 @@ const BlorkError = require("../../lib/errors/BlorkError");

describe("BlorkError()", () => {
test("Return correct error with default message", () => {
expect(new BlorkError()).toHaveProperty("message");
expect(new BlorkError()).toHaveProperty("reason");
expect(new BlorkError()).not.toHaveProperty("value");
});
test("Return correct error with message only", () => {
expect(new BlorkError("Message")).toHaveProperty("message", "Message");
expect(new BlorkError("Message")).toHaveProperty("prefix", "");
expect(new BlorkError("Message")).toHaveProperty("reason", "Message");
expect(new BlorkError("Message")).not.toHaveProperty("value");
});
test("Return correct error with message and value", () => {
expect(new BlorkError("Message", 123)).toHaveProperty("message", "Message (received 123)");
expect(new BlorkError("Message", 123)).toHaveProperty("prefix", "");
expect(new BlorkError("Message", 123)).toHaveProperty("reason", "Message");
expect(new BlorkError("Message", 123)).toHaveProperty("value", 123);
});
test("Return correct error with message, value, and prefix", () => {
expect(new BlorkError("Message", 123, "Prefix")).toHaveProperty("message", "Prefix: Message (received 123)");
expect(new BlorkError("Message", 123, "Prefix")).toHaveProperty("prefix", "Prefix");
expect(new BlorkError("Message", 123, "Prefix")).toHaveProperty("reason", "Message");
expect(new BlorkError("Message", 123, "Prefix")).toHaveProperty("value", 123);
});
});
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