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

jack-of-all-decorators

v1.1.0-beta.1

Published

Decorator library for TypeScript. Serialize/deserialzie classes to JSON. Decorate methods with lodash, etc. Dependency injection.

Downloads

2

Readme

Build Status Coverage Status GitHub version npm version

Jack-of-All-Decorators (beta)

Is a TypeScript library that contains may useful class decorators to help remove some of the tiresome boiler-plate from TypeScript/JavaScript development.

  • Jsonables adds JSON Serialization/Deserialization to classes.
  • Decorators wraps class members with convenient transformers, like lodash functions and others.
  • Dependency Injection handles instantiation/destruction of class dependencies at the global and/or module level.

Installation

Install via npm:

npm install jack-of-all-decorators

Documentation Wiki

View the docs at the GitHub Wiki.


Brief Intro to the Library...

Jsonables - JSON Serialization/Deserialization of Classes.

Jsonable decorators make classes JSON serializable by adding the toJSON() method.

Example Class with Basic JSON Serialization:

@Json.Serializable()
class MyClass {

    constructor (
        public foo: string = "",
        private _bar: string = ""
    ) {}

    public getBar () {
        return this._bar;
    }

    public setBar (v: string) {
        this._bar = v;
    }
}

const myClass = new MyClass ("a", "b");
const json = myClass.toJSON();
console.log(JSON.stringify(myClass));
// Outputs: {"foo": "a", "bar": "b"}

Example JSON Deserialization:

const myNewClass = Json.Serializer.deserialize<MyClass>(MyClass, json);
assert.equals(myClass.foo, myNewClass.foo);
assert.equals(myClass.getBar(), myNewClass.getBar());

Note: Jsonables offers highly customizable JSON serialization options beyond the basic example above. Explore the docs to learn more.

Decorators - Wrap Class Members with Useful Transformers

The Decorators module provides many decorators to augment the input and output of class members. Most deocrators use the amazing lodash library. A few others provide features beyond what lodash offers.

Example Decorator Usage:

class MyClass {

    private _createdOn = new Date();

    // Returns a copy of the _createdOn Date object.
    @defensiveCopy
    public get createdOn () {
        return this._createdOn;
    }

    // Returns the sum of the array: 15.
    @sum
    public getTotal () {
        return [1, 2, 3, 4, 5];
    }

    // Returns: &lt;strong&gt;TypeScript &amp; JavaScript&lt;/strong&gt;
    @escape
    pubic getHTMLSafe () {
        return "<strong>TypeScript & JavaScript</strong>";
    }

    // Returns: Saturday, June 9, 2007
    @dateFormat("fullDate")
    public getDate() {
        return new Date();
    }
}

Dependency Injection - Handle Class Dependencies

The Dependency Injection module provides an easy way to manage class dependencies. Dependencies are instantiated as Singletons that are sandboxed to the global or given module namespace.

Example Dependency Injection Usage:

@Injectable()
class Foo implements IInjectable {

    public guid = Math.random().toString(36).substr(2);

    public destruct(): void {
        this.guid = null;
    }
}

class MyClass implements IInjectable {

    constructor (
        @Inject(Foo) public foo: Foo
    ) {}

    public destruct () {
        this.foo = null;
    }
}

const myClass = DI.Modularize<MyClass>(MyClass, "module.path");
console.log(myClass.foo);
DI.Destruct("module.path");

Special Thanks

I stand upon the shoulders of giants

lodash -- https://github.com/lodash/lodash/

The lodash library is used extensively in the Decorators module.

dateformat -- https://github.com/felixge/node-dateformat

The dateformat library is used by the dateFormat decorator.


License

(The MIT License)

Copyright (c) 2016 Patrick Martin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.