-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (26 loc) · 894 Bytes
/
index.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
32
33
const { keys, assign } = Object
const eachModule = require('depject/each')
const defaultPriority = 500
module.exports = depjectPriority
function depjectPriority (...modules) {
var modulesByPriority = {}
modules.forEach(m => {
eachModule(m, (module, path) => {
set({ modulesByPriority, module, path })
})
})
// create copy of modules by priority
// where keys are created in order of priority.
var prioritized = {}
const priorityMinToMax = keys(modulesByPriority).sort()
priorityMinToMax.forEach(priority => {
prioritized[priority] = modulesByPriority[priority]
})
return prioritized
}
function set ({ modulesByPriority, module, path }) {
const { priority = defaultPriority } = module
module = assign({ path }, module)
if (modulesByPriority[priority] === undefined) modulesByPriority[priority] = []
modulesByPriority[priority].push(module)
}