00001
00002 (function() {
00003 var assign, camelCase, capitalize, isArray, isEmpty, isFunction, isObject, isPlainObject, kebabCase, snakeCase, titleCase, words,
00004 slice = [].slice,
00005 hasProp = {}.hasOwnProperty;
00006
00007 assign = function() {
00008 var i, key, len, source, sources, target;
00009 target = arguments[0], sources = 2 <= arguments.length ? slice.call(arguments, 1) : [];
00010 if (isFunction(Object.assign)) {
00011 Object.assign.apply(null, arguments);
00012 } else {
00013 for (i = 0, len = sources.length; i < len; i++) {
00014 source = sources[i];
00015 if (source != null) {
00016 for (key in source) {
00017 if (!hasProp.call(source, key)) continue;
00018 target[key] = source[key];
00019 }
00020 }
00021 }
00022 }
00023 return target;
00024 };
00025
00026 isFunction = function(val) {
00027 return !!val && Object.prototype.toString.call(val) === '[object Function]';
00028 };
00029
00030 isObject = function(val) {
00031 var ref;
00032 return !!val && ((ref = typeof val) === 'function' || ref === 'object');
00033 };
00034
00035 isArray = function(val) {
00036 if (isFunction(Array.isArray)) {
00037 return Array.isArray(val);
00038 } else {
00039 return Object.prototype.toString.call(val) === '[object Array]';
00040 }
00041 };
00042
00043 isEmpty = function(val) {
00044 var key;
00045 if (isArray(val)) {
00046 return !val.length;
00047 } else {
00048 for (key in val) {
00049 if (!hasProp.call(val, key)) continue;
00050 return false;
00051 }
00052 return true;
00053 }
00054 };
00055
00056 isPlainObject = function(val) {
00057 var ctor, proto;
00058 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));
00059 };
00060
00061 words = function(val) {
00062 return (val.split(/[-_\s]+|(?=[A-Z][a-z])/) || []).filter(function(n) {
00063 return !!n;
00064 });
00065 };
00066
00067 camelCase = function(val) {
00068 var i, index, len, r, ref, word;
00069 r = '';
00070 ref = words(val);
00071 for (index = i = 0, len = ref.length; i < len; index = ++i) {
00072 word = ref[index];
00073 r += index ? capitalize(word.toLowerCase()) : word.toLowerCase();
00074 }
00075 return r;
00076 };
00077
00078 titleCase = function(val) {
00079 var i, index, len, r, ref, word;
00080 r = '';
00081 ref = words(val);
00082 for (index = i = 0, len = ref.length; i < len; index = ++i) {
00083 word = ref[index];
00084 r += capitalize(word.toLowerCase());
00085 }
00086 return r;
00087 };
00088
00089 kebabCase = function(val) {
00090 var i, index, len, r, ref, word;
00091 r = '';
00092 ref = words(val);
00093 for (index = i = 0, len = ref.length; i < len; index = ++i) {
00094 word = ref[index];
00095 r += (index ? '-' : '') + word.toLowerCase();
00096 }
00097 return r;
00098 };
00099
00100 snakeCase = function(val) {
00101 var i, index, len, r, ref, word;
00102 r = '';
00103 ref = words(val);
00104 for (index = i = 0, len = ref.length; i < len; index = ++i) {
00105 word = ref[index];
00106 r += (index ? '_' : '') + word.toLowerCase();
00107 }
00108 return r;
00109 };
00110
00111 capitalize = function(val) {
00112 return val.charAt(0).toUpperCase() + val.slice(1);
00113 };
00114
00115 module.exports.assign = assign;
00116
00117 module.exports.isFunction = isFunction;
00118
00119 module.exports.isObject = isObject;
00120
00121 module.exports.isArray = isArray;
00122
00123 module.exports.isEmpty = isEmpty;
00124
00125 module.exports.isPlainObject = isPlainObject;
00126
00127 module.exports.camelCase = camelCase;
00128
00129 module.exports.titleCase = titleCase;
00130
00131 module.exports.kebabCase = kebabCase;
00132
00133 module.exports.snakeCase = snakeCase;
00134
00135 module.exports.capitalize = capitalize;
00136
00137 module.exports.words = words;
00138
00139 }).call(this);