@applicaster/zapp-react-native-utils 16.0.0-alpha.5652127751 → 16.0.0-alpha.6466900632

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.
@@ -1,40 +1,53 @@
1
- import * as R from "ramda";
2
1
  import { DEFAULT_NAMESPACE } from "../consts";
3
2
  import { KeyName, KeyNameObj } from "../index";
4
3
 
5
- const lastDotRegex = /\.([^.]+)$/;
6
- const splitByLastDot = R.compose(R.init, R.split(lastDotRegex));
7
-
8
4
  export function getNamespaceAndKey(namespacedKey: KeyName): KeyNameObj {
9
5
  if (typeof namespacedKey !== "string") return namespacedKey;
10
6
 
11
- const namespacedKeyProps = namespacedKey.includes(".")
12
- ? splitByLastDot(namespacedKey)
13
- : [DEFAULT_NAMESPACE, namespacedKey];
7
+ if (!namespacedKey.includes(".")) {
8
+ return { namespace: DEFAULT_NAMESPACE, key: namespacedKey };
9
+ }
10
+
11
+ // split on the last dot - the namespace itself may contain dots
12
+ const lastDotIndex = namespacedKey.lastIndexOf(".");
14
13
 
15
- return R.zipObj(["namespace", "key"], namespacedKeyProps);
14
+ return {
15
+ namespace: namespacedKey.slice(0, lastDotIndex),
16
+ key: namespacedKey.slice(lastDotIndex + 1),
17
+ };
16
18
  }
17
19
 
18
- const propIsNotNullOrUndefined = (prop) =>
19
- R.compose(R.not, R.isNil, R.prop(prop));
20
+ const hasOwn = (obj: object, prop: string): boolean =>
21
+ Object.prototype.hasOwnProperty.call(obj, prop);
22
+
23
+ const isEmpty = (value: unknown): boolean => {
24
+ if (typeof value === "string" || Array.isArray(value)) {
25
+ return value.length === 0;
26
+ }
27
+
28
+ if (value !== null && typeof value === "object") {
29
+ return Object.keys(value).length === 0;
30
+ }
31
+
32
+ return false;
33
+ };
34
+
35
+ export const keyIsValid = (parsedKey: unknown): boolean => {
36
+ if (parsedKey == null) return false;
37
+ if (typeof parsedKey === "string") return false;
38
+ if (Array.isArray(parsedKey)) return false;
20
39
 
21
- const propIsNotEmpty = (prop) => R.compose(R.not, R.isEmpty, R.prop(prop));
40
+ const obj = parsedKey as Record<string, unknown>;
22
41
 
23
- export const keyIsValid = R.allPass([
24
- R.compose(R.not, R.isNil),
25
- R.compose(R.not, R.is(String)),
26
- R.compose(R.not, R.is(Array)),
27
- R.has("key"),
28
- R.has("namespace"),
29
- propIsNotNullOrUndefined("key"),
30
- propIsNotNullOrUndefined("namespace"),
31
- propIsNotEmpty("key"),
32
- propIsNotEmpty("namespace"),
33
- ]);
42
+ if (!hasOwn(obj, "key") || !hasOwn(obj, "namespace")) return false;
43
+ if (obj.key == null || obj.namespace == null) return false;
44
+ if (isEmpty(obj.key) || isEmpty(obj.namespace)) return false;
45
+
46
+ return true;
47
+ };
34
48
 
35
49
  export const buildNamespaceKey = (key: string, namespace: string) =>
36
50
  `${namespace}.${key}`;
37
51
 
38
- export const savingResultIsSuccess = (result: unknown): boolean => {
39
- return R.is(Boolean, result) && !!result;
40
- };
52
+ export const savingResultIsSuccess = (result: unknown): boolean =>
53
+ typeof result === "boolean" && result === true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-alpha.5652127751",
3
+ "version": "16.0.0-alpha.6466900632",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-alpha.5652127751",
30
+ "@applicaster/applicaster-types": "16.0.0-alpha.6466900632",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -9,6 +9,16 @@ import { Dimensions } from "react-native";
9
9
 
10
10
  export { getPlayerActionButtons } from "./getPlayerActionButtons";
11
11
 
12
+ export const HLS_MIME_TYPES = [
13
+ "application/x-mpegURL",
14
+ "application/vnd.apple.mpegurl",
15
+ ];
16
+
17
+ export const STREAMING_VIDEO_MIME_TYPES = [
18
+ ...HLS_MIME_TYPES,
19
+ "application/dash+xml",
20
+ ];
21
+
12
22
  /**
13
23
  * Gets duration value from player manager, and from extensions
14
24
  * then checks whether the value from either is a not a valid number
@@ -80,6 +90,16 @@ export function isLive(entry: ZappEntry): boolean {
80
90
  return isEntryLive(entry) || isLiveByManager();
81
91
  }
82
92
 
93
+ export const isVideoItem = (item: Option<ZappEntry>) => {
94
+ const contentType = item?.content?.type;
95
+
96
+ return (
97
+ isString(contentType) &&
98
+ (contentType.includes("video") ||
99
+ STREAMING_VIDEO_MIME_TYPES.includes(contentType))
100
+ );
101
+ };
102
+
83
103
  export const isAudioItem = (item: Option<ZappEntry>) => {
84
104
  if (
85
105
  isString(item?.content?.type) &&