-
Notifications
You must be signed in to change notification settings - Fork 17
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
jin-sir
wants to merge
38
commits into
DTStack:master
Choose a base branch
from
jin-sir:feat_utils
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
50d84ab
chore: upgrade package & replace packaging tools
jin-sir 9131eef
refactor: remove old functions
jin-sir 82a4a25
refactor: rename browserCheck to checkBrowserSupport
jin-sir 9963d6a
refactor: improve copy
jin-sir 5f4b0bd
refactor: rename downLoadData to downloadFile
jin-sir 58a28e5
refactor: rename convertBytes to formatBytes
jin-sir 49bc19b
refactor: rename dateTime to formatDateTime
jin-sir 492de08
feat: add formatSecond
jin-sir 7157840
feat: add formatBase64
jin-sir bc628b4
refactor: rename generateFullUrlPath to generateUrlWithQuery
jin-sir ee4e777
refactor: merge generateAKey and getRandomStr into getKey
jin-sir 8530435
refactor: improve getQueryParameters
jin-sir 5cff92d
feat: add getTypeOfValue
jin-sir 56ba7cc
refactor: improve isMacOS
jin-sir 1705964
refactor: improve isMobile
jin-sir 8df8b0e
refactor: improve isWindows
jin-sir d8eb0bd
refactor: localDB.set support batch set, localDB.clear support except…
jin-sir d35ca34
refactor: improve LocalIndexedDB
jin-sir 1744d5b
feat: add sessionDB
jin-sir 3166fec
feat: add shouldRender
jin-sir c20cf9d
refactor: merge getBase64 and base64Encode into toBase64
jin-sir a2774db
refactor: rename percent to toPercent
jin-sir 4dea50d
refactor: rename exchangeOrder to toSortOrder
jin-sir 20c180a
refactor: rename getThousandth to toThousand
jin-sir fb7148e
feat: add unit testing
jin-sir 3f9cee2
chore: add entry file
jin-sir f5e2bf1
chore: remove docs
jin-sir 44587fe
refactor: build site with VitePress and generate documentation using …
jin-sir 2e8f0a5
chore: add docs:deploy script
jin-sir b766ac0
chore: replace yarn with pnpm
jin-sir 2aa1db3
refactor: rename LocalIndexedDB to IndexedDB
jin-sir 853ef05
refactor: improve code
jin-sir 00c11ed
chore: translate English comments to Chinese
jin-sir c80bde9
chore: update project configuration and set TypeScript package version
jin-sir 698f9d0
chore: update docs
jin-sir 77ce923
Merge remote-tracking branch 'origin/master' into feat_utils
jin-sir 94aba92
chore: replace yarn with pnpm
jin-sir fb73a55
refactor: rename getKey to generateUniqueId
jin-sir File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import UAParser from 'ua-parser-js'; | ||
|
|
||
| import isMacOS from '../index'; | ||
|
|
||
| jest.mock('ua-parser-js'); | ||
|
|
||
| describe('isMacOS', () => { | ||
| it('should return true for macOS', () => { | ||
| (UAParser as unknown as jest.Mock).mockImplementation(() => ({ | ||
| getOS: () => ({ name: 'macOS' }), | ||
| })); | ||
|
|
||
| expect(isMacOS()).toBe(true); | ||
| }); | ||
|
|
||
| it('should return false for other OS', () => { | ||
| (UAParser as unknown as jest.Mock).mockImplementation(() => ({ | ||
| getOS: () => ({ name: 'Windows' }), | ||
| })); | ||
|
|
||
| expect(isMacOS()).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import UAParser from 'ua-parser-js'; | ||
|
|
||
| /** | ||
| * Check if the current operating system is macOS. | ||
| * | ||
| * @category Environment Detection | ||
| * @returns {boolean} Returns `true` if running on macOS, `false` otherwise | ||
| * | ||
| * @example | ||
| * ```typescript | ||
| * import { isMacOS } from 'dt-utils'; | ||
| * | ||
| * // Check if current OS is macOS | ||
| * if (isMacOS()) { | ||
| * console.log('Running on macOS'); | ||
| * } else { | ||
| * console.log('Not running on macOS'); | ||
| * } | ||
| * | ||
| * // Direct usage | ||
| * const isOnMac = isMacOS(); // => true/false | ||
| * ``` | ||
| */ | ||
| const isMacOS = (): boolean => { | ||
| const parser = new UAParser(); | ||
| const result = parser.getOS(); | ||
|
|
||
| return result.name === 'macOS'; | ||
| }; | ||
|
|
||
| export default isMacOS; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mac 和 Windows 都需要实际测一下,目前这里判断 name === 'macos' 是不对的

源码:https://github.com/faisalman/ua-parser-js/blob/1.0.x/src/ua-parser.js