diff --git a/.github/workflows/automation.yaml b/.github/workflows/automation.yaml
index a231368..6e11999 100644
--- a/.github/workflows/automation.yaml
+++ b/.github/workflows/automation.yaml
@@ -10,12 +10,12 @@ jobs:
strategy:
matrix:
- node-version: [16.x]
+ node-version: [24.x]
registry-url: ['https://registry.npmjs.org']
steps:
- - uses: actions/checkout@v2
- - uses: actions/setup-node@v2
+ - uses: actions/checkout@v4
+ - uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
registry-url: ${{ matrix.registry-url }}
diff --git a/README.md b/README.md
index 084cce8..ed7b080 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,60 @@
-# os-check
+# os-check [![NPM Downloads][downloads-image]][downloads-url]
-here : https://www.npmjs.com/package/os-check
+[downloads-image]: https://img.shields.io/npm/dm/os-check.svg
+[downloads-url]: https://npmcharts.com/compare/os-check?minimal=true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+NPM : https://www.npmjs.com/package/os-check
```
npm install os-check
yarn add os-check
```
+
+## Code
+ - codesandbox: https://codesandbox.io/s/os-check-example-hro7y6?file=/src/App.tsx
+ - Usage:
+ ```
+ import React, { useEffect } from "react";
+
+import { osCheck, OsType } from "os-check";
+
+const App = () => {
+ useEffect(() => {
+ // only for testing purposes
+ // alert(osCheck())
+ }, []);
+ return (
+
+
{osCheck()}
+ {osCheck() === OsType.Windows && "Windows-hmmm"}
+ {osCheck() === OsType.Linux && "Linux-hmmm"}
+
+ );
+};
+
+export default App;
+ ```
diff --git a/index.ts b/index.ts
index d8baba1..fbaf122 100644
--- a/index.ts
+++ b/index.ts
@@ -1,12 +1,31 @@
+/**
+ * Enumeration for different types of operating systems.
+ */
enum OsType {
- MacOS,
- iOS,
- Windows,
- Android,
- Linux,
- Others,
+ MacOS = "MacOS",
+ iOS = "iOS",
+ Windows = "Windows",
+ Android = "Android",
+ Linux = "Linux",
+ Others = "Others OS",
}
+/**
+ * Determines the operating system of the user's device.
+ * It uses the navigator's user agent and platform information to identify the OS.
+ *
+ * @returns {OsType} The detected type of operating system.
+ *
+ * @example
+ * import { osCheck, OsType } from "os-check";
+ *
+ * const userOS = osCheck();
+ * console.log(`The user's operating system is: ${userOS}`);
+ *
+ * @note
+ * - This function may not be accurate in all cases, as the user agent can be spoofed.
+ * - It covers major operating systems but might not detect all existing or future OS types.
+ */
const osCheck = (): OsType => {
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
@@ -33,3 +52,5 @@ const osCheck = (): OsType => {
}
return OsType.Others;
};
+
+export { osCheck, OsType };
diff --git a/lib/index.d.ts b/lib/index.d.ts
deleted file mode 100644
index 33900cb..0000000
--- a/lib/index.d.ts
+++ /dev/null
@@ -1 +0,0 @@
-declare const osCheck: () => "Mac OS" | "iOS" | "Windows" | "Android" | "Linux" | undefined;
diff --git a/lib/index.js b/lib/index.js
deleted file mode 100644
index 27f9f66..0000000
--- a/lib/index.js
+++ /dev/null
@@ -1,23 +0,0 @@
-"use strict";
-const osCheck = () => {
- const userAgent = window.navigator.userAgent;
- const platform = window.navigator.platform;
- const macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K', 'darwin'];
- const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'];
- const iosPlatforms = ['iPhone', 'iPad', 'iPod'];
- if (macosPlatforms.indexOf(platform) !== -1) {
- return 'Mac OS';
- }
- else if (iosPlatforms.indexOf(platform) !== -1) {
- return 'iOS';
- }
- else if (windowsPlatforms.indexOf(platform) !== -1) {
- return 'Windows';
- }
- else if (/Android/.test(userAgent)) {
- return 'Android';
- }
- else if (/Linux/.test(platform)) {
- return 'Linux';
- }
-};
diff --git a/package.json b/package.json
index 3770f98..b7a979e 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
"name": "os-check",
- "version": "2.1.0",
+ "version": "2.5.0",
"description": "Check OS of the host system",
- "main": "index.ts",
+ "main": "lib/index.js",
"scripts": {
"prepare": "npm run build",
"build": "tsc"