Git Product home page Git Product logo

utils-decorators's Introduction

utils-decorators

Build Status
Coverage Status
Mutation testing badge

This library was highly inspired by lodash but uses decorators to implement its util methods.
The lib can be used both in node and in web application, it is built to be tree-shakable so you can use it even if you need a specific decorator.
Also, note that this library can be used both as functions and decorators,

installation:

npm i utils-decorators

Please note that the decorators are working perfectly with plain JavaScript code as well as with TypeScript.

Docs

check the documentation

Feedback

I will be more than happy to hear your feedback, don't hesitate to ask any question or open an issue. PRs are always welcomed :)
Also, I will be happy to hear about new ideas for new decorators, if you have such, please open an issue and describe the requirements and features of your decorator.

utils-decorators's People

Contributors

dependabot[bot] avatar gongpeione avatar maormoshe avatar notanengineercom avatar tripodsgames avatar tsachis avatar tyllo avatar vlio20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

utils-decorators's Issues

throttleAsync decorator

This decorator will allow only certin amount of calls to the async decorated method simultaneously. If the allowed amount of calls will be acceded the calls will be throttled.

Changelog

Please post a Github release when updating the NPM package or create a CHANGELOG.md - this allows Dependabot to display the changelog when proposing an upgrade to a newer util-decorators

Cache burst for memoize/memoizeAsync

First, thanks for your work and this library.

Please is it possible to provide a sample how to "burst"/invalidate the cache when we use memoize/memoizeAsync function/decorator ?

Thank you

Retry decorator

A decorator which will run x amount of retries of the method

measure decorator

A decorator which will measure the execution time of the decorated method

onError method decorator

Will invoke the provided method if the decorated method will throw an exception.

API:

function onError(method: Function): void

before (method)

Will invoke the provided method before the decorated method.

API:

function before(method: Function): void

timeout

this decorator will throw a timeout exception after waiting given time if the decorated method won't response during it

callableTimes

Will limit the amount of calls to the decorated method. If a call will be made after the specific amount an exception will be thrown

Uncatchable timeout

Is it possible to catch the timeout exception somehow? I'm always crashing with "Unhandled promise rejection"

UnhandledPromiseRejectionWarning: Error: timeout occurred after 2000
    at new TimeoutError (node_modules/utils-decorators/src/timeout/timeout.ts:6:5)
    at Timeout._onTimeout (node_modules/utils-decorators/src/timeout/timeout.ts:28:20)
    at listOnTimeout (internal/timers.js:554:17)
    at processTimers (internal/timers.js:497:7)

After decorator

Will invoke the provided after before the decorated method.

API:
function before(method: Function, delayMs: number): void

afterSet

Will trigger a method after setting the property

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.