-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.js
31 lines (30 loc) · 924 Bytes
/
plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict'
module.exports = (name, dependencies, plugin) => {
if (typeof name !== 'string') {
throw new TypeError(
`Expected name to be a string but got ${typeof name} "${name}"`
)
}
if (dependencies && !Array.isArray(dependencies)) {
throw new TypeError(
`Expected dependencies to be an array or null but got ${typeof dependencies} "${dependencies}"`
)
}
if (!plugin) {
throw new ReferenceError(
'Expected a plugin function passed as third argument, but third argument was not supplied.'
)
}
if (typeof plugin !== 'function') {
throw new TypeError(
`Expected plugin to be a function but got ${typeof plugin} "${plugin}"`
)
}
return (opts = {}) => {
plugin = plugin.bind(null, opts)
Object.defineProperty(plugin, 'name', { get: () => name })
plugin.dependencies = dependencies
plugin.isChappiePlugin = true
return plugin
}
}