artdaq_node_server  v1_00_09
 All Classes Namespaces Files Variables Pages
Utility.js
1 // Generated by CoffeeScript 1.10.0
2 (function() {
3  var assign, camelCase, capitalize, isArray, isEmpty, isFunction, isObject, isPlainObject, kebabCase, snakeCase, titleCase, words,
4  slice = [].slice,
5  hasProp = {}.hasOwnProperty;
6 
7  assign = function() {
8  var i, key, len, source, sources, target;
9  target = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
10  if (isFunction(Object.assign)) {
11  Object.assign.apply(null, arguments);
12  } else {
13  for (i = 0, len = sources.length; i < len; i++) {
14  source = sources[i];
15  if (source != null) {
16  for (key in source) {
17  if (!hasProp.call(source, key)) continue;
18  target[key] = source[key];
19  }
20  }
21  }
22  }
23  return target;
24  };
25 
26  isFunction = function(val) {
27  return !!val && Object.prototype.toString.call(val) === '[object Function]';
28  };
29 
30  isObject = function(val) {
31  var ref;
32  return !!val && ((ref = typeof val) === 'function' || ref === 'object');
33  };
34 
35  isArray = function(val) {
36  if (isFunction(Array.isArray)) {
37  return Array.isArray(val);
38  } else {
39  return Object.prototype.toString.call(val) === '[object Array]';
40  }
41  };
42 
43  isEmpty = function(val) {
44  var key;
45  if (isArray(val)) {
46  return !val.length;
47  } else {
48  for (key in val) {
49  if (!hasProp.call(val, key)) continue;
50  return false;
51  }
52  return true;
53  }
54  };
55 
56  isPlainObject = function(val) {
57  var ctor, proto;
58  return isObject(val) && (proto = Object.getPrototypeOf(val)) && (ctor = proto.constructor) && (typeof ctor === 'function') && (ctor instanceof ctor) && (Function.prototype.toString.call(ctor) === Function.prototype.toString.call(Object));
59  };
60 
61  words = function(val) {
62  return (val.split(/[-_\s]+|(?=[A-Z][a-z])/) || []).filter(function(n) {
63  return !!n;
64  });
65  };
66 
67  camelCase = function(val) {
68  var i, index, len, r, ref, word;
69  r = '';
70  ref = words(val);
71  for (index = i = 0, len = ref.length; i < len; index = ++i) {
72  word = ref[index];
73  r += index ? capitalize(word.toLowerCase()) : word.toLowerCase();
74  }
75  return r;
76  };
77 
78  titleCase = function(val) {
79  var i, index, len, r, ref, word;
80  r = '';
81  ref = words(val);
82  for (index = i = 0, len = ref.length; i < len; index = ++i) {
83  word = ref[index];
84  r += capitalize(word.toLowerCase());
85  }
86  return r;
87  };
88 
89  kebabCase = function(val) {
90  var i, index, len, r, ref, word;
91  r = '';
92  ref = words(val);
93  for (index = i = 0, len = ref.length; i < len; index = ++i) {
94  word = ref[index];
95  r += (index ? '-' : '') + word.toLowerCase();
96  }
97  return r;
98  };
99 
100  snakeCase = function(val) {
101  var i, index, len, r, ref, word;
102  r = '';
103  ref = words(val);
104  for (index = i = 0, len = ref.length; i < len; index = ++i) {
105  word = ref[index];
106  r += (index ? '_' : '') + word.toLowerCase();
107  }
108  return r;
109  };
110 
111  capitalize = function(val) {
112  return val.charAt(0).toUpperCase() + val.slice(1);
113  };
114 
115  module.exports.assign = assign;
116 
117  module.exports.isFunction = isFunction;
118 
119  module.exports.isObject = isObject;
120 
121  module.exports.isArray = isArray;
122 
123  module.exports.isEmpty = isEmpty;
124 
125  module.exports.isPlainObject = isPlainObject;
126 
127  module.exports.camelCase = camelCase;
128 
129  module.exports.titleCase = titleCase;
130 
131  module.exports.kebabCase = kebabCase;
132 
133  module.exports.snakeCase = snakeCase;
134 
135  module.exports.capitalize = capitalize;
136 
137  module.exports.words = words;
138 
139 }).call(this);