8 changed files with 55 additions and 29 deletions
@ -0,0 +1,17 @@ |
|||||
|
|
||||
|
export function reverseString(str){ |
||||
|
return str.split("").reverse().join(""); |
||||
|
} |
||||
|
|
||||
|
export function randomElement(arr){ |
||||
|
return arr[Math.floor(Math.random()*arr.length)]; |
||||
|
} |
||||
|
|
||||
|
export const minutes = 60*1000; |
||||
|
export const hours = 3600*1000; |
||||
|
export const days = 24*hours; |
||||
|
|
||||
|
export function notYet(date){ |
||||
|
if(!date) return false; |
||||
|
return (new Date() <= date); |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
import fs from 'fs'; |
||||
|
import path from 'path'; |
||||
|
import { fileURLToPath } from 'url'; |
||||
|
|
||||
|
const __filename = fileURLToPath(import.meta.url); |
||||
|
const __dirname = path.dirname(__filename); |
||||
|
|
||||
|
function defaultFileFilter(filename){ |
||||
|
return !!filename.match(/\.js$/); |
||||
|
} |
||||
|
|
||||
|
export async function importAll(folder, opts){ |
||||
|
const controllerPaths = ( |
||||
|
fs.readdirSync(path.join(__dirname, '../'+folder)) |
||||
|
.filter(defaultFileFilter) |
||||
|
.map(file => path.join(__dirname, '../'+folder, file)) |
||||
|
); |
||||
|
for (const path of controllerPaths) { |
||||
|
const submodule = await import('file://'+path); |
||||
|
submodule.default(opts); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue