@folklore/utils 0.1.2 → 0.1.3

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.
Files changed (3) hide show
  1. package/dist/cjs.js +25 -0
  2. package/dist/es.js +25 -1
  3. package/package.json +2 -2
package/dist/cjs.js CHANGED
@@ -21,5 +21,30 @@ function getDisplayName(_ref) {
21
21
  return displayName || name || 'Component';
22
22
  }
23
23
 
24
+ function isTouchScreen() {
25
+ if (typeof navigator === 'undefined') {
26
+ return null;
27
+ }
28
+ let hasTouchScreen = false;
29
+ if ('maxTouchPoints' in navigator) {
30
+ hasTouchScreen = navigator.maxTouchPoints > 0;
31
+ } else if ('msMaxTouchPoints' in navigator) {
32
+ hasTouchScreen = navigator.msMaxTouchPoints > 0;
33
+ } else {
34
+ const mQ = matchMedia?.('(pointer:coarse)');
35
+ if (mQ?.media === '(pointer:coarse)') {
36
+ hasTouchScreen = !!mQ.matches;
37
+ } else if ('orientation' in window) {
38
+ hasTouchScreen = true; // deprecated, but good fallback
39
+ } else {
40
+ // Only as a last resort, fall back to user agent sniffing
41
+ const UA = navigator.userAgent;
42
+ hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
43
+ }
44
+ }
45
+ return hasTouchScreen;
46
+ }
47
+
24
48
  exports.getComponentFromName = getComponentFromName;
25
49
  exports.getDisplayName = getDisplayName;
50
+ exports.isTouchScreen = isTouchScreen;
package/dist/es.js CHANGED
@@ -19,4 +19,28 @@ function getDisplayName(_ref) {
19
19
  return displayName || name || 'Component';
20
20
  }
21
21
 
22
- export { getComponentFromName, getDisplayName };
22
+ function isTouchScreen() {
23
+ if (typeof navigator === 'undefined') {
24
+ return null;
25
+ }
26
+ let hasTouchScreen = false;
27
+ if ('maxTouchPoints' in navigator) {
28
+ hasTouchScreen = navigator.maxTouchPoints > 0;
29
+ } else if ('msMaxTouchPoints' in navigator) {
30
+ hasTouchScreen = navigator.msMaxTouchPoints > 0;
31
+ } else {
32
+ const mQ = matchMedia?.('(pointer:coarse)');
33
+ if (mQ?.media === '(pointer:coarse)') {
34
+ hasTouchScreen = !!mQ.matches;
35
+ } else if ('orientation' in window) {
36
+ hasTouchScreen = true; // deprecated, but good fallback
37
+ } else {
38
+ // Only as a last resort, fall back to user agent sniffing
39
+ const UA = navigator.userAgent;
40
+ hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
41
+ }
42
+ }
43
+ return hasTouchScreen;
44
+ }
45
+
46
+ export { getComponentFromName, getDisplayName, isTouchScreen };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Utilities",
5
5
  "keywords": [
6
6
  "javascript",
@@ -43,5 +43,5 @@
43
43
  "lodash": "^4.17.4",
44
44
  "pascal-case": "^3.1.2"
45
45
  },
46
- "gitHead": "c13ef70b8126b3182b3e3365f34f9231fa9b1535"
46
+ "gitHead": "5e58b1aa0d9aeb6eb7caaaac538357d3285909b9"
47
47
  }