UNPKG

@applicaster/zapp-react-native-utils

Version:

Applicaster Zapp React Native utilities package

53 lines (43 loc) 1.19 kB
import * as R from "ramda"; import { toPascalCase } from "../stringUtils"; import * as itemTypeMatchers from "./itemTypeMatchers"; import * as itemIdResolvers from "./itemIdResolvers"; const { getIdProp } = itemIdResolvers; export const SCREEN_TYPES = { PLAYABLE: "playable", RIVER: "river", ARTICLE: "article", MENU_ITEM: "menu_item", URL_SCHEME: "url_scheme", LINK: "link", CONTENT_SCREEN: "content_screen", }; export const getTypeMatcher = R.compose( R.prop(R.__, itemTypeMatchers), R.concat("is"), toPascalCase ); export const itemIsOfType = R.curry((item, type) => R.compose(R.apply(R.__, [item]), getTypeMatcher)(type) ); export const getIdResolver = R.compose( R.defaultTo(getIdProp), R.prop(R.__, itemIdResolvers), R.concat(R.__, "Id"), R.concat("get"), toPascalCase ); export function isScreenPlayable(pathname) { if (pathname) { const pathComponents = R.split("/"); const dividedItems = R.tail(pathComponents(pathname)); const searchedItemIndex = dividedItems.length - 2; if ( searchedItemIndex > 0 && dividedItems[searchedItemIndex] === "playable" ) { return true; } } return false; }