npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

shiki-decorators

v1.0.1

Published

[![Build Status](https://travis-ci.com/shikimori/shiki-decorators.svg?branch=master)](https://travis-ci.com/shikimori/shiki-decorators)

Downloads

2,272

Readme

Build Status

shiki-decorators

This repository contains set of useful es7 decorators: bind, memoize, chain, throttle and debounce.

@bind uses NoHomey/bind-decorator

Binds method to the current context.

import { bind } from 'shiki-decorators';
// or to import with tree shaking use
// import bind from 'shiki-decorators/src/bind';

class Example {
  a = 'a from example'

  @bind
  foo() {
    console.log(this.a);
  }

  boo() {
    console.log(this.a);
  }
}

const example = new Example();
const z = { a: 'a from z' };
z.foo = example.foo;
z.boo = example.boo;

z.foo();
z.boo();

// Output
// a from example
// a from z

@memoize uses andreypopp/memoize-decorator

A method/getter decorator which is when applied to a method or a getter memoizes the result of the first call and returns it on subsequent calls.

import { memoize } from 'shiki-decorators';
// or to import with tree shaking use
// import memoize from 'shiki-decorators/src/memoize';

class Example {
  @memoize
  foo() {
    console.log('heavy method computations');
    return 'foo';
  }

  @memoize
  get boo() {
    console.log('heavy getter computations');
    return 'boo';
  }
}

let example = new Example();

console.log(example.foo()); // prints '', and then prints "1"
console.log(example.boo); // prints '', and then prints "1"

console.log(example.foo()); // just prints '1'
console.log(example.boo); // just prints '1'

// Output
// heavy method computations
// foo
// heavy getter computations
// boo
// foo
// boo

@chain

Allows chaining execution of a function. Each method returns a called object, allowing the calls to be chained together in a single statement.

import { chain } from 'shiki-decorators';
// or to import with tree shaking use
// import chain from 'shiki-decorators/src/chain';

class Example {
  @chain
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();
example.foo(1).foo(2);

// Output
// num: 1
// num: 2

@throttle

Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.

import { throttle } from 'shiki-decorators';
// or to import with tree shaking use
// import throttle from 'shiki-decorators/src/throttle';

class Example {
  @throttle(1000)
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();

example.foo(1); // Will execute the callback
example.foo(2); // Won’t execute callback
example.foo(3); // Won’t execute callback

setTimeout(() => {
  example.foo(10); // Will execute the callback
}, 900);

setTimeout(() => {
  example.foo(100); // Will execute the callback
}, 1200);

// Output
// num: 1
// num: 10
// num: 100

@debounce

Debounce execution of a function. Debouncing, unlike throttling, guarantees that a function is only executed a single time, either at the very beginning of a series of calls, or at the very end.

import { debounce } from 'shiki-decorators';
// or to import with tree shaking use
// import debounce from 'shiki-decorators/src/debounce';

class Example {
  @debounce(1000)
  foo(num) {
    console.log('num:', num);
  }
}

const example = new Example();

example.foo(1); // Won't execute callback
example.foo(2); // Won’t execute callback
example.foo(3); // Will execute the callback

setTimeout(() => {
  example.foo(10); // Will execute the callback
}, 1200);

// Output
// num: 3
// num: 10

Package release command

GITHUB_TOKEN=... npm run release