Browse Source

:sparkles::rocket:continuous updating

striveDJiang 8 years ago
parent
commit
5729552d74

+ 3 - 3
array/arrayFlattening.js

@@ -32,8 +32,8 @@ function arrayFlattening(arr) {
 //         } else {
 //             // 不是数组直接 push 到 newArr 中
 //             newArr.push(arr[i]);
-//         }
-//     }
+//         };
+//     };
 //     return newArr;
 // };
 
@@ -41,7 +41,7 @@ function arrayFlattening(arr) {
 // function arrayFlattening(arr) {
 //     while (arr.some((item) => Array.isArray(item))) {
 //         arr = [].concat(...arr);
-//     }
+//     };
 //     return arr;
 // };
 

+ 3 - 3
array/arrayRemoveRepeat.js

@@ -27,10 +27,10 @@ function arrayRemoveRepeat(arr) {
 //         for (let j = i + 1; j < arr.length; j++) {
 //             if (arr[i] === arr[j]) {
 //                 j = ++i;
-//             }
-//         }
+//             };
+//         };
 //         newarr.push(arr[i]);
-//     }
+//     };
 //     return newarr;
 // };
 

+ 3 - 3
array/getCount.js

@@ -16,7 +16,7 @@ function getCount(arr, rank, ranktype) {
             obj[k]++;
         } else {
             obj[k] = 1;
-        }
+        };
     };
     //保存结果{el:'元素',count:出现次数}
     for (var o in obj) {
@@ -27,12 +27,12 @@ function getCount(arr, rank, ranktype) {
     };
     //排序(降序)
     arr1.sort(function (n1, n2) {
-        return n2.count - n1.count
+        return n2.count - n1.count;
     });
     //如果ranktype为1,则为升序,反转数组
     if (ranktype === 1) {
         arr1 = arr1.reverse();
-    }
+    };
     var rank1 = rank || arr1.length;
     return arr1.slice(0, rank1);
 };

+ 1 - 1
array/getEleCount.js

@@ -10,7 +10,7 @@ function getEleCount(obj, ele) {
     for (var i = 0, len = obj.length; i < len; i++) {
         if (ele === obj[i]) {
             num++;
-        }
+        };
     };
     return num;
 };

+ 1 - 1
bom/offset.js

@@ -15,6 +15,6 @@ function offset(ele) {
         ele = ele.offsetParent;
     };
     return pos;
-}
+};
 
 module.exports = offset;

+ 6 - 6
bom/scrollTo.js

@@ -17,23 +17,23 @@ var requestAnimFrame = (function () {
 function scrollTo(to, duration) {
     if (duration < 0) {
         setScrollTop(to);
-        return
-    }
+        return;
+    };
     var diff = to - getScrollTop();
-    if (diff === 0) return
+    if (diff === 0) return;
     var step = diff / duration * 10;
     requestAnimationFrame(
         function () {
             if (Math.abs(step) > Math.abs(diff)) {
                 setScrollTop(getScrollTop() + diff);
                 return;
-            }
+            };
             setScrollTop(getScrollTop() + step);
             if (diff > 0 && getScrollTop() >= to || diff < 0 && getScrollTop() <= to) {
                 return;
-            }
+            };
             scrollTo(to, duration - 16);
         });
-}
+};
 
 module.exports = scrollTo;

+ 1 - 1
bom/setScrollTop.js

@@ -5,6 +5,6 @@
 function setScrollTop(value) {
     window.scrollTo(0, value);
     return value;
-}
+};
 
 module.exports = setScrollTop;

+ 3 - 3
cookie/getCookie.js

@@ -10,9 +10,9 @@ function getCookie(name) {
         var tempArr = arr[i].split('=');
         if (tempArr[0] == name) {
             return decodeURIComponent(tempArr[1]);
-        }
-    }
+        };
+    };
     return '';
 };
 
-module.exports = getCookie
+module.exports = getCookie;

+ 2 - 2
cookie/removeCookie.js

@@ -7,6 +7,6 @@ var setCookie = require('./setCookie');
 function removeCookie(name) {
     // 设置已过期,系统会立刻删除cookie
     setCookie(name, '1', -1);
-}
+};
 
-module.exports = removeCookie
+module.exports = removeCookie;

+ 2 - 2
cookie/setCookie.js

@@ -9,6 +9,6 @@ function setCookie(name, value, days) {
     var date = new Date();
     date.setDate(date.getDate() + days);
     document.cookie = name + '=' + value + ';expires=' + date;
-}
+};
 
-module.exports = setCookie
+module.exports = setCookie;

+ 7 - 7
date/formatPassTime.js

