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 3.3.3 to 3.4.0

test/add.test.js

8

lib/check.js

@@ -154,4 +154,4 @@ const BlorkError = require("./BlorkError");

function checkArray(value, type, name, instanceError, instanceCheckers, typeStack, valueStack) {
// Value must be an array.
if (!(value instanceof Array)) throw new instanceError(format("Must be an array", value, name));
// Value must be an array (reuse the checker logic too.
checkInternal(value, "array", name, instanceError, instanceCheckers, typeStack, valueStack);

@@ -231,4 +231,4 @@ // Prevent infinite loops.

function checkObject(value, type, name, instanceError, instanceCheckers, typeStack, valueStack) {
// Value must be an object.
if (!(value instanceof Object)) throw new instanceError(format("Must be an object", value, name));
// Value must be an object (reuse the checker logic too.
checkInternal(value, "object", name, instanceError, instanceCheckers, typeStack, valueStack);

@@ -235,0 +235,0 @@ // Prevent infinite loops.

@@ -40,3 +40,3 @@ // Primatives.

// Functions.
exports["function"] = exports["func"] = v => v instanceof Function || "Must be a function";
exports["function"] = exports["func"] = v => typeof v === "function" || "Must be a function";

@@ -48,5 +48,5 @@ // Objects.

"Must be a plain object with one or more enumerable properties";
exports["objectlike"] = v => v instanceof Object || "Must be an object";
exports["objectlike"] = v => (typeof v === "object" && v !== null) || "Must be an object";
exports["iterable"] = v =>
(v instanceof Object && typeof v[Symbol.iterator] === "function") || "Must be an iterable object";
(typeof v === "object" && typeof v[Symbol.iterator] === "function") || "Must be an iterable object";

@@ -58,3 +58,4 @@ // Arrays.

exports["arraylike"] = exports["arguments"] = exports["args"] = v =>
(v instanceof Object &&
(typeof v === "object" &&
v !== null &&
v.hasOwnProperty("length") &&

@@ -61,0 +62,0 @@ typeof v.length === "number" &&

@@ -38,6 +38,8 @@ // Constants.

else if (typeof value === "string") return debugString(value);
else if (value instanceof Function) return debugFunction(value);
else if (value instanceof Error) return debugError(value);
else if (value instanceof Object) {
if (value.constructor === Date) {
else if (typeof value === "function") return debugFunction(value);
else if (typeof value === "object") {
if (value instanceof Error) {
// Error, e.g. TypeError "What went wrong"
return debugError(value);
} else if (value.constructor === Date) {
// Date, e.g. 2011-10-05T14:48:00.000Z

@@ -86,3 +88,3 @@ return value.toISOString();

? `${value.constructor.name} `
: "anonymous ";
: "anonymous object ";

@@ -143,3 +145,3 @@ // Empty object, e.g. {}

// Unnamed function, e.g. function()
return "function()";
return "anonymous function()";
}

@@ -151,3 +153,6 @@ }

// Error, e.g. TypeError "Must be a string"
return `${value.constructor.name} ${debugString(value.message)}`;
const name = value.name || value.constructor.name;
const message = value.message;
if (message) return `${name} ${debugString(value.message)}`;
else return name;
}

@@ -154,0 +159,0 @@

{
"name": "blork",
"description": "Blork! Mini runtime type checking in Javascript",
"version": "3.3.3",
"version": "3.4.0",
"license": "0BSD",

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

@@ -70,3 +70,3 @@ const { debug } = require("../lib/exports");

test("Return correct debug string for functions", () => {
expect(debug(function() {})).toBe("function()");
expect(debug(function() {})).toBe("anonymous function()");
expect(debug(function dog() {})).toBe("dog()");

@@ -76,3 +76,3 @@ });

expect(debug(new class MyClass {}())).toBe("MyClass {}");
expect(debug(new class {}())).toBe("anonymous {}");
expect(debug(new class {}())).toBe("anonymous object {}");
});

@@ -82,2 +82,10 @@ test("Return correct debug string for errors", () => {

expect(debug(new TypeError("My error message"))).toBe('TypeError "My error message"');
class MyError extends Error {}
MyError.prototype.name = "MyError";
expect(debug(new MyError())).toBe("MyError");
expect(debug(new MyError("My error message"))).toBe('MyError "My error message"');
class AnonymousError extends Error {}
AnonymousError.prototype.name = "";
expect(debug(new AnonymousError())).toBe("AnonymousError");
expect(debug(new AnonymousError("My error message"))).toBe('AnonymousError "My error message"');
});

@@ -110,2 +118,7 @@ test("Return correct debug string for symbols", () => {

});
test("Return correct debug for arguments objects", () => {
(function() {
expect(debug(arguments)).toBe('{ "0": "abc", "1": 123, "2": true }');
})("abc", 123, 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