# utils **Repository Path**: wait-fish/utils ## Basic Information - **Project Name**: utils - **Description**: 工具方法的一个思路 - **Primary Language**: JavaScript - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-10-12 - **Last Updated**: 2025-01-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: TypeScript, JavaScript ## README # utils #### 介绍 1. **TimeOperation类:**操作时间的工具类,持续更新。 2. **StorageOperate对象**:操作session,local,可过期local。 #### 方法 ##### 1.**TimeOperation**类方法 ​ type = ['yyyy-MM-dd','yyyy-MM-dd hh:mm:ss', 'y-M-d', 'y/M/d','y.M.d', 'ww'] 1. `new TimeOperation(date = new Date()) ` 默认当前时间 2. `getOneHour() ` 返回一个小时的毫秒 3. `getOneDay()` 返回半个小时的毫秒 4. `get([yyyy,yy,MM,M,ww,w,dd,d,hh,h,mm,m,s,s])` 返回对应的时间2022 5. `setValue(date)` [“2022-10-12 00:00:00”,Date对象] 6. `call(fnName, [value])` 例:call('setMonth', 2),call('getMonth') 7. `format([type])` 返回格式化时间 8. `getFirstTime([type])` 返回当天最早时间 9. `getLastTime`([type]) 返回 当天最后时间 10. `getMonthFirstDay([type])` 返回当月第一天 11. `getMonthLastDay([type])` 返回当月最后一天 12. `getAfterMinutes(minutes = 0, [type])` 返回n分钟之后 13. `getAfterHours(hours = 0, [type])` 返回n小时之后 14. `timeDistance(endTime, type = 'd')` [“2022-10-12 00:00:00”,Date对象],type = ['d','h', 'm'] ##### 2.StorageOperate对象方法 ###### 2.1fishSessionStorage对象 1. `fishSessionStorage.get(key)` 2. `fishSessionStorage.set(key, value)` 3. `fishSessionStorage.remove(key)` ###### 2.2 fishLocalStorage对象 1. `fishLocalStorage.get(key)` 2. `fishLocalStorage.set(key, value)` 3. `fishLocalStorage.remove(key)` ###### 2.3 fishExpireLocalStorage可过期对象 1. `fishExpireLocalStorage.get(key)` 2. `fishExpireLocalStorage.set(key, value, expire)` expire过期时间ms 3. `fishExpireLocalStorage.remove(key)` ##### 3. TimeDict时间字典 方便设置过期时间使用 ​ 1.`TimeDict.ONEHOUR` 一小时 ​ 2.`TimeDict.ONEDAY` 一天 ​ 3.`TimeDict.ONEMINUTES` 一分钟 ​ 4.`TimeDict.ONESECOND` 一秒 ##### 4.getType 方法 `getType(123)` 返回" Number" 既原型本身类型 ##### 5.fileConversion方法集合 1. `urlToFile(base64)` 2. `blobToFile(blob)` 3. `base64ToFile(base64, file = "file")` 4. `base64ToBlob(base64)` 5. `urlToBlob(httpUrl)` 6. `fileToBlob(file)` 7. `urlToBase64(httpUrl)` 8. `blobToBase64(blob)` 9. `fileTOBase64(file)` 10. `dealImage(base64, targetWidth, (newBase64: string) => string)`图片压缩 11. `fileDownload(file, fileName?)` 12. `blobDownload(blob, fileName?)` 13. `base64Download(base64, fileName?)` 14. `downloadIamge(url, fileName?)` 15. `download(url, fileName?)` ###### 6.htmlEscape 转义 1. `htmlToEscape(sHtml)` HTML转字符串 2. `escapeToHtml(str)` 转义字符串转HTML ###### 7. 深拷贝 1. `jsonDeepClone(jsonStructureObject, [(k,v) => {}], [indentation])` json对象深拷贝 2. `deepClone(obj)` 自实现深拷贝 ###### 8.zoom 屏幕缩放 1. `detectZoom()` 检查比例 2. `setZoom()` 检查并设置比例