-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDomainNames.js
39 lines (29 loc) · 919 Bytes
/
DomainNames.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
34
35
36
37
38
39
// A group of Domain Name
const debug = require('debug')('d::domain-tree::DomainNames')
const map = require('lodash/map')
const reverse = require('lodash/reverse')
const Tree = require('./Tree.js')
const DomainName = require('./DomainName.js')
module.exports = class DomainNames extends Tree {
levels(domain){ return reverse(domain.split('.')) }
addDomain(domain, data) {
debug('adding domain', domain)
let last = this.root
this.levels(domain).forEach( level => {
let node = last.addNode(level, null)
last = node
})
last.data = data
return last
}
fetchDomain(domain) {
debug('adding domain', domain)
return this.root.fetchNode( this.levels(domain) )
}
// this needs to recurse
getSubDomains(domain) {
let node = this.root.fetchNode( this.levels(domain) )
return map(node.children, child => child.id)
}
}
module.exports.node_type = DomainName