1.0.5 • Published 3 years ago

@namchee/decora v1.0.5

Weekly downloads
34
License
MIT
Repository
github
Last release
3 years ago

Decora

Useful ECMAScript decorator for personal purposes.

Although it's written in TypeScript, these decorators should be compatible with normal JS files as long as it supports ES7.

Will be updated indefinitely.

@benchmark

Decorator Type: Method decorator

Add benchmarking functionality to a method from a class. Benchmark result will be written to console.

Will transform the decorated function into an asynchronous function.

class Example {
  @benchmark()
  logMe() {
    console.log('test');
  }
}

Parameters

NameRequired?ValuesDefault ValueDescription
metricfalse['s', 'ms', 'ns']'ms'Metric to be used when logging function runtime
precisionfalsenumber, n > 1undefinedNumber of digits after comma. Passing undefined will print an abruptly long string.
streamtrueNodeJS.WritableStreamprocess.stdoutDestination for the log to be written to. Detailed Explanation

@timeout

Decorator Type: Method decorator

Limits a function execution time to a certain time limit. Will throw an error if timeout value exceeded.

Will transform the decorated function into an asynchronous function.

class Example {
  @benchmark(1000)
  timeoutMe() {
    setTimeoutPromise(5000); // will throw an error
  }
}

Parameters

NameRequired?ValuesDefault ValueDescription
timetruenumber-Time limit for the function
metricfalse['s', 'ms', 'ns']'ms'Metric to be used when logging function runtime