added methods has_module and segment_number

This commit is contained in:
luk 2024-08-03 14:23:27 +08:00
parent 4a61dfa4e2
commit 4ff5c00560

View File

@ -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, ' ')
},
}