@@ -11,12 +11,12 @@ function formatPassTime(startTime) {
         min = parseInt(time / (1000 * 60)),
         month = parseInt(day / 30),
         year = parseInt(month / 12);
-    if (year) return year + "年前"
-    if (month) return month + "个月前"
-    if (day) return day + "天前"
-    if (hour) return hour + "小时前"
-    if (min) return min + "分钟前"
-    else return '刚刚'
+    if (year) return year + "年前";
+    if (month) return month + "个月前";
+    if (day) return day + "天前";
+    if (hour) return hour + "小时前";
+    if (min) return min + "分钟前";
+    else return '刚刚';
 };
 
-module.exports = formatPassTime
+module.exports = formatPassTime;

+ 2 - 2
date/formatRemainTime.js

@@ -17,8 +17,8 @@ function formatRemainTime(endTime) {
         h = Math.floor(t / 1000 / 60 / 60 % 24);
         m = Math.floor(t / 1000 / 60 % 60);
         s = Math.floor(t / 1000 % 60);
-    }
+    };
     return d + "天 " + h + "小时 " + m + "分钟 " + s + "秒";
 };
 
-module.exports = formatRemainTime
+module.exports = formatRemainTime;

+ 7 - 7
device/getExplore.js

@@ -15,13 +15,13 @@ function getExplore() {
         (s = ua.match(/chrome\/([\d\.]+)/)) ? sys.chrome = s[1] :
         (s = ua.match(/version\/([\d\.]+).*safari/)) ? sys.safari = s[1] : 0;
     // 根据关系进行判断
-    if (sys.ie) return ('IE: ' + sys.ie)
-    if (sys.edge) return ('EDGE: ' + sys.edge)
-    if (sys.firefox) return ('Firefox: ' + sys.firefox)
-    if (sys.chrome) return ('Chrome: ' + sys.chrome)
-    if (sys.opera) return ('Opera: ' + sys.opera)
-    if (sys.safari) return ('Safari: ' + sys.safari)
-    return 'Unkonwn'
+    if (sys.ie) return ('IE: ' + sys.ie);
+    if (sys.edge) return ('EDGE: ' + sys.edge);
+    if (sys.firefox) return ('Firefox: ' + sys.firefox);
+    if (sys.chrome) return ('Chrome: ' + sys.chrome);
+    if (sys.opera) return ('Opera: ' + sys.opera);
+    if (sys.safari) return ('Safari: ' + sys.safari);
+    return 'Unkonwn';
 };
 
 module.exports = getExplore;

+ 1 - 2
device/getKeyName.js

@@ -116,9 +116,8 @@ function getKeyName(keycode) {
     if (keyCodeMap[keycode]) {
         return keyCodeMap[keycode];
     } else {
-        console.log('Unknow Key(Key Code:' + keycode + ')');
         return '';
-    }
+    };
 };
 
 module.exports = getKeyName;

+ 6 - 6
device/getOS.js

@@ -8,12 +8,12 @@ function getOS() {
     var vendor = 'navigator' in window && 'vendor' in navigator && navigator.vendor.toLowerCase() || '';
     var appVersion = 'navigator' in window && 'appVersion' in navigator && navigator.appVersion.toLowerCase() || '';
 
-    if (/mac/i.test(appVersion)) return 'MacOSX'
-    if (/win/i.test(appVersion)) return 'windows'
-    if (/linux/i.test(appVersion)) return 'linux'
-    if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) 'ios'
-    if (/android/i.test(userAgent)) return 'android'
-    if (/win/i.test(appVersion) && /phone/i.test(userAgent)) return 'windowsPhone'
+    if (/mac/i.test(appVersion)) return 'MacOSX';
+    if (/win/i.test(appVersion)) return 'windows';
+    if (/linux/i.test(appVersion)) return 'linux';
+    if (/iphone/i.test(userAgent) || /ipad/i.test(userAgent) || /ipod/i.test(userAgent)) 'ios';
+    if (/android/i.test(userAgent)) return 'android';
+    if (/win/i.test(appVersion) && /phone/i.test(userAgent)) return 'windowsPhone';
 };
 
 module.exports = getOS;

+ 1 - 2
dom/addClass.js

@@ -4,13 +4,12 @@
  * @param  {HTMLElement} ele 
  * @param  {String} cls 
  */
-
 var hasClass = require('./hasClass');
 
 function addClass(ele, cls) {
     if (!hasClass(ele, cls)) {
         ele.className += ' ' + cls;
-    }
+    };
 };
 
 module.exports = addClass;

+ 1 - 2
dom/removeClass.js

@@ -4,14 +4,13 @@
  * @param {HTMLElement} ele 
  * @param {String} cls 
  */
