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

get-spot

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-spot - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

2

dist/index.min.js

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

function e(e=1){let t=(new Error).stack;return(e=Math.max(e,1))!=e&&(e=1),t=function(e){const t=(e||"").split("\n");return t.map((e=>{let t,a,l,r=[];if((a=(e=e.trim()).match(/at (.+) \(eval at .+ \((.+)\), .+\)/))||(a=e.match(/at (.+) \((.+)\)/))||"at "!==e.slice(0,3)&&(a=e.match(/(.*)@(.*)/)))t=a[1],r=(a[2].match(/(.*):(\d+):(\d+)/)||a[2].match(/(.*):(\d+)/)||[]).slice(1);else{if(!(l=e.match(/^(at\s+)*(.+):(\d+):(\d+)/)))return;r=l.slice(2)}return{file:r[0],beforeParse:e,callee:t||"",line:parseInt(r[1]||"",10)||void 0,column:parseInt(r[2]||"",10)||void 0}})).filter((e=>void 0!==e))}(t).slice(e).map((e=>{return t=e,Object.assign(t,{calleeShort:t.calleeShort||(t.callee||"").split(".")[(t.callee||"").split(".").length-1]});var t})),t}export{e as default,e as getSpot};
function e(e=1){return e instanceof Error||e?.message?t([a(e.stack)[0]])[0]:((e=Math.max(e,1))!=e&&(e=1),a((new Error).stack).slice(e).map((e=>t(e))))}function t(e){return Object.assign(e,{calleeShort:e.calleeShort||(e.callee||"").split(".")[(e.callee||"").split(".").length-1]})}function a(e){return e.split("\n").map((e=>{let t,a,l,r=[];if((a=(e=e.trim()).match(/at (.+) \(eval at .+ \((.+)\), .+\)/))||(a=e.match(/at (.+) \((.+)\)/))||"at "!==e.slice(0,3)&&(a=e.match(/(.*)@(.*)/)))t=a[1],r=(a[2].match(/(.*):(\d+):(\d+)/)||a[2].match(/(.*):(\d+)/)||[]).slice(1);else{if(!(l=e.match(/^(at\s+)*(.+):(\d+):(\d+)/)))return;r=l.slice(2)}return{file:r[0],beforeParse:e,callee:t||"",line:parseInt(r[1]||"",10)||void 0,column:parseInt(r[2]||"",10)||void 0}})).filter((e=>void 0!==e))}export{e as default,e as getSpot};
function getSpot(offset = 1) {
let input = new Error().stack;
if (offset instanceof Error || offset?.message) {
return getErrorSpot(offset);
}
offset = Math.max(offset, 1);
if (offset !== offset) offset = 1;
input = rawParse(input).slice(offset).map(x => extractEntryMetadata(x))
return input;
return rawParse(new Error().stack).slice(offset).map(x => extractEntryMetadata(x));
}
function getErrorSpot(error) {
return extractEntryMetadata([rawParse(error.stack)[0]])[0];
}
function extractEntryMetadata(e) {

@@ -16,6 +21,4 @@ return Object.assign(e, {

function rawParse(str) {
const lines = (str || '').split('\n')
const entries = str.split('\n').map(line => {
const entries = lines.map(line => {
line = line.trim()

@@ -22,0 +25,0 @@

{
"name": "get-spot",
"version": "1.0.2",
"version": "1.1.0",
"description": "Line number, column number, filename",

@@ -19,2 +19,3 @@ "main": "index.js",

"b4a": "^1.6.6",
"bring-your-own-storage-utilities": "^0.0.1331",
"brittle": "^3.4.0",

@@ -21,0 +22,0 @@ "jsdoc-to-markdown": "^8.0.1",

@@ -14,6 +14,15 @@ ## get-spot

## `[...stack] = getSpot(offset = 1)`
---
## Two overloads
## #1 `[...stack] = getSpot(offset = 1)`
`offset`: must be 1 or greater
## #2 `topMostStackItem = getSpot(error)`
`error` An error that is an instance of `Error` or an object with message, i.e. error.message
---
Stack will have the following information

@@ -20,0 +29,0 @@

@@ -1,2 +0,2 @@

import {test} from "brittle";
import {test, solo} from "brittle";
import {getSpot} from "./index.js";

@@ -54,2 +54,11 @@

}
});
});
test("Get spot from actual error", t => {
const e = new Error();
const {line, column, file, callee} = getSpot(e);
t.is(line, 57);
t.is(column, 15);
t.ok(file.endsWith("test.js"));
t.is(callee, "", "");
})
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