Socket
Book a DemoInstallSign in
Socket

@corefunc/decorators

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@corefunc/decorators

Decorators for modern JavaScript

0.0.5
latest
Source
npmnpm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

CoreFunc Decorators

CoreFunc Decorators

Decorators for modern JavaScript.

NPM Version NPM Downloads GitHub Stars TypeScript Typings Travis CI LGTM

Please Note: This is "Work in Progress" package. The new functionality will be added very slowly.

Usage

ECMAScript Module.

import {
  attempt, consoleGroup, measureExecution,
} from "@corefunc/decorators";

Deno (Pika https://pika.dev/)

import {
  attempt, consoleGroup, measureExecution,
} from "https://cdn.pika.dev/@corefunc/decorators";

Examples

Method Decorators

Attempt

import { attempt } from "@corefunc/decorators";

class Kitty {
  @attempt((error: Error, args: any[]) => {
    console.warn("Exception thrown!");
    console.log(error.message); // "uwu"
    console.dir(args); // [ 10, false ]
  })
  meow(volume: number, cute = true) {
    throw new Error("uwu");
  }
}

new Kitty().meow(10, false);

Console Group

import { consoleGroup } from "@corefunc/decorators";

class Class {
  @consoleGroup("GROUP ASYNC")
  async asyncRun() {
    console.log("I'm async");
  }
  @consoleGroup("GROUP SYNC")
  syncRun() {
    console.log("I'm sync");
  }
}
const test = new Class();
test.syncRun();
await test.asyncRun();

Measure Execution

import { measureExecution } from "@corefunc/decorators";

class Class {
  /* conole.time() label text */
  @measureExecution("long execution time here")
  hardTask() {
    let result = 0;
    for (let index = 0; index < 1_000_000_000; index++) {
      result += index;
    }
    return result;
  }
}
new Class().hardTask();

Property Decorators

Instance

import { Instance } from "@corefunc/decorators";

class ClassAlpha {
  name;
}
class ClassBeta {
  @Instance(ClassAlpha)
  alpha;
  constructor(alpha) {
   this.alpha = alpha;
  }
}
const beta = new ClassBeta({ name: 'ALPHA' });
beta.alpha; // ClassAlpha

See also

💾 My other projects

Open Source

Keywords

aop

FAQs

Package last updated on 27 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.