-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (38 loc) · 860 Bytes
/
index.js
File metadata and controls
43 lines (38 loc) · 860 Bytes
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
40
41
42
var _ = require('lodash')
, Manager = require('manager')
, utils = require('./utils')
module.exports = function (base, data) {
var args = []
if (arguments.length < 2) {
data = base
base = Manager
} else if (arguments.length > 2) {
args = [].slice.call(arguments, 1, -1)
data = arguments[arguments.length - 1]
}
args.push({
genId: newId.bind(null, 16),
defaultNode: {
children: [],
data: {text: ''},
type: 'normal',
tags: []
},
})
var f = base.bind.apply(base, [null].concat(args))
var m = new f()
utils.dump(m, data)
m.dump = function (data) {
utils.dump(m, data)
}
return m
}
function newId(ln) {
var chars = 'abcdef01245689'
, id = ''
ln = ln || 8
for (var i=0; i<chars.length; i++) {
id += chars[parseInt(chars.length * Math.random())]
}
return id
}