-
 var hasClass = require('./hasClass');
 
 function removeClass(ele, cls) {
     if (hasClass(ele, cls)) {
         var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
         ele.className = ele.className.replace(reg, ' ');
-    }
+    };
 };
 
 module.exports = removeClass;

+ 2 - 2
function/debounce.js

@@ -1,5 +1,3 @@
-var throttle = require('./throttle');
-
 /**
  * @desc 函数防抖 
  * 与throttle不同的是,debounce保证一个函数在多少毫秒内不再被触发,只会执行一次,
@@ -14,6 +12,8 @@ var throttle = require('./throttle');
  *
  * @return {Function} 新的防抖函数。
  */
+var throttle = require('./throttle');
+
 function debounce(delay, atBegin, callback) {
     return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);
 };

+ 7 - 21
function/throttle.js

@@ -15,59 +15,48 @@
  * @return {Function}  新的节流函数
  */
 module.exports = function throttle(delay, noTrailing, callback, debounceMode) {
-
     // After wrapper has stopped being called, this timeout ensures that
     // `callback` is executed at the proper times in `throttle` and `end`
     // debounce modes.
     var timeoutID;
-
     // Keep track of the last time `callback` was executed.
     var lastExec = 0;
-
     // `noTrailing` defaults to falsy.
     if (typeof noTrailing !== 'boolean') {
         debounceMode = callback;
         callback = noTrailing;
         noTrailing = undefined;
-    }
-
+    };
     // The `wrapper` function encapsulates all of the throttling / debouncing
     // functionality and when executed will limit the rate at which `callback`
     // is executed.
     function wrapper() {
-
         var self = this;
         var elapsed = Number(new Date()) - lastExec;
         var args = arguments;
-
         // Execute `callback` and update the `lastExec` timestamp.
         function exec() {
             lastExec = Number(new Date());
             callback.apply(self, args);
-        }
-
+        };
         // If `debounceMode` is true (at begin) this is used to clear the flag
         // to allow future `callback` executions.
         function clear() {
             timeoutID = undefined;
-        }
-
+        };
         if (debounceMode && !timeoutID) {
             // Since `wrapper` is being called for the first time and
             // `debounceMode` is true (at begin), execute `callback`.
             exec();
-        }
-
+        };
         // Clear any existing timeout.
         if (timeoutID) {
             clearTimeout(timeoutID);
-        }
-
+        };
         if (debounceMode === undefined && elapsed > delay) {
             // In throttle mode, if `delay` time has been exceeded, execute
             // `callback`.
             exec();
-
         } else if (noTrailing !== true) {
             // In trailing throttle mode, since `delay` time has not been
             // exceeded, schedule `callback` to execute `delay` ms after most
@@ -79,11 +68,8 @@ module.exports = function throttle(delay, noTrailing, callback, debounceMode) {
             // If `debounceMode` is false (at end), schedule `callback` to
             // execute after `delay` ms.
             timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);
-        }
-
-    }
-
+        };
+    };
     // Return the wrapper function.
     return wrapper;
-
 };

+ 5 - 5
object/dataType.js

@@ -8,7 +8,7 @@
 function dataType(o, type) {
     if (type) {
         var _type = type.toLowerCase();
-    }
+    };
     switch (_type) {
         case 'string':
             return Object.prototype.toString.call(o) === '[object String]';
@@ -29,10 +29,10 @@ function dataType(o, type) {
         case 'nan':
             return isNaN(o);
         case 'elements':
-            return Object.prototype.toString.call(o).indexOf('HTML') !== -1
+            return Object.prototype.toString.call(o).indexOf('HTML') !== -1;
         default:
-            return Object.prototype.toString.call(o)
-    }
+            return Object.prototype.toString.call(o);
+    };
 };
 
-module.exports = dataType
+module.exports = dataType;

+ 5 - 10
object/deepClone.js

@@ -4,35 +4,30 @@
  */
 function deepClone(values) {
     var copy;
-
     // Handle the 3 simple types, and null or undefined
     if (null == values || "object" != typeof values) return values;
-
     // Handle Date
     if (values instanceof Date) {
         copy = new Date();
         copy.setTime(values.getTime());
         return copy;
-    }
-
+    };
     // Handle Array
     if (values instanceof Array) {
         copy = [];
         for (var i = 0, len = values.length; i < len; i++) {
             copy[i] = deepClone(values[i]);
-        }
+        };
         return copy;
-    }
-
+    };
     // Handle Object
     if (values instanceof Object) {
         copy = {};
         for (var attr in values) {
             if (values.hasOwnProperty(attr)) copy[attr] = deepClone(values[attr]);
-        }
+        };
         return copy;
-    }
-
+    };
     throw new Error("Unable to copy values! Its type isn't supported.");
 };
 

+ 2 - 2
object/isEmptyObject.js

