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

common-types

Package Overview
Dependencies
Maintainers
1
Versions
308
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

common-types - npm Package Compare versions

Comparing version 1.2.3 to 1.3.0

.vscode/settings.json

47

lib/common-types.d.ts

@@ -42,1 +42,48 @@ /**

}
/** A decorator signature for a class property */
export declare type PropertyDecorator = (target: any, key: string | symbol) => void;
/** A decorator signature for a class */
export declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
export interface IVerboseError {
/** A short and unique identifier for the error; typically would not have any spaces in it */
code: string;
/** A user-friendly description of the error message */
message: string;
module?: string;
function?: string;
fileName?: string;
stackFrames?: any[];
}
export declare type LazyString = () => string;
export interface IStackFrame {
getTypeName: LazyString;
getFunctionName: LazyString;
getMethodName: LazyString;
getFileName: LazyString;
getLineNumber: LazyString;
getColumnNumber: LazyString;
isNative: LazyString | string;
}
export declare class VerboseError extends Error implements IVerboseError {
private static stackParser(err);
/**
* If you want to use a library like stack-trace(node) or stacktrace-js(client) add in the "get"
* function that they provide
*/
static setStackParser(fn: (err: IVerboseError) => any): void;
static useColor: true;
static filePathDepth: 3;
code: string;
message: string;
module?: string;
function?: string;
stackFrames?: IStackFrame[];
constructor(err: IVerboseError, ...args: any[]);
toString(): string;
toJSON(): string;
toObject(): {
code: string;
message: string;
module: string;
};
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require("chalk");
var STAGE;

@@ -23,2 +24,62 @@ (function (STAGE) {

;
class VerboseError extends Error {
static stackParser(err) {
return undefined;
}
/**
* If you want to use a library like stack-trace(node) or stacktrace-js(client) add in the "get"
* function that they provide
*/
static setStackParser(fn) {
VerboseError.stackParser = fn;
}
constructor(err, ...args) {
super(...args);
this.code = err.code;
this.message = err.message;
this.module = err.module;
this.function = err.function;
const stackFrames = VerboseError.stackParser(this);
if (stackFrames) {
this.stackFrames = stackFrames
.filter(frame => (frame.getFileName() || '').indexOf('common-types') === -1);
this.function = stackFrames[0].getMethodName();
this.stack = this.message + "\n\n" + this.stackFrames.map(frame => {
const isNative = typeof frame.isNative === 'function' ? frame.isNative() : frame.isNative;
const colorize = (content) => VerboseError.useColor && isNative ? chalk.grey.italic(content) : content;
const className = frame.getTypeName() ? frame.getTypeName() + ' → ' : '';
const functionName = frame.getMethodName() || frame.getFunctionName() || '<anonymous>';
const classAndFunction = VerboseError.useColor
? chalk.bold(`${className}${functionName}`)
: `${className}${functionName}`;
const fileName = (frame.getFileName() || '')
.split('/')
.slice(-1 * VerboseError.filePathDepth)
.join('/');
const details = isNative
? '( native function )'
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${fileName} ]`;
console.log(colorize(`\t at ${classAndFunction} ${details}`));
return colorize(`\t at ${classAndFunction} ${details}`);
}).join("\n");
}
else {
this.stack = this.stack.split("\n").filter(line => line.indexOf('VerboseError') === -1).join("\n");
}
}
toString() {
return this.message + this.stack;
}
toJSON() {
return JSON.stringify(this.toObject(), null, 2);
}
toObject() {
return {
code: this.code,
message: this.message,
module: this.module,
};
}
}
exports.VerboseError = VerboseError;
//# sourceMappingURL=common-types.js.map

10

package.json
{
"name": "common-types",
"version": "1.2.3",
"version": "1.3.0",
"description": "Common types not included in Typescript",

@@ -11,3 +11,9 @@ "main": "lib/common-types.js",

"author": "Ken Snyder <ken@ken.net>",
"license": "MIT"
"license": "MIT",
"dependencies": {
"chalk": "^2.1.0"
},
"devDependencies": {
"@types/chalk": "^0.4.31"
}
}

106

src/common-types.ts

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

import chalk = require('chalk');
/**

@@ -47,2 +47,104 @@ * A Javascript hash which allows for any set of keys

child_changed = 'child_changed'
};
};
// DECORATORS
/** A decorator signature for a class property */
export type PropertyDecorator = (target: any, key: string | symbol) => void;
/** A decorator signature for a class */
export type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
// ERRORS
export interface IVerboseError {
/** A short and unique identifier for the error; typically would not have any spaces in it */
code: string;
/** A user-friendly description of the error message */
message: string;
module?: string;
function?: string;
fileName?: string;
stackFrames?: any[];
}
export type LazyString = () => string;
export interface IStackFrame {
getTypeName: LazyString;
getFunctionName: LazyString;
getMethodName: LazyString;
getFileName: LazyString;
getLineNumber: LazyString;
getColumnNumber: LazyString;
isNative: LazyString | string;
}
export class VerboseError extends Error implements IVerboseError {
private static stackParser(err: VerboseError): void | any[] {
return undefined;
}
/**
* If you want to use a library like stack-trace(node) or stacktrace-js(client) add in the "get"
* function that they provide
*/
public static setStackParser(fn: (err: IVerboseError) => any) {
VerboseError.stackParser = fn;
}
public static useColor: true;
public static filePathDepth: 3;
code: string;
message: string;
module?: string;
function?: string;
stackFrames?: IStackFrame[];
constructor(err: IVerboseError, ...args: any[]) {
super(...args);
this.code = err.code;
this.message = err.message;
this.module = err.module;
this.function = err.function;
const stackFrames = VerboseError.stackParser(this);
if(stackFrames) {
this.stackFrames = stackFrames
.filter(frame => (frame.getFileName() || '').indexOf('common-types') === -1);
this.function = stackFrames[0].getMethodName();
this.stack = this.message + "\n\n" + this.stackFrames.map(frame => {
const isNative = typeof frame.isNative === 'function' ? frame.isNative() : frame.isNative;
const colorize = (content: string) => VerboseError.useColor && isNative ? chalk.grey.italic(content) : content;
const className = frame.getTypeName() ? frame.getTypeName() + ' → ' : '';
const functionName = frame.getMethodName() || frame.getFunctionName() || '<anonymous>';
const classAndFunction = VerboseError.useColor
? chalk.bold(`${className}${functionName}`)
: `${className}${functionName}`;
const fileName = (frame.getFileName() || '')
.split('/')
.slice(-1 * VerboseError.filePathDepth)
.join('/');
const details = isNative
? '( native function )'
: `[ line ${frame.getLineNumber()}, col ${frame.getColumnNumber()} in ${fileName} ]`;
console.log(colorize(`\t at ${classAndFunction} ${details}`));
return colorize(`\t at ${classAndFunction} ${details}`);
}).join("\n");
} else {
this.stack = this.stack.split("\n").filter(line => line.indexOf('VerboseError') === -1).join("\n");
}
}
toString() {
return this.message + this.stack;
}
toJSON() {
return JSON.stringify(this.toObject(), null, 2);
}
toObject() {
return {
code: this.code,
message: this.message,
module: this.module,
};
}
}

Sorry, the diff of this file is not supported yet

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