Socket
Socket
Sign inDemoInstall

@visulima/error

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@visulima/error - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

dist/chunk-26F4MLO2.js

7

CHANGELOG.md

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

## @visulima/error [1.1.0](https://github.com/visulima/visulima/compare/@visulima/error@1.0.2...@visulima/error@1.1.0) (2023-11-30)
### Features
* added a stacktrace parser and a sourcemap loader ([#250](https://github.com/visulima/visulima/issues/250)) ([4543e44](https://github.com/visulima/visulima/commit/4543e44becc85a54cdbe7701e2c3e6601b282985))
## @visulima/error [1.0.2](https://github.com/visulima/visulima/compare/@visulima/error@1.0.1...@visulima/error@1.0.2) (2023-11-30)

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

57

dist/index.d.ts

@@ -1,53 +0,10 @@

interface ErrorProperties {
hint?: string;
location?: ErrorLocation;
message?: string;
name: string;
stack?: string;
title?: string;
}
interface ErrorLocation {
column?: number;
file?: string;
line?: number;
}
interface ErrorWithMetadata<Type = NonNullable<unknown> & string> {
[name: string]: any;
cause?: any;
frame?: string;
fullCode?: string;
hint?: string;
id?: string;
loc?: {
column?: number;
file?: string;
line?: number;
};
message: string;
name: string;
stack: string;
title?: string;
type?: Type | "VisulimaError";
}
type CodeFrameOptions = {
focusLineColor?: (value: string) => string;
linesAbove?: number;
linesBelow?: number;
};
import { E as ErrorLocation, C as CodeFrameOptions } from './types-e15294e6.js';
export { a as ErrorProperties, b as ErrorWithMetadata, T as Trace } from './types-e15294e6.js';
export { VisulimaError, isVisulimaError } from './error.js';
export { loadSourceMap } from './sourcemap.js';
export { TraceMap, generatedPositionFor, originalPositionFor, sourceContentFor, traceSegment } from '@jridgewell/trace-mapping';
export { parseStacktrace } from './stacktrace.js';
declare const codeFrame: (source: string, loc: ErrorLocation, options?: CodeFrameOptions) => string;
declare const isVisulimaError: (error: unknown) => error is VisulimaError;
declare class VisulimaError extends Error {
loc: ErrorLocation | undefined;
title: string | undefined;
hint: string[] | string | undefined;
type: string;
constructor(properties: ErrorProperties, ...parameters: any);
setLocation(location: ErrorLocation): void;
setName(name: string): void;
setMessage(message: string): void;
setHint(hint: string[] | string): void;
}
declare const positionAt: (offset: number, text: string) => {

@@ -58,2 +15,2 @@ column: number;

export { CodeFrameOptions, ErrorLocation, ErrorProperties, ErrorWithMetadata, VisulimaError, codeFrame, isVisulimaError, positionAt };
export { CodeFrameOptions, ErrorLocation, codeFrame, positionAt };

@@ -0,13 +1,17 @@

export { b as VisulimaError, a as isVisulimaError } from './chunk-X3TE67TZ.js';
export { a as parseStacktrace } from './chunk-26F4MLO2.js';
export { b as generatedPositionFor, a as loadSourceMap, c as originalPositionFor, d as sourceContentFor, e as traceSegment } from './chunk-F52HEHA7.js';
import './chunk-7Q3PPTBP.js';
import { platform, env } from 'process';
var E=Object.defineProperty;var b=(r,n,t)=>n in r?E(r,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[n]=t;var u=(r,n,t)=>(b(r,typeof n!="symbol"?n+"":n,t),t);var L=r=>{let n=[],t=!0;for(let i=0;i<r.length;i++){t&&(n.push(i),t=!1);let o=r.charAt(i);t=o==="\r"||o===`
`,o==="\r"&&i+1<r.length&&r.charAt(i+1)===`
`&&i++;}return t&&r.length>0&&n.push(r.length),n},g=r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
`),y=(r,n)=>{let t=L(n);r=Math.max(0,Math.min(n.length,r));let i=0,o=t.length;if(o===0)return {column:r,line:0};for(;i<=o;){let s=Math.floor((i+o)/2),c=t[s];if(c===r)return {column:0,line:s};r>c?i=s+1:o=s-1;}let a=i-1;return {column:r-t[a],line:a}};var d=platform==="win32"&&!env.WT_SESSION?">":"\u276F",O=(r,n,t)=>{if(n.line===void 0||n.column===void 0)return "";let i={focusLineColor:e=>e,linesAbove:2,linesBelow:3,...t},o=g(r).split(`
`).map(e=>e.replaceAll(" "," ")),a=[];for(let e=-(i.linesAbove+1);e<=i.linesBelow;e++)o[n.line+e]&&a.push(n.line+e);let s=0;a.forEach(e=>{let l=`${d} ${e}${e<9?" ":""}`;l.length>s&&(s=l.length);});let c="";return a.forEach(e=>{let l="",m=e===n.line-1;l+=m?`${d} `:" ",l+=`${e<9?" ":""}${e+1} | ${o[e]}
`,m&&(l+=`${Array.from({length:s}).join(" ")} | ${Array.from({length:n.column}).join(" ")}^`),c+=m?`${i.focusLineColor(l)}
`:l;}),c},v=O;var F=r=>r instanceof Error&&r.type==="VisulimaError",f=class extends Error{constructor(t,...i){super(...i);u(this,"loc");u(this,"title");u(this,"hint");u(this,"type","VisulimaError");let{hint:o,location:a,message:s,name:c,stack:e,title:l}=t;this.title=l,this.name=c,s&&(this.message=s),this.stack=e??this.stack,this.loc=a,this.hint=o,Error.captureStackTrace(this,this.constructor);}setLocation(t){this.loc=t;}setName(t){this.name=t;}setMessage(t){this.message=t;}setHint(t){this.hint=t;}};
var O=r=>{let o=[],i=!0;for(let e=0;e<r.length;e++){i&&(o.push(e),i=!1);let t=r.charAt(e);i=t==="\r"||t===`
`,t==="\r"&&e+1<r.length&&r.charAt(e+1)===`
`&&e++;}return i&&r.length>0&&o.push(r.length),o},f=r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
`),S=(r,o)=>{let i=O(o);r=Math.max(0,Math.min(o.length,r));let e=0,t=i.length;if(t===0)return {column:r,line:0};for(;e<=t;){let s=Math.floor((e+t)/2),m=i[s];if(m===r)return {column:0,line:s};r>m?e=s+1:t=s-1;}let a=e-1;return {column:r-i[a],line:a}};var h=platform==="win32"&&!env.WT_SESSION?">":"\u276F",y=(r,o,i)=>{if(o.line===void 0||o.column===void 0)return "";let e={focusLineColor:n=>n,linesAbove:2,linesBelow:3,...i},t=f(r).split(`
`).map(n=>n.replaceAll(" "," ")),a=[];for(let n=-(e.linesAbove+1);n<=e.linesBelow;n++)t[o.line+n]&&a.push(o.line+n);let s=0;a.forEach(n=>{let l=`${h} ${n}${n<9?" ":""}`;l.length>s&&(s=l.length);});let m="";return a.forEach(n=>{let l="",c=n===o.line-1;l+=c?`${h} `:" ",l+=`${n<9?" ":""}${n+1} | ${t[n]}
`,c&&(l+=`${Array.from({length:s}).join(" ")} | ${Array.from({length:o.column}).join(" ")}^`),m+=c?`${e.focusLineColor(l)}
`:l;}),m},C=y;
export { f as VisulimaError, v as codeFrame, F as isVisulimaError, y as positionAt };
export { C as codeFrame, S as positionAt };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.js.map
{
"name": "@visulima/error",
"version": "1.0.2",
"description": "Error with more than just a message.",
"version": "1.1.0",
"description": "Error with more than just a message, stacktrace parsing and sourcemap loading.",
"keywords": [

@@ -11,3 +11,10 @@ "visulima",

"code-frame",
"codeframe"
"codeframe",
"stack",
"stacktrace",
"stack-trace",
"trace",
"source-map",
"parser",
"v8"
],

@@ -44,5 +51,22 @@ "homepage": "https://www.visulima.com/docs/package/error",

},
"./error": {
"import": {
"types": "./dist/error.d.ts",
"default": "./dist/error.js"
}
},
"./sourcemap": {
"import": {
"types": "./dist/sourcemap.d.ts",
"default": "./dist/sourcemap.js"
}
},
"./stacktrace": {
"import": {
"types": "./dist/stacktrace.d.ts",
"default": "./dist/stacktrace.js"
}
},
"./package.json": "./package.json"
},
"source": "src/index.ts",
"types": "dist/index.d.ts",

@@ -70,2 +94,5 @@ "files": [

},
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.20"
},
"devDependencies": {

@@ -75,3 +102,3 @@ "@anolilab/eslint-config": "^15.0.2",

"@anolilab/semantic-release-preset": "^8.0.2",
"@babel/core": "^7.23.3",
"@babel/core": "^7.23.5",
"@eslint-types/deprecation": "^2.0.0",

@@ -123,3 +150,9 @@ "@eslint-types/import": "^2.29.0",

}
}
},
"sources": [
"src/index.ts",
"src/error.ts",
"src/stacktrace.ts",
"src/sourcemap.ts"
]
}
<div align="center">
<h3>Visulima error</h3>
<p>
Error with more than just a message.
Error with more than just a message, stacktrace parsing and sourcemap loading.
</p>

