@folklore/utils 0.1.4 → 0.1.7

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.
@@ -0,0 +1,12 @@
1
+ type ComponentsMap = Record<string, unknown>;
2
+ declare function getComponentFromName(components: ComponentsMap, name: string | null, defaultComponentName?: string | unknown): unknown;
3
+
4
+ type DisplayNameInput = {
5
+ displayName?: string | null;
6
+ name?: string | null;
7
+ };
8
+ declare function getDisplayName({ displayName, name, }: DisplayNameInput): string;
9
+
10
+ declare function isTouchScreen(): boolean | null;
11
+
12
+ export { getComponentFromName, getDisplayName, isTouchScreen };
@@ -18,14 +18,15 @@ function getDisplayName({
18
18
  }
19
19
 
20
20
  function isTouchScreen() {
21
- if (typeof navigator === 'undefined') {
21
+ if (typeof window === 'undefined' || typeof navigator === 'undefined') {
22
22
  return null;
23
23
  }
24
+ const typedNavigator = navigator;
24
25
  let hasTouchScreen = false;
25
- if ('maxTouchPoints' in navigator) {
26
- hasTouchScreen = navigator.maxTouchPoints > 0;
27
- } else if ('msMaxTouchPoints' in navigator) {
28
- hasTouchScreen = navigator.msMaxTouchPoints > 0;
26
+ if ('maxTouchPoints' in typedNavigator) {
27
+ hasTouchScreen = typedNavigator.maxTouchPoints > 0;
28
+ } else if ('msMaxTouchPoints' in typedNavigator) {
29
+ hasTouchScreen = (typedNavigator.msMaxTouchPoints || 0) > 0;
29
30
  } else {
30
31
  const mQ = matchMedia?.('(pointer:coarse)');
31
32
  if (mQ?.media === '(pointer:coarse)') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@folklore/utils",
3
- "version": "0.1.4",
3
+ "version": "0.1.7",
4
4
  "description": "Utilities",
5
5
  "keywords": [
6
6
  "javascript",
@@ -28,20 +28,29 @@
28
28
  "email": "nrb@folklore.email"
29
29
  }
30
30
  ],
31
- "main": "dist/cjs.js",
32
- "module": "dist/es.js",
31
+ "type": "module",
32
+ "module": "dist/index.js",
33
+ "types": "dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "default": "./dist/index.js",
37
+ "types": "./dist/index.d.ts"
38
+ }
39
+ },
33
40
  "files": [
34
41
  "dist"
35
42
  ],
36
43
  "scripts": {
37
- "clean": "rm -rf dist",
38
- "build": "rollup --bundleConfigAsCjs --config ../../rollup.config.js",
39
- "prepublishOnly": "npm run clean && npm run build"
44
+ "build": "../../scripts/prepare-package.sh --types",
45
+ "prepublishOnly": "npm run build"
46
+ },
47
+ "publishConfig": {
48
+ "access": "public"
40
49
  },
41
50
  "dependencies": {
42
51
  "@babel/runtime": "^7.4.3",
43
52
  "lodash": "^4.17.4",
44
53
  "pascal-case": "^3.1.2"
45
54
  },
46
- "gitHead": "a04cfaacb364f3b35307d65d8778b078dace4491"
55
+ "gitHead": "86b75a50a42c09a0c0868f53e2d1edf270f86229"
47
56
  }
package/dist/cjs.js DELETED
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- var isString = require('lodash/isString');
4
- var pascalCase = require('pascal-case');
5
-
6
- function getComponentFromName(components, name, defaultComponentName = null) {
7
- const defaultComponent = (isString(defaultComponentName) ? components[pascalCase.pascalCase(defaultComponentName)] : defaultComponentName) || null;
8
- if (name === null) {
9
- return defaultComponent;
10
- }
11
- const componentName = pascalCase.pascalCase(name);
12
- return components[componentName] || defaultComponent;
13
- }
14
-
15
- function getDisplayName({
16
- displayName = null,
17
- name = null
18
- }) {
19
- return displayName || name || 'Component';
20
- }
21
-
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
- exports.getComponentFromName = getComponentFromName;
47
- exports.getDisplayName = getDisplayName;
48
- exports.isTouchScreen = isTouchScreen;