diff --git a/coretool.js b/coretool.js index 03ca2c4..01a5edf 100644 --- a/coretool.js +++ b/coretool.js @@ -1,6 +1,9 @@ /* 基础小工具,可通用于服务端和用户端 */ +const path = require('path') +const fs = require('fs') + module.exports = { BASEPORT_API_SERVER: 7000, BASEPORT_WEB_SERVER: 8000, @@ -359,6 +362,18 @@ module.exports = { delete file.filename delete file.destination return file - } + }, + + has_module (module) { + if (typeof (module) === 'string' && module) { + return module.paths.some(modulesPath => fs.existsSync(path.join(modulesPath, module))) + } else { + return false + } + }, + + segment_number (sizeBytes = '') { // segment a number with a space between each 3 digits + return (sizeBytes).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ' ') + }, }