@@ -85,2 +85,61 @@ </div>

## Stacktrace
> Browser older than 6 years are not supported.
Currently supported browsers/platforms:
- Firefox
- Chrome
- Webkit / Safari
- Edge
- Node / Node V8
- Opera (Chromium based)
```ts
import { parseStack } from "@visulima/error";
const error = new Error("My error message");
const stack = parseStack(error);
console.log(stack);
// [
// {
// column: 16,
// file: "file:///Users/danielbannert/Projects/visulima/packages/error/src/index.ts",
// line: 2,
// methodName: "Object.<anonymous>",
// raw: " at Object.<anonymous> (/visulima/packages/error/src/index.ts:2:16)",
// type: undefined, // optional property, can be undefined, "eval", "native", or "internal"
// evalOrigin: undefined, // optional property only available if the stacktrace contains eval
// },
// ...and so on
// ];
```
## Source Map
```ts
import { loadSourceMap, originalPositionFor, sourceContentFor } from "@visulima/error";
const sourceMap = loadSourceMap("your_path/src/index.js"); // returns a TraceMap
const traced = originalPositionFor(sourceMap, { column: 13, line: 30 });
console.log(traced);
// {
// column: 9,
// line: 15,
// name: "setState",
// source: "your_path/src/index.js"
// }
console.log(sourceContentFor(sourceMap, traced.source)); // 'content for your_path/src/index.js'
```
For more information about the TraceMap see [@jridgewell/trace-mapping](https://github.com/jridgewell/trace-mapping)
## Supported Node.js Versions

@@ -102,2 +161,22 @@

## About
### Related Projects
- [baseerr](https://github.com/tjmehta/baseerr): merge another error with additional properties.
- [callsite-record](https://github.com/inikulin/callsite-record): create a fancy log entries for errors and function call sites.
- [callsites](https://github.com/sindresorhus/callsites): get callsites from the V8 stack trace API.
- [explain-error](https://github.com/dominictarr/explain-error): wrap an error with additional explanation.
- [error-wrapper](https://github.com/spudly/error-wrapper): merges the stack of another error to its own.
- [errwischt/stacktrace-parser](https://github.com/errwischt/stacktrace-parser)
- [trace](https://github.com/AndreasMadsen/trace): create super long stack traces.
- [clarify](https://github.com/AndreasMadsen/clarify): remove node related stack trace noise.
- [piotr-szewczyk/stacktrace-parser-node](https://github.com/piotr-szewczyk/stacktrace-parser-node)
- [pretty-error](https://github.com/AriaMinaei/pretty-error): make the call stacks clear.
- [ono](https://github.com/bigstickcarpet/ono): allow different types of error to be thrown.
- [ololog](https://github.com/xpl/ololog): another logger with a similar motivation but only support console.log as its sole transport.
- [stacktracejs/error-stack-parser](https://github.com/stacktracejs/error-stack-parser)
- [marvinhagemeister/errorstacks](https://github.com/marvinhagemeister/errorstacks) Tiny library to parse error stack traces
- [getsentry/sentry-javascript](https://github.com/getsentry/sentry-javascript)
## License

@@ -104,0 +183,0 @@

Sorry, the diff of this file is not supported yet

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