@applicaster/zapp-react-native-ui-components
Version:
Applicaster Zapp React Native ui components for the Quick Brick App
56 lines (48 loc) • 1.99 kB
JavaScript
import * as R from "ramda";
import { isDateValid } from "./Utils";
import { masterCellLogger } from "../logger";
import { imageSrcFromMediaItem as imageSrcFromMediaItemConfigUtils } from "@applicaster/zapp-react-native-utils/configurationUtils";
export const imageSrcFromMediaItem = (...args) => {
__DEV__ &&
masterCellLogger?.debug({
message:
'Deprecated, please modify import from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/MappingFunctions" to "@applicaster/zapp-react-native-utils/configurationUtils"',
});
return imageSrcFromMediaItemConfigUtils(...args);
};
/**
* Fetch a date object from a path, and convert to a string.
* Returns an empty string if the resulting path has no value,
* or if the date parsing failed.
* @param {Object} obj Any object holding an ISO8061 date, usually a feed entry.
* @param {Array} args Path to the value containing the date to parse.
*/
export function stringifyDateFromPath(obj, path) {
const date = new Date(pathWithFallback(obj, path));
return isDateValid(date) ? date.toDateString() : "";
}
/**
* Retrieves value in an object given its path.
* Returns an empty string if the resulting path has no value.
* @param {Object} obj Plain javascript object
* @param {Array} path Path to the value, as an array (see R.pathOr)
* @returns {any} Found object or empty string
*/
export function pathWithFallback(obj, path) {
return R.pathOr("", path)(obj);
}
// prettier-ignore
const functionsNames = {
"path": pathWithFallback,
"image_src_from_media_item": imageSrcFromMediaItemConfigUtils,
"stringify_date_from_path": stringifyDateFromPath,
};
/**
* Returns the matching function for the funcName,
* If not found, returns the "path" function as a default;
* @param {String} func Name of the func
* @returns {Function} Function to apply, defaults to "path"
*/
export function functionForName(func) {
return functionsNames[func] || pathWithFallback;
}