This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var getType = function (obj) { | |
return Object.prototype.toString.call(obj).match(/\[object (\w+)\]/)[1]; | |
}; | |
isString = function () { | |
return getType(this) === 'String'; | |
}; | |
isArray = function () { | |
return getType(this) === 'Array'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* file : validator | |
* author : qiuzhiming | |
* date : 2017-3-3 10:40:43 | |
* last : 2017-3-3 10:40:43 | |
* description : 用于表单的数据验证,支持链式操作,Submit的操作可以写在最后的Done里面 | |
* sample: v.test({ | |
* data : 'hello', | |
* rule : {Function} or {RegExp} or {Boolean} or {String} | |
* success: {Function}, 可以省略 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
<style> | |
ul { | |
display: flex; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (global, factory) { | |
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | |
typeof define === 'function' && define.amd ? define(factory) : | |
(global.YourProjectName = factory()); | |
}(this, (function () { | |
'use strict'; | |
}))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cached (fn) { | |
var cache = Object.create(null); | |
return (function cachedFn (str) { | |
var hit = cache[str]; | |
return hit || (cache[str] = fn(str)) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Camelize a hyphen-delimited string. | |
*/ | |
var camelizeRE = /-(\w)/g; | |
var camelize = cached(function (str) { | |
return str.replace(camelizeRE, function (_, c) { return c ? c.toUpperCase() : ''; }) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert an Array-like object to a real Array. | |
*/ | |
function toArray (list, start) { | |
start = start || 0; | |
var i = list.length - start; | |
var ret = new Array(i); | |
while (i--) { | |
ret[i] = list[i + start]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Mix properties into target object. | |
*/ | |
function extend (to, _from) { | |
for (var key in _from) { | |
to[key] = _from[key]; | |
} | |
return to | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Return same value | |
* var _a = identity(a) || b; | |
* 当a是undefined的时候,_a 可以是undefined | |
*/ | |
var identity = function (_) { return _; }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Check if two values are loosely equal - that is, | |
* if they are plain objects, do they have the same shape? | |
*/ | |
function looseEqual(a, b) { | |
var isObjectA = Object.prototype.toString.call(a) === '[object Object]'; | |
var isObjectB = Object.prototype.toString.call(b) === '[object Object]'; | |
if (isObjectA && isObjectB) { | |
return JSON.stringify(a) === JSON.stringify(b) | |
} else if (!isObjectA && !isObjectB) { |