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

deborator

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deborator - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

61

index.ts
class DeboratorOptions {
log?: (text: string) => void;
showReturnValues? = false;
showProperties? = false;
}

@@ -84,20 +85,56 @@

enum FunctionKind {
Normal,
Getter,
Setter
}
const decorateFunction = (c: any, prop: string) => {
const overrideFunction = (fun: Function, kind: FunctionKind): Function => {
return (...args: any[]) => {
let funName = prop;
switch(kind) {
case FunctionKind.Normal:
default:
break;
case FunctionKind.Getter:
funName = "get " + funName;
break;
case FunctionKind.Setter:
funName = "set " + funName;
break;
}
const callMessage = original.name + "." + funName + dumpArgs(args);
log(callMessage);
const returnValue = fun.apply(c, args);
if (options.showReturnValues) {
log(" " + callMessage + " => " + dumpReturnValue(returnValue));
}
if (kind !== FunctionKind.Setter) {
return returnValue;
}
}
};
const originalFun = c[prop];
if (typeof originalFun !== "function") {
return;
}
c[prop] = (...args: any[]) => {
const callMessage = original.name + "." + prop + dumpArgs(args);
log(callMessage);
let getter = c.__lookupGetter__(prop);
let setter = c.__lookupSetter__(prop);
const returnValue = originalFun.apply(c, args);
if (options.showReturnValues) {
log(" " + callMessage + " => " + dumpReturnValue(returnValue));
if(options.showProperties) {
if (typeof(getter) === "function") {
c.__defineGetter__(prop, overrideFunction(getter, FunctionKind.Getter));
}
if (typeof(setter) === "function") {
c.__defineSetter__(prop, overrideFunction(setter, FunctionKind.Setter));
}
}
return returnValue;
};
} else {
c[prop] = overrideFunction(originalFun, FunctionKind.Normal);
}
};

@@ -104,0 +141,0 @@

2

package.json
{
"name": "deborator",
"version": "1.0.8",
"version": "1.0.9",
"description": "a TypeScript decorator, to add console.log() to all methods and properties of a class.",

@@ -5,0 +5,0 @@ "main": "deborator.ts",

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