Skip to content

feat(dt-utils): refactor the dt-utils #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: master
Choose a base branch
from

Conversation

jin-sir
Copy link
Collaborator

@jin-sir jin-sir commented Jun 22, 2025

变更类型

请选择以下选项以描述 PR 的类型:

  • Bug 修复(修复现有问题)
  • 新功能(添加了一个功能)
  • 代码优化(性能改进、代码重构)
  • 文档更新
  • 单测新增或修改
  • 其他(请说明):

相关问题

变更内容

优化

  • browserCheck
    • 更名 checkBrowserSupport
    • 使用 ua-parser-js 获取浏览器信息
    • 版本对比精确到小版本
  • copy
    • 使用 Promise 替换 callback
    • 优先使用 navigator.clipboard
  • downLoadData
    • 更名 downloadFile
    • 使用 Promise 替换 callback,且将 Response 作为参数传递
  • convertBytes
    • 更名 formatBytes
    • 新增 decimals 参数,控制小数位数
    • 优化计算逻辑
  • generateAKey、getRandomStr
    • 合并并命名为 getKey
    • 使用 nanoid 生成 key
  • generateFullUrlPath
    • 更名 generateUrlWithQuery
    • 新增 object 和 array 参数的处理:将对象转换为 JSON 字符串
  • getQueryParameters
    • 兼容 generateFullUrlPath ,新增 object 和 array 的解析
  • isMacOs
    • 更名 isMacOS
    • 使用 ua-parser-js 判断
  • isWindows
    • 使用 ua-parser-js 判断
  • isMobileDevice
  • localDB
    • set 支持批量添加
    • clear 支持保留部分 key
  • dateTime
    • 删除 dateTime 中的所有函数,新增 formatDateTime
    • formatDateTime 支持将传入的时间根据传入的格式进行格式化
    • 同时提供 DayjsFormat 枚举,其中包含了常见的时间格式,方便使用
  • getBase64、base64Encode
    • 合并为 toBase64
    • 非文件使用 js-base64 进行编码
  • percent
    • 更名 toPercent
    • 放开最大值 1 的限制
  • exchangeOrder
    • 更名 toSortOrder
  • getThousandth
    • 更名 toThousand

新增

  • formatSecond
    • 格式化秒数:3661 -> 1h1m1s
  • formatBase64
    • 从 js-base64 导出,解码 base64 字符串
  • getTypeOfValue
    • 获取传入的值的类型
  • sessionDB
    • 功能同 localDB

对应 Previewer

https://jin-sir.github.io/dt-utils/

@jin-sir jin-sir requested a review from liuxy0551 June 23, 2025 02:58
@jin-sir jin-sir requested a review from LuckyFBB June 25, 2025 08:10
Copy link
Contributor

@LuckyFBB LuckyFBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档里面 github icon 的链接能否设置为 dt-utils 的 github 链接

* generateUrlWithQuery('/api/data', { id: 123, name: null, status: undefined }) // => '/api/data?id=123'
* ```
*/
const generateUrlWithQuery = (pathname: string, queryParams: QueryParams = {}): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildQueryUrl
formatUrlWithParams
appendQueryToUrl

这几个命名如何

* getKey(5) // => "a4b2x"
* ```
*/
const getKey = (size: number): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会不会太简单了,太宽泛了。
generateUniqueId 这个如何?

* getTypeOfValue(new Set()); // => 'set'
* ```
*/
const getTypeOfValue = (value: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比 typeof 强点,要不直接叫 typeof吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants