Skip to content
Open
Show file tree
Hide file tree
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 Jun 22, 2025
9131eef
refactor: remove old functions
jin-sir Jun 22, 2025
82a4a25
refactor: rename browserCheck to checkBrowserSupport
jin-sir Jun 22, 2025
9963d6a
refactor: improve copy
jin-sir Jun 22, 2025
5f4b0bd
refactor: rename downLoadData to downloadFile
jin-sir Jun 22, 2025
58a28e5
refactor: rename convertBytes to formatBytes
jin-sir Jun 22, 2025
49bc19b
refactor: rename dateTime to formatDateTime
jin-sir Jun 22, 2025
492de08
feat: add formatSecond
jin-sir Jun 22, 2025
7157840
feat: add formatBase64
jin-sir Jun 22, 2025
bc628b4
refactor: rename generateFullUrlPath to generateUrlWithQuery
jin-sir Jun 22, 2025
ee4e777
refactor: merge generateAKey and getRandomStr into getKey
jin-sir Jun 22, 2025
8530435
refactor: improve getQueryParameters
jin-sir Jun 22, 2025
5cff92d
feat: add getTypeOfValue
jin-sir Jun 22, 2025
56ba7cc
refactor: improve isMacOS
jin-sir Jun 22, 2025
1705964
refactor: improve isMobile
jin-sir Jun 22, 2025
8df8b0e
refactor: improve isWindows
jin-sir Jun 22, 2025
d8eb0bd
refactor: localDB.set support batch set, localDB.clear support except…
jin-sir Jun 22, 2025
d35ca34
refactor: improve LocalIndexedDB
jin-sir Jun 22, 2025
1744d5b
feat: add sessionDB
jin-sir Jun 22, 2025
3166fec
feat: add shouldRender
jin-sir Jun 22, 2025
c20cf9d
refactor: merge getBase64 and base64Encode into toBase64
jin-sir Jun 22, 2025
a2774db
refactor: rename percent to toPercent
jin-sir Jun 22, 2025
4dea50d
refactor: rename exchangeOrder to toSortOrder
jin-sir Jun 22, 2025
20c180a
refactor: rename getThousandth to toThousand
jin-sir Jun 22, 2025
fb7148e
feat: add unit testing
jin-sir Jun 22, 2025
3f9cee2
chore: add entry file
jin-sir Jun 22, 2025
f5e2bf1
chore: remove docs
jin-sir Jun 22, 2025
44587fe
refactor: build site with VitePress and generate documentation using …
jin-sir Jun 22, 2025
2e8f0a5
chore: add docs:deploy script
jin-sir Jun 22, 2025
b766ac0
chore: replace yarn with pnpm
jin-sir Jul 29, 2025
2aa1db3
refactor: rename LocalIndexedDB to IndexedDB
jin-sir Aug 6, 2025
853ef05
refactor: improve code
jin-sir Aug 6, 2025
00c11ed
chore: translate English comments to Chinese
jin-sir Aug 8, 2025
c80bde9
chore: update project configuration and set TypeScript package version
jin-sir Aug 8, 2025
698f9d0
chore: update docs
jin-sir Aug 8, 2025
77ce923
Merge remote-tracking branch 'origin/master' into feat_utils
jin-sir Aug 8, 2025
94aba92
chore: replace yarn with pnpm
jin-sir Aug 8, 2025
fb73a55
refactor: rename getKey to generateUniqueId
jin-sir Aug 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/isMacOS/__test__/index.test.ts
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);
});
});
31 changes: 31 additions & 0 deletions src/isMacOS/index.ts
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';
Copy link
Collaborator

Choose a reason for hiding this comment

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

image image

Mac 和 Windows 都需要实际测一下,目前这里判断 name === 'macos' 是不对的
image

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

};

export default isMacOS;