@brizy/media-gallery
Version:
33 lines (32 loc) • 1.01 kB
JavaScript
/**
* Read a string value from an unknown value
*/ function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
export var read = function(v) {
switch(typeof v === "undefined" ? "undefined" : _type_of(v)){
case "string":
return v;
case "number":
return isNaN(v) ? undefined : String(v);
default:
return undefined;
}
};
export function onNoEmpty(f, s) {
return s && f(s);
}
export var capitalize = function(str) {
return str.charAt(0).toUpperCase() + str.toLowerCase().slice(1);
};
/**
* Add ... after given position
*/ export var ellipsis = function(str, length) {
return str.length > length - 3 ? str.substr(0, length) + "..." : str;
};
/**
* transform any string in kebab-case format
*/ export var toKebabCase = function(str) {
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
};