@@ -6,8 +6,8 @@
  */
 function isEmptyObject(obj) {
     if (!obj || typeof obj !== 'object' || Array.isArray(obj))
-        return false
-    return !Object.keys(obj).length
+        return false;
+    return !Object.keys(obj).length;
 };
 
 module.exports = isEmptyObject;

+ 1 - 1
regexp/isIdCard.js

@@ -6,6 +6,6 @@
  */
 function isIdCard(str) {
     return /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/.test(str)
-}
+};
 
 module.exports = isIdCard;

+ 2 - 2
regexp/isPhoneNum.js

@@ -5,7 +5,7 @@
  * @return {Boolean} 
  */
 function isPhoneNum(str) {
-    return /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test(str)
-}
+    return /^(0|86|17951)?(13[0-9]|15[012356789]|17[678]|18[0-9]|14[57])[0-9]{8}$/.test(str);
+};
 
 module.exports = isPhoneNum;

+ 1 - 1
regexp/isUrl.js

@@ -6,6 +6,6 @@
  */
 function isUrl(str) {
     return /[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/i.test(str);
-}
+};
 
 module.exports = isUrl;

+ 2 - 2
string/changeCase.js

@@ -7,7 +7,7 @@
  */
 function changeCase(str, type) {
     function ToggleCase(str) {
-        var itemText = ""
+        var itemText = "";
         str.split("").forEach(
             function (item) {
                 if (/^([a-z]+)/.test(item)) {
@@ -37,7 +37,7 @@ function changeCase(str, type) {
             return str.toLowerCase();
         default:
             return str;
-    }
+    };
 };
 
 module.exports = changeCase;

+ 4 - 4
string/digitUppercase.js

@@ -19,7 +19,7 @@ function digitUppercase(n) {
     var s = '';
     for (var i = 0; i < fraction.length; i++) {
         s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
-    }
+    };
     s = s || '整';
     n = Math.floor(n);
     for (var i = 0; i < unit[0].length && n > 0; i++) {
@@ -27,12 +27,12 @@ function digitUppercase(n) {
         for (var j = 0; j < unit[1].length && n > 0; j++) {
             p = digit[n % 10] + unit[1][j] + p;
             n = Math.floor(n / 10);
-        }
+        };
         s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
-    }
+    };
     return head + s.replace(/(零.)*零元/, '元')
         .replace(/(零.)+/g, '零')
         .replace(/^整$/, '零元整');
 };
 
-module.exports = digitUppercase
+module.exports = digitUppercase;

+ 2 - 2
string/removeSpace.js

@@ -17,7 +17,7 @@ function removeSpace(str, type) {
             return str.replace(/(\s*$)/g, "");
         default:
             return str;
-    }
+    };
 };
 
-module.exports = removeSpace
+module.exports = removeSpace;

+ 2 - 2
string/repeatCopy.js

@@ -9,8 +9,8 @@ function repeatCopy(str, count) {
     var text = '';
     for (var i = 0; i < count; i++) {
         text += str;
-    }
+    };
     return text;
 };
 
-module.exports = repeatCopy
+module.exports = repeatCopy;

+ 1 - 1
string/stringFormat.JS

@@ -14,4 +14,4 @@ function stringFormat(str, size, delimiter) {
     return str.replace(reg, _delimiter);
 };
 
-module.exports = stringFormat
+module.exports = stringFormat;

+ 1 - 1
string/stringReplace.js

@@ -11,4 +11,4 @@ function stringReplace(str, FindText, RegText) {
     return str.replace(fRegExp, RegText);
 };
 
-module.exports = stringReplace
+module.exports = stringReplace;

+ 4 - 4
url/parseQueryString.js

@@ -5,12 +5,12 @@
  * @return {Object} 
  */
 function parseQueryString(url) {
-    url = url == null ? window.location.href : url
-    var search = url.substring(url.lastIndexOf('?') + 1)
+    url = url == null ? window.location.href : url;
+    var search = url.substring(url.lastIndexOf('?') + 1);
     if (!search) {
         return {}
     }
-    return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
-}
+    return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
+};
 
 module.exports = parseQueryString;

+ 3 - 6
url/stringfyQueryString.js

@@ -10,18 +10,15 @@ function stringfyQueryString(obj) {
 
     for (var key in obj) {
         var value = obj[key];
-
         if (value instanceof Array) {
             for (var i = 0; i < value.length; ++i) {
                 pairs.push(encodeURIComponent(key + '[' + i + ']') + '=' + encodeURIComponent(value[i]));
-            }
+            };
             continue;
         }
-
         pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key]));
-    }
-
+    };
     return pairs.join('&');
-}
+};
 
 module.exports = stringfyQueryString;