-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.coffee
50 lines (45 loc) · 1.02 KB
/
base.coffee
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
43
44
45
46
47
48
49
50
exports.apply = apply = (o, c) ->
o = o || {}
(o[k]=v) for k,v of c
o
exports.applyIf = applyIf = (o, c) ->
o = o || {}
(o[k]=v) for k,v of c when !o[k]
o
exports.cloneIf = cloneIf = (o, t) ->
if t==false
o
else if typeof t=='function'
t(null, o)
else if o==null or o==undefined
null
else if typeof o!='object'
o
else if t==true
apply(null, o)
else
c = {}
for k,v of t
c[k] = cloneIf(o[k], v)
c
exports.copyIf = copyIf = (o, c, t) ->
if t==false
c
else if typeof t=='function'
t(null, c)
else if o==null or o==undefined
null
else if typeof o!='object'
c
else if t==true
apply(null, c)
else
o = o || {}
for k,v of t
o[k] = cloneIf(c[k], v)
o
exports.trim = trim = (s) ->
s.replace(/^\s\s*/, '').replace(/\s\s*$/, '')
exports.install = (namespace) ->
if namespace and !namespace.apply
apply(namespace, exports)