/*
* @Author: AlexFun
* @Date: 2021-05-11 18:47:08
* @LastEditors: AlexFun
* @LastEditTime: 2021-05-11 22:03:48
* @Description: 常用公共类
*/
import util from 'util'
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import mongoose from 'mongoose'
//常用公共方法类
export default class Utils{
//递归创建文件夹
public static mkdirsSync(filePath: string) {
if (fs.existsSync(path.dirname(filePath))) return true;
if (this.mkdirsSync(path.dirname(filePath))) {
fs.mkdirSync(filePath);
return true;
}
}
/**
* 获得内容的hash值
*
* @param {String} content 文件内容
* @param {String} encoding 文件的编码,例如:'utf8' 等
* @param {String} type hash算法,例如:'md5'、'sha1'、'sha256'、'sha512' 等
* @returns {String}
* @author AlexFun
* @date 2021-05-13 11:13:24
*/
public static getHash(content: string,encoding: any,type: string){
return crypto.createHash(type).update(content,encodi
【node,ts】后端开发常用公共方法(不定期更新)
最新推荐文章于 2025-05-15 15:51:10 发布