@folklore/utils 0.1.1 → 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 +26 -7
  2. package/dist/es.js +25 -1
  3. package/package.json +3 -3
package/dist/cjs.js CHANGED
@@ -1,17 +1,11 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  var isString = require('lodash/isString');
6
4
  var pascalCase = require('pascal-case');
7
5
 
8
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
-
10
- var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
11
-
12
6
  function getComponentFromName(components, name) {
13
7
  let defaultComponentName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
14
- const defaultComponent = (isString__default["default"](defaultComponentName) ? components[pascalCase.pascalCase(defaultComponentName)] : defaultComponentName) || null;
8
+ const defaultComponent = (isString(defaultComponentName) ? components[pascalCase.pascalCase(defaultComponentName)] : defaultComponentName) || null;
15
9
  if (name === null) {
16
10
  return defaultComponent;
17
11
  }
@@ -27,5 +21,30 @@ function getDisplayName(_ref) {
27
21
  return displayName || name || 'Component';
28
22
  }
29
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
+
30
48
  exports.getComponentFromName = getComponentFromName;
31
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.1",
3
+ "version": "0.1.3",
4
4
  "description": "Utilities",
5
5
  "keywords": [
6
6
  "javascript",
@@ -35,7 +35,7 @@
35
35
  ],
36
36
  "scripts": {
37
37
  "clean": "rm -rf dist",
38
- "build": "rollup --config ../../rollup.config.js",
38
+ "build": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
39
39
  "prepare": "npm run clean && npm run build"
40
40
  },
41
41
  "dependencies": {
@@ -43,5 +43,5 @@
43
43
  "lodash": "^4.17.4",
44
44
  "pascal-case": "^3.1.2"
45
45
  },
46
- "gitHead": "c054f8aebebb312df15dbd87158516bbc750855f"
46
+ "gitHead": "5e58b1aa0d9aeb6eb7caaaac538357d3285909b9"
47
47
  }