@folklore/utils 0.1.4 → 0.1.6
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/dist/index.d.ts +12 -0
- package/dist/{es.js → index.js} +5 -4
- package/package.json +16 -7
- package/dist/cjs.js +0 -48
package/dist/index.d.ts
ADDED
|
@@ -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 };
|
package/dist/{es.js → index.js}
RENAMED
|
@@ -21,11 +21,12 @@ function isTouchScreen() {
|
|
|
21
21
|
if (typeof navigator === 'undefined') {
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
+
const typedNavigator = navigator;
|
|
24
25
|
let hasTouchScreen = false;
|
|
25
|
-
if ('maxTouchPoints' in
|
|
26
|
-
hasTouchScreen =
|
|
27
|
-
} else if ('msMaxTouchPoints' in
|
|
28
|
-
hasTouchScreen =
|
|
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.
|
|
3
|
+
"version": "0.1.6",
|
|
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
|
-
"
|
|
32
|
-
"module": "dist/
|
|
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
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
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": "
|
|
55
|
+
"gitHead": "d1ea3212d18c8203657536bc2b80caeb284403e2"
|
|
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;
|