How to use the typical.isClass function in typical

To help you get started, we’ve selected a few typical examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 75lb / renamer / lib / util.js View on Github external
return arrayify(pluginNames).map(pluginName => {
    let createPlugin
    if (typeof pluginName === 'string') {
      const loadModule = require('load-module')
      const globalModules = require('global-modules')
      createPlugin = loadModule(pluginName, {
        paths: [path.resolve(__dirname, 'plugin'), '.', globalModules],
        prefix: 'renamer-'
      })
    } else {
      createPlugin = pluginName
    }
    if (!(typeof createPlugin === 'function' && !t.isClass(createPlugin))) {
      throw new Error('Invalid plugin: plugin module must export a function')
    }
    const Plugin = createPlugin(require('./plugin-base'))
    if (!t.isClass(Plugin)) {
      throw new Error('Invalid plugin: plugin module must export a function which returns a class')
    }
    if (!Plugin.prototype.replace) {
      throw new Error('Invalid plugin: plugin class must implement a replace method')
    }
    return new Plugin()
  })
}
github 75lb / renamer / lib / util.js View on Github external
let createPlugin
    if (typeof pluginName === 'string') {
      const loadModule = require('load-module')
      const globalModules = require('global-modules')
      createPlugin = loadModule(pluginName, {
        paths: [path.resolve(__dirname, 'plugin'), '.', globalModules],
        prefix: 'renamer-'
      })
    } else {
      createPlugin = pluginName
    }
    if (!(typeof createPlugin === 'function' && !t.isClass(createPlugin))) {
      throw new Error('Invalid plugin: plugin module must export a function')
    }
    const Plugin = createPlugin(require('./plugin-base'))
    if (!t.isClass(Plugin)) {
      throw new Error('Invalid plugin: plugin module must export a function which returns a class')
    }
    if (!Plugin.prototype.replace) {
      throw new Error('Invalid plugin: plugin class must implement a replace method')
    }
    return new Plugin()
  })
}
github lwsjs / lws / lib / commands.js View on Github external
expand () {
    for (const [ name, cmd ] of this) {
      if (typeof cmd === 'string') {
        const Command = require(cmd)
        this.set(name, new Command())
      } else if (t.isClass(cmd)) {
        this.set(name, new cmd())
      }
    }
  }

typical

Isomorphic, functional type-checking for Javascript

MIT
Latest version published 1 month ago

Package Health Score

74 / 100
Full package analysis