This file contains 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
const surveyMachine = Machine({ | |
id: 'survey', | |
initial: 'index', | |
states: { | |
index: { | |
on: { | |
VERIFICATION_ACTIVE: 'verification', | |
VERIFICATION_INACTIVE: 'start', |
This file contains 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
//正整数 | |
/^[0-9]*[1-9][0-9]*$/; | |
//负整数 | |
/^-[0-9]*[1-9][0-9]*$/; | |
//正浮点数 | |
/^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/; | |
//负浮点数 |
This file contains 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 transformRMB(tranvalue) { | |
//拆分整数与小数 | |
var splits = function(tranvalue) { | |
var value = new Array('', ''); | |
temp = tranvalue.toString().split("."); | |
for (var i = 0; i < temp.length; i++) { | |
value = temp; | |
} | |
return value; | |
}; |
This file contains 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
/* | |
1、< 60s, 显示为“刚刚” | |
2、>= 1min && < 60 min, 显示与当前时间差“XX分钟前” | |
3、>= 60min && < 1day, 显示与当前时间差“今天 XX:XX” | |
4、>= 1day && < 1year, 显示日期“XX月XX日 XX:XX” | |
5、>= 1year, 显示具体日期“XXXX年XX月XX日 XX:XX” | |
*/ | |
function timeFormat(time) { | |
var date = new Date(time), | |
curDate = new Date(), |
This file contains 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 deepClone() { | |
let copy | |
// 处理3个简单的类型, null 或者 undefined | |
if (obj === null || typeof obj !== 'object') { | |
return obj | |
} | |
if (obj instanceof Date) { | |
copy = new Date() |
This file contains 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 throttle(fn, delay = 200) { | |
let now | |
let lastExec | |
let timer | |
let context | |
let args | |
const execute = () => { | |
fn.apply(context, args) | |
lastExec = now |
This file contains 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
class Storage { | |
constructor(strategy = 'internal') { | |
this.strategy = strategy | |
} | |
/** | |
* @param {string} key | |
* @param {any} val | |
* @param {number} maxAge 存储时间:ms | |
*/ |
This file contains 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
/** | |
* 获取URL参数 | |
* // http://jsfiddle.net/draft/?foo=foo&bar=bar | |
console.log(getUrlParams('foo')); // "foo" | |
console.log(getUrlParams()); // {foo: "foo", bar: "bar"} | |
*/ | |
function getUrlParams(name, uri) { | |
const params = {} | |
const search = uri || window.location.search |
This file contains 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
window.requestAnimFrame = (function requestAnimFrame() { | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
function simulation(callback) { | |
window.setTimeout(callback, 1000 / 60) | |
} | |
}()) | |
function scrollToY(scrollTargetY = 0, speed = 2000, easing = 'easeOutSine') { |
This file contains 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 optionalChaining(obj, chain) { | |
return chain | |
.split('.') | |
.reduce(function(acc, val) { | |
return acc ? acc[val] : undefined; | |
}, obj); | |
} | |
var user = { address: { street: 'No.969 West WenYi Road', }, a: { b: { c: 2 } }, } | |
var ret = optionalChaining(user, 'address'); | |
console.log(ret) |
NewerOlder