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
| Number.prototype.pad = function(size) { | |
| var s = String(this); | |
| while (s.length < (size || 2)) {s = "0" + s;} | |
| return s; | |
| } |
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
| /** | |
| * @param {string} dir file or folder path | |
| * @param {function} fileHandler hanlder function used for deal with file | |
| */ | |
| function walk(dir, fileHandler = (filePath) => filePath) { | |
| const fstats = fs.lstatSync(dir); | |
| if (fstats.isDirectory()) { | |
| const files = fs.readdirSync(dir); | |
| files.forEach((file) => { |
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
| // | |
| // Simple plugins mode in koajs use JavaScript async await | |
| // https://github.com/senchalabs/connect/blob/master/index.js | |
| // | |
| const plugins = { | |
| stack: [], | |
| use: (plugin) => { | |
| plugins.stack.push(plugin); | |
| }, | |
| run: async (done) => { |
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
| const fillArrayWithIndex = (length) => { | |
| return Array.from(Array(length).keys()); | |
| } | |
| const fillArray = (start, end) => { | |
| return Array.from(Array(end - start + 1).keys()).map((v)=>v+start); | |
| } | |
| const fillArrayWithStep = (start, end, step=1) => { | |
| return Array.from(Array(end - start + step).keys()).map((v)=>v+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
| const schedule = (() => { | |
| const taskQueue = []; | |
| const runTask = () => { | |
| while (taskQueue.length > 0) { | |
| const task = taskQueue.shift(); | |
| task(); | |
| } | |
| }; | |
| const isArray = (obj) => { | |
| return Object.prototype.toString.call(obj) === "[object 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
| const defProp = (obj, name, value) => { | |
| obj[name] = value; | |
| }; | |
| const isThenable = (value) => { | |
| return value && typeof value.then === "function"; | |
| }; | |
| const State = { | |
| Pending: "Pending", | |
| Fullfill: "Fullfill", | |
| Reject: "Reject", |
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
| const memo = (fun) => { | |
| let lastArgs = []; | |
| let lastResult; | |
| return (...args) => { | |
| let argsEqual = true; | |
| for (let i = 0; i < args.length; i++) { | |
| if (args[i] !== lastArgs[i]) { | |
| argsEqual = false; | |
| break; | |
| } |
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
| const downloadFile = (data, fileName, type = 'text/plain') => { | |
| const a = document.createElement('a'); | |
| a.style.display = 'none'; | |
| document.body.appendChild(a); | |
| a.href = window.URL.createObjectURL(new Blob([data], { type })); | |
| a.setAttribute('download', fileName); | |
| a.click(); | |
| setTimeout(()=>{ | |
| document.body.removeChild(a); | |
| }) |
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 operation(num) { | |
| console.log(num); | |
| } | |
| const applyMiddleware = (...middlewares) => { | |
| return (next) => (...args) => { | |
| (middlewares || []).forEach(function(middleware) { | |
| middleware(next)(...args); | |
| }); | |
| }; |
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 removeDup(arr){ | |
| return [...new Set(arr)]; | |
| } | |
| function removeDup(arr){ | |
| return Array.from(new Set(arr)); | |
| } | |
| function removeDup(arr){ |