¶ Utils¶ Exports: ObjectA collection of helper functions |
|
export the functions |
|
¶ randomString
Generate a random string Params
string_length
Number
string length to generate
speciallevel
Number
Level of complexity.
0 = only letters upper and lowercase, 52 possible chars;
1 = 0 + Numbers, 62 possible chars;
2 = 1 + "_-@:.", 67 possible chars;
3 = 2 + may speacial chars, 135 possible chars;
Returns
String
The gerated string
|
25
26 randomString: ( string_length = 5, specialLevel = 0 ) ->
27 chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
28 chars += "0123456789" if specialLevel >= 1
29 chars += "_-@:." if specialLevel >= 2
30 chars += "!\"§$%&/()=?*'_:;,.-#+¬”#£fi^\\˜·¯˙˚«∑€®†Ω¨⁄øπ•‘æœ@∆ºª©ƒ∂‚å–…∞µ~∫√ç≈¥" if specialLevel >= 3
31
32 randomstring = ""
33 i = 0
34
35 while i < string_length
36 rnum = Math.floor(Math.random() * chars.length)
37 randomstring += chars.substring(rnum, rnum + 1)
38 i++
39 randomstring
40
41
42 |
¶ randRange
Create a random number bewtween two values Params
lowVal
Number
Min number
highVal
Number
Max number
Returns
Number
A random number
|
|
¶ randRange
Create a random number bewtween two values Params
value
Number
String
The value to pad
[padding=2]
Number
The padding size
[fill="0"]
String
The filler value.
Returns
String
the padded value
|