1.0.4 • Published 4 years ago

@abstraqt-dev/nameof v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

This is a transformer for the TypeScript compiler that adds a whole new nameof keyword.

Example usage with WebPack and ts-loader:

In webpack.config.js:

1) Import the nameof transformer

        const nameOfTransformer = require("./node_modules/@abstraqt-dev/nameof/lib/transformer").default;

2) In the rules sction

        rules: [
        {
            test: /\.(ts|tsx)$/,
            loader: 'ts-loader',
            options: {
                getCustomTransformers: (program) => ({
                    before: [nameOfTransformer(program)],
                    after: []
                })
            },
            exclude: /node_modules/,
        },

3) In tsconfig.json add the library to the included declarations files

    {
        ...,

        "types": [
            "@abstraqt-dev/nameof"
        ],
        
        ...
    }

In your code now you can just use the nameof keyword:

    interface IFoo {

    }

    class Bar {

    }

    let foo = nameof<IFoo>();
    let bar = nameof<Bar>();

    console.log(foo); // "IFoo"
    console.log(bar); // "Bar"
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago