JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1795
  • Score
    100M100P100Q104716F
  • License MIT

Get the methods of a JavaScript class.

Package Exports

  • class-methods

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (class-methods) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

class-methods PayPal Version Downloads Get help on Codementor

Get the methods of a JavaScript class.

☁️ Installation

$ npm i --save class-methods

📋 Example

const classMethods = require("class-methods");

class Person {
    constructor (name) {
        this.setName(name);
    }
    setName (name) {
        this.name = name;
    }
    getName (name) {
        return this.name;
    }
}

class Worker extends Person {
    constructor (name, job) {
        super(name);
        this.setJob(job);
    }
    setJob (job) {
        this.job = job;
    }
    getJob (job) {
        return this.job;
    }
    static randomName () {
        // Yes, it's random enough :D
        return ["Alice", "Bob"][0];
    }
}

console.log(classMethods(Worker));
// [ 'setJob', 'getJob', 'setName', 'getName' ]

console.log(classMethods(Person));
// [ 'setName', 'getName' ]

console.log(classMethods(Worker, {
    deep: false
}));
// [ 'setJob', 'getJob' ]

console.log(classMethods(Worker, {
    includeStatic: true
}));
// [ 'setJob', 'getJob', 'randomName', 'setName', 'getName' ]

📝 Documentation

classMethods(input, options)

Get the methods of a JavaScript class.

Params

  • Class input: The class you want to get the methods of.
  • Object options: An object containing the following fields:
  • deep (Boolean): If false the parent classes will not be iterated.
  • includeStatic (Boolean): If true, the static methods will be included too.

Return

  • Array The class methods.

😋 How to contribute

Have an idea? Found a bug? See how to contribute.

📜 License

MIT © Ionică Bizău