From 4ff5c005601117fee585ec2d04706172c9b4a969 Mon Sep 17 00:00:00 2001 From: luk Date: Sat, 3 Aug 2024 14:23:27 +0800 Subject: [PATCH] added methods `has_module` and `segment_number` --- coretool.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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, ' ') + }, }