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