Skip to content

Commit

Permalink
Merge pull request #3 from healerlab/feature/docs
Browse files Browse the repository at this point in the history
fix: navigator is not defined
  • Loading branch information
HealerNguyen committed Nov 19, 2023
2 parents 599f93a + 8ba7913 commit 909a69d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
{ text: 'Home', link: '/' },
{ text: 'Get Started', link: '/usage-examples' },
{
text: '0.0.3',
text: '0.0.4',
items: [
{
text: 'Changelog',
Expand Down
8 changes: 8 additions & 0 deletions docs/usage-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,11 @@ This module uses [crawler-user-agents](https://github.com/monperrus/crawler-user

## Note
This module inspired by [@nuxtjs/device](https://github.com/nuxt-modules/device) module

<script setup>
import pkg from "@healerlab/device-js"
const {detectDevice} = pkg
</script>
<div>
{{ detectDevice }}
</div>
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@healerlab/device-js",
"private": false,
"version": "0.0.3",
"version": "0.0.4",
"description": "Powerful, lightweight device detector module",
"main": "./dist/h-device.umd.cjs",
"module": "./dist/h-device.js",
Expand Down Expand Up @@ -49,5 +49,8 @@
"repository": {
"type": "git",
"url": "https://github.com/healerlab/device-js.git"
},
"dependencies": {
"@healerlab/device-js": "^0.0.4"
}
}
4 changes: 3 additions & 1 deletion src/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const generateDevice = (headers: any, userAgent: string): Device => {
}
}

const deviceInfo = generateDevice({}, navigator.userAgent) as Device
const userAgent = typeof window !== 'undefined' ? navigator.userAgent : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Safari/537.36'

const deviceInfo = generateDevice({}, userAgent) as Device


export const detectDevice = deviceInfo
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@
resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.19.5.tgz#faad84c41ba12e3a0acb52571df9bff37bee75f6"
integrity sha512-czTrygUsB/jlM8qEW5MD8bgYU2Xg14lo6kBDXW6HdxKjh8M5PzETGiSHaz9MtbXBYDloHNUAUW2tMiKW4KM9Mw==

"@healerlab/device-js@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@healerlab/device-js/-/device-js-0.0.4.tgz#ec63379e907bd99b65e3cdcf5eb814b893978466"
integrity sha512-3h7RVFEDmVd6Lv9G0ipXCt3RPRpr1mw7TlR0eifYLrjZ5qmTbbKKcGqqlZ+WIf0XVEjHMTaWa+lxW16IWXgJVA==

"@jridgewell/sourcemap-codec@^1.4.15":
version "1.4.15"
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32"
Expand Down

0 comments on commit 909a69d

Please sign in to comment.