Skip to content

Commit

Permalink
/ui: added PLATFORM constant and isPlatformIn() function (#597)
Browse files Browse the repository at this point in the history
closes #596
  • Loading branch information
saabi authored Dec 9, 2022
1 parent 29decbd commit e00e3df
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- added `HighlightedText.svelte`
- added `CopyToClipboard.svelte`
- added `ScrollbarStyler.svelte`
- added `PLATFORM` and `isPlatformIn(oses, browsers)`

## `@svizzle/site` v0.4.1 (next)

Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/components/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- added `HighlightedText.svelte`
- added `CopyToClipboard.svelte`
- added `ScrollbarStyler.svelte`
- added `PLATFORM` and `isPlatformIn(oses, browsers)`

## `@svizzle/ui` v0.8.0

Expand Down
1 change: 1 addition & 0 deletions packages/components/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@macfja/svelte-persistent-store": "^2.1.0",
"@svizzle/dom": "^0.7.0",
"@svizzle/utils": "^0.18.0",
"bowser": "^2.11.0",
"just-compare": "^2.2.2",
"uid": "^2.0.0"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/components/ui/src/utils/env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import Bowser from 'bowser';

export const isServerSide = typeof window === 'undefined';

export const isClientSide = !isServerSide;

export const PLATFORM = isClientSide
? {...Bowser.parse(window.navigator.userAgent)}
: null;

export const isPlatformIn = (oses, browsers) => isClientSide
&& oses.includes(PLATFORM?.os.name)
&& browsers.includes(PLATFORM?.browser.name);

0 comments on commit e00e3df

Please sign in to comment.