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 9.2.0 to 9.2.1

4

lib/errors/ValueError.js

@@ -31,4 +31,4 @@ const debug = require("../helpers/debug");

// Pin down the cause of the error.
// This looks through the Error.stack and finds where e.g. check() or args() was actually called.
const frame = stackTrigger(this.stack, "blork$");
// This looks through the Error.stack and finds where e.g. check() was actually called.
const frame = stackTrigger(this.stack, ["check()"]);

@@ -35,0 +35,0 @@ // If there was an error causing function prepend it to the message.

@@ -10,3 +10,3 @@ // List of function and file names we blank out (for consistency).

{
match: /^ +at (?:([^(\r\n]+) \(([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?\)|([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)$/gm,
match: /^ +at (?:(?:Object\.)?([^(\r\n]+) \(([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?\)|([^:\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)$/gm,
each(matches) {

@@ -38,3 +38,3 @@ // Was function named?

{
match: /^([^@\r\n]*)(?:@([^\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)?$/gm,
match: /^(?:Object\.)?([^@\r\n]*)(?:@([^\r\n]+?)(?::([0-9]+))?(?::([0-9]+))?)?$/gm,
each(matches) {

@@ -41,0 +41,0 @@ return {

@@ -13,8 +13,8 @@ const destack = require("./destack");

* @param {string} stack A stack string as generated by `new Error()` — unfortunately different browsers use different formats.
* @param {string} needle The needle to look for in function names that indicates the triggering error of the stack. Has to be something unique like "blorker$"
* @returns {array} An array like `[functionName, file, line]` that represents the file/line/call that caused this error, or undefined if it can't be found.
* @param {string[]} ignore Functions to ignore at the top of the stack. The first frame of the stack with a named function not in this list is the 'trigger'. Functions need to be formatted with a pair of parens like `myFunc()`
* @returns {Array} An array like `[functionName, file, line]` that represents the file/line/call that caused this error, or undefined if it can't be found.
*
* @internal
*/
function stackTrigger(stack, needle) {
function stackTrigger(stack, ignore) {
// Parse the stack into its constituent rows.

@@ -31,4 +31,4 @@ const frames = destack(stack);

for (let i = 0; i < frames.length; i++) {
// Does the function name include needle
if (frames[i].function.indexOf(needle) >= 0) {
// Is the function named needle?
if (ignore.indexOf(frames[i].function) >= 0) {
// Return the next named function.

@@ -35,0 +35,0 @@ returnNextNamed = true;

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

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

@@ -10,9 +10,9 @@ const BlorkError = require("../../lib/errors/BlorkError");

test("Return correct error with message only", () => {
expect(new BlorkError("Message")).toHaveProperty("message", "Object.test(): Message");
expect(new BlorkError("Message")).toHaveProperty("message", "test(): Message");
expect(new BlorkError("Message")).not.toHaveProperty("value");
});
test("Return correct error with message and value", () => {
expect(new BlorkError("Message", 123)).toHaveProperty("message", "Object.test(): Message (received 123)");
expect(new BlorkError("Message", 123)).toHaveProperty("message", "test(): Message (received 123)");
expect(new BlorkError("Message", 123)).toHaveProperty("value", 123);
});
});

@@ -50,3 +50,3 @@ const destack = require("../../lib/helpers/destack");

" at abc (<anonymous>:1:30)",
" at def (<anonymous>:1:18)",
" at Object.def (<anonymous>:1:18)",
" at GHI.ghi (<anonymous>:2:9)",

@@ -59,3 +59,3 @@ " at <anonymous>:1:3",

{ function: "abc()", file: "", line: 1, column: 30, original: " at abc (<anonymous>:1:30)" },
{ function: "def()", file: "", line: 1, column: 18, original: " at def (<anonymous>:1:18)" },
{ function: "def()", file: "", line: 1, column: 18, original: " at Object.def (<anonymous>:1:18)" },
{ function: "GHI.ghi()", file: "", line: 2, column: 9, original: " at GHI.ghi (<anonymous>:2:9)" },

@@ -79,3 +79,3 @@ { function: "", file: "", line: 1, column: 3, original: " at <anonymous>:1:3" },

{
function: "Object.test()",
function: "test()",
file: "/blork/test/functions/destack.test.js",

@@ -87,3 +87,3 @@ line: 21,

{
function: "Object.asyncFn()",
function: "asyncFn()",
file: "/jest-jasmine2/build/jasmine_async.js",

@@ -161,2 +161,11 @@ line: 129,

]);
expect(destack("Object.a@file:///C:/example.html:19")).toEqual([
{
function: "a()",
file: "file:///C:/example.html",
line: 19,
column: null,
original: "Object.a@file:///C:/example.html:19"
}
]);
expect(destack("@debugger eval code:21:9")).toEqual([

@@ -163,0 +172,0 @@ { function: "", file: "", line: 21, column: 9, original: "@debugger eval code:21:9" }

@@ -10,6 +10,3 @@ const stackTrigger = require("../../lib/helpers/stackTrigger");

"ValueError: Must be finite string (received 123)",
" at throwError (classes/Blorker.js:41:83)",
" at runChecker (classes/Blorker.js:21:77)",
" at Blorker._check (classes/Blorker.js:261:109)",
" at blorker$check (classes/Blorker.js:118:31)",
" at check (classes/Blorker.js:118:31)",
" at MyClass.name (MyClass.js:8:4)",

@@ -20,3 +17,3 @@ " at myFunc (helpers/myFunc.js:129:432)"

// Get the stackTrigger stack frame from the frames.
const c = stackTrigger(stack.join("\n"), "blorker$");
const c = stackTrigger(stack.join("\n"), ["check()"]);
expect(c.function).toBe("MyClass.name()");

@@ -39,6 +36,3 @@ expect(c.file).toBe("MyClass.js");

"ValueError: Must be finite string (received 123)",
" at throwError (classes/Blorker.js:41:83)",
" at runChecker (classes/Blorker.js:21:77)",
" at Blorker._check (classes/Blorker.js:261:109)",
" at blorker$check (classes/Blorker.js:118:31)",
" at check (classes/Blorker.js:118:31)",
" at <anonymous>:1:3", // Anonymous.

@@ -52,3 +46,3 @@ " at <anonymous>:1", // Anonymous.

// Get the stackTrigger stack frame from the frames.
const c = stackTrigger(stack.join("\n"), "blorker$");
const c = stackTrigger(stack.join("\n"), ["check()"]);
expect(c.function).toBe("MyClass.name()");

@@ -67,3 +61,3 @@ expect(c.file).toBe("MyClass.js");

});
test("First frame is returned if no Blorker call is in the stack", () => {
test("First frame if no ignore functions are found in stack", () => {
// Full stack from a random Blork error.

@@ -83,4 +77,4 @@ const stack = [

// Get the stackTrigger stack frame from the frames.
const c = stackTrigger(stack.join("\n"), "blorker$");
expect(c.function).toBe("Object.test()");
const c = stackTrigger(stack.join("\n"), ["notInStack()"]);
expect(c.function).toBe("test()");
expect(c.file).toBe("functions/stackTrigger.test.js");

@@ -97,6 +91,3 @@ expect(c.line).toBe(8);

const stack = [
"throwError@classes/Blorker.js:41:83",
"runChecker@classes/Blorker.js:21:77",
"Blorker._check@classes/Blorker.js:261:109",
"blorker$check@classes/Blorker.js:118:31",
"check@classes/Blorker.js:118:31",
"MyClass.name@MyClass.js:8:4",

@@ -107,3 +98,3 @@ "myFunc@helpers/myFunc.js:129:432"

// Get the stackTrigger stack frame from the frames.
const c = stackTrigger(stack.join("\n"), "blorker$");
const c = stackTrigger(stack.join("\n"), ["check()"]);
expect(c.function).toBe("MyClass.name()");

@@ -119,6 +110,3 @@ expect(c.file).toBe("MyClass.js");

const stack = [
"throwError@classes/Blorker.js:41:83",
"runChecker@classes/Blorker.js:21:77",
"Blorker._check@classes/Blorker.js:261:109",
"blorker$check@classes/Blorker.js:118:31",
"check@classes/Blorker.js:118:31",
"@file:///C:/example.html:16:13", // Anonymous.

@@ -131,3 +119,3 @@ "@debugger eval code:21:9", // Anonymous.

// Get the stackTrigger stack frame from the frames.
const c = stackTrigger(stack.join("\n"), "blorker$");
const c = stackTrigger(stack.join("\n"), ["check()"]);
expect(c.function).toBe("MyClass.name()");

@@ -134,0 +122,0 @@ expect(c.file).toBe("MyClass.js");

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