@ouroboros/browser 0.5.2 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  # @ouroboros/browser
2
-
3
2
  [![npm version](https://img.shields.io/npm/v/@ouroboros/browser.svg)](https://www.npmjs.com/package/@ouroboros/browser) ![MIT License](https://img.shields.io/npm/l/@ouroboros/browser.svg)
4
3
 
5
4
  A library of classes to manage functionality in browsers.
@@ -24,7 +23,7 @@ or
24
23
  import { clipboard } from '@ouroboros/browser';
25
24
  ```
26
25
 
27
- copy()
26
+ `clipboard.copy()`
28
27
 
29
28
  ## cookies
30
29
 
@@ -40,7 +39,23 @@ or
40
39
  import { cookies } from '@ouroboros/browser';
41
40
  ```
42
41
 
43
- get(), remove(), set()
42
+ `get()`, `remove()`, `set()`
43
+
44
+ ## devices
45
+
46
+ Import Devices into your code
47
+
48
+ ```javascript
49
+ import devices, { hasPointer, isMobile } from '@ouroboros/browser/devices';
50
+ ```
51
+
52
+ or
53
+
54
+ ```javascript
55
+ import { devices } from '@ouroboros/browser';
56
+ ```
57
+
58
+ `devices.hasPointer()`
44
59
 
45
60
  ## hash
46
61
 
@@ -56,7 +71,7 @@ or
56
71
  import { hash } from '@ouroboros/browser';
57
72
  ```
58
73
 
59
- get(), set(), subscribe(), unsubscribe()
74
+ `hash.get()`, `hash.set()`, `hash.subscribe()`, `hash.unsubscribe()`
60
75
 
61
76
  ## network
62
77
 
@@ -72,7 +87,7 @@ or
72
87
  import { network } from '@ouroboros/browser';
73
88
  ```
74
89
 
75
- default (Subscribe)
90
+ default (`Subscribe`)
76
91
 
77
92
  ## pageVisibility
78
93
 
@@ -88,7 +103,7 @@ or
88
103
  import { pageVisibility } from '@ouroboros/browser';
89
104
  ```
90
105
 
91
- default (Subscribe)
106
+ default (`Subscribe`)
92
107
 
93
108
  ## safeLocalStorage
94
109
 
@@ -104,7 +119,7 @@ or
104
119
  import { safeLocalStorage } from '@ouroboros/browser';
105
120
  ```
106
121
 
107
- bool(), json(), string()
122
+ `safeLocalStorage.bool()`, `safeLocalStorage.json()`, `safeLocalStorage.string()`
108
123
 
109
124
  ## size
110
125
 
@@ -120,4 +135,4 @@ or
120
135
  import { size } from '@ouroboros/browser';
121
136
  ```
122
137
 
123
- size (Subscribe), compare(), greaterThan(), lessThan()
138
+ default (`Subscribe`), `size.compare()`, `size.greaterThan()`, `size.lessThan()`
package/devices.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Device
3
+ *
4
+ * Functions for getting device information
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2025-04-16
9
+ */
10
+ /**
11
+ * Has Pointer
12
+ *
13
+ * Returns true only if the device has some sort of pointer device like a mouse.
14
+ *
15
+ * @name hasPointer
16
+ * @access public
17
+ * @returns bool
18
+ */
19
+ export declare function hasPointer(): boolean;
20
+ /**
21
+ * Is Mobile
22
+ *
23
+ * Returns true only if the device appears to be a mobile device, but does not
24
+ * gaurantee anything.
25
+ *
26
+ * @name isMobile
27
+ * @access public
28
+ * @returns bool
29
+ */
30
+ export declare function isMobile(): boolean;
31
+ declare const devices: {
32
+ hasPointer: typeof hasPointer;
33
+ isMobile: typeof isMobile;
34
+ };
35
+ export default devices;
package/devices.js ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Device
3
+ *
4
+ * Functions for getting device information
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2025-04-16
9
+ */
10
+ /**
11
+ * Has Pointer
12
+ *
13
+ * Returns true only if the device has some sort of pointer device like a mouse.
14
+ *
15
+ * @name hasPointer
16
+ * @access public
17
+ * @returns bool
18
+ */
19
+ export function hasPointer() {
20
+ return window.matchMedia("(any-hover: hover)").matches;
21
+ }
22
+ /**
23
+ * Is Mobile
24
+ *
25
+ * Returns true only if the device appears to be a mobile device, but does not
26
+ * gaurantee anything.
27
+ *
28
+ * @name isMobile
29
+ * @access public
30
+ * @returns bool
31
+ */
32
+ export function isMobile() {
33
+ // Mobile regex
34
+ const reMobile = /iPhone|Android.*Mobile|Mobile.*Android|KaiOS/i;
35
+ // If any of the following fail, we are probably on desktop
36
+ if (!reMobile.test(navigator.userAgent)
37
+ || !('ontouchstart' in window)
38
+ || !('orientation' in window)
39
+ || window.innerWidth >= 768) {
40
+ // Not a mobile device
41
+ return false;
42
+ }
43
+ // Probably a mobile device
44
+ return true;
45
+ }
46
+ // Default export
47
+ const devices = { hasPointer, isMobile };
48
+ export default devices;
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as clipboard } from './clipboard';
2
2
  export { default as cookies } from './cookies';
3
+ export { default as devices } from './devices';
3
4
  export { default as hash } from './hash';
4
5
  export { default as network } from './network';
5
6
  export { default as pageVisibility } from './pageVisibility';
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as clipboard } from './clipboard';
2
2
  export { default as cookies } from './cookies';
3
+ export { default as devices } from './devices';
3
4
  export { default as hash } from './hash';
4
5
  export { default as network } from './network';
5
6
  export { default as pageVisibility } from './pageVisibility';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ouroboros/browser",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "Package to handle common browser functionality.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@ouroboros/clone": "^1.1.0",
40
- "@ouroboros/subscribe": "^1.3.1",
41
- "@ouroboros/tools": "^0.6.1"
40
+ "@ouroboros/subscribe": "^1.3.2",
41
+ "@ouroboros/tools": "^0.7.1"
42
42
  }
43
43
  }
package/src/devices.ts ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Device
3
+ *
4
+ * Functions for getting device information
5
+ *
6
+ * @author Chris Nasr <chris@ouroboroscoding.com>
7
+ * @copyright Ouroboros Coding Inc.
8
+ * @created 2025-04-16
9
+ */
10
+
11
+ /**
12
+ * Has Pointer
13
+ *
14
+ * Returns true only if the device has some sort of pointer device like a mouse.
15
+ *
16
+ * @name hasPointer
17
+ * @access public
18
+ * @returns bool
19
+ */
20
+ export function hasPointer(): boolean {
21
+ return window.matchMedia("(any-hover: hover)").matches
22
+ }
23
+
24
+ /**
25
+ * Is Mobile
26
+ *
27
+ * Returns true only if the device appears to be a mobile device, but does not
28
+ * gaurantee anything.
29
+ *
30
+ * @name isMobile
31
+ * @access public
32
+ * @returns bool
33
+ */
34
+ export function isMobile(): boolean {
35
+
36
+ // Mobile regex
37
+ const reMobile = /iPhone|Android.*Mobile|Mobile.*Android|KaiOS/i;
38
+
39
+ // If any of the following fail, we are probably on desktop
40
+ if(!reMobile.test(navigator.userAgent)
41
+ || !('ontouchstart' in window)
42
+ || !('orientation' in window)
43
+ || window.innerWidth >= 768) {
44
+
45
+ // Not a mobile device
46
+ return false;
47
+ }
48
+
49
+ // Probably a mobile device
50
+ return true;
51
+ }
52
+
53
+ // Default export
54
+ const devices = { hasPointer, isMobile }
55
+ export default devices;
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as clipboard } from './clipboard';
2
2
  export { default as cookies } from './cookies';
3
+ export { default as devices } from './devices';
3
4
  export { default as hash } from './hash';
4
5
  export { default as network } from './network';
5
6
  export { default as pageVisibility } from './pageVisibility';