@brizy/media-gallery
Version:
35 lines (34 loc) • 944 B
JavaScript
import { always, ifElse } from "ramda";
var itemId = /*#__PURE__*/ function(itemId) {
itemId["type"] = "itemId";
return itemId;
}(itemId || {});
/**
* Check if the string value is a ItemId value
*/ export var is = function(s) {
return !!s.match(/^\/item\/.*$/);
};
/**
* Try to read a ItemId value from a string
*/ export var fromString = function(v) {
return ifElse(is, always, function(v) {
return "/item/".concat(v);
})(v);
};
/**
* from itemId to string
*/ export var toString = function(v) {
return v.replace("/item/", "");
};
/**
* Create a ItemId value from an numeric Id
*/ export var fromId = function(id) {
return "/item/".concat(id);
};
/**
* Converts a ItemId value to an numeric Id
*
* Note: A ItemId value contains a Id value inside, so we can afford this dangerous forced conversion to Id
*/ export var toId = function(itemId) {
return Number(itemId.replace("/item/", ""));
};