-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtron.coffee
55 lines (44 loc) · 1.46 KB
/
tron.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
51
52
53
54
55
# Very useful helper function to remove array items
Array::remove = (e) -> @[t..t] = [] if (t = @indexOf(e)) > -1
class Tron
constructor: ->
@timers = []
test: (args...) ->
u = """
This simple function will define the way we test Socrenchus. You can do
things in most of the same ways you did them with the console.
Call it with your test function like this:
tron.test( ->
tron.log( 'this writes to the log' )
tron.info( 'this is an info message' )
tron.warn( 'this is a warning' )
tron.error( 'this is an error' )
)
"""
for a in args
unless typeof a == 'function'
@warn(usage)
else
a()
stopwatch: ( timer_name ) ->
u = """
This function acts as both console.time and console.timeEnd, just pass it
a string to start the timer, and the same string to stop it.
"""
unless timer_name?
@warn(u)
else unless timer_name in @timers
@timers.push( timer_name )
console.time( timer_name )
else
r = console.timeEnd( timer_name )
@timers.remove( timer_name )
return r
log: (args...) -> console.log(args...)
info: (args...) -> console.info(args...)
warn: (args...) -> console.warn(args...)
error: (args...) -> console.error(args...)
dir: (args...) -> console.dir(args...)
trace: (args...) -> console.trace(args...)
assert: (args...) -> console.assert(args...)
tron = new Tron()