nexus site path corrected
[portal.git] / ecomp-portal-FE / client / bower_components / jqTree / src / util.coffee
1 # Standard javascript indexOf. Implemented here because not all browsers support it.
2 _indexOf = (array, item) ->
3     for value, i in array
4         if value == item
5             return i
6     return -1
7
8 indexOf = (array, item) ->
9     if array.indexOf
10         # The browser supports indexOf
11         return array.indexOf(item)
12     else
13         # Do our own indexOf
14         return _indexOf(array, item)
15
16 isInt = (n) ->
17     return typeof n is 'number' and n % 1 == 0
18
19
20 isFunction = (v) ->
21     return typeof v == 'function'
22
23
24 # Escape a string for HTML interpolation; copied from underscore js
25 html_escape = (string) ->
26     return (''+string)
27         .replace(/&/g, '&')
28         .replace(/</g, '&lt;')
29         .replace(/>/g, '&gt;')
30         .replace(/"/g, '&quot;')
31         .replace(/'/g, '&#x27;')
32         .replace(/\//g,'&#x2F;')
33
34
35 getBoolString = (value) ->
36     if value
37         return 'true'
38     else
39         return 'false'
40
41
42 module.exports =
43     _indexOf: _indexOf
44     getBoolString: getBoolString
45     html_escape: html_escape
46     indexOf: indexOf
47     isInt: isInt
48     isFunction: isFunction