ar-design
Version:
AR Design is a (react | nextjs) ui library.
83 lines (82 loc) • 3.08 kB
JavaScript
class Utils {
GetClassName = (variant = "filled", status = "light", border = { radius: "sm" }, size = "normal", icon, className) => {
const classNames = [variant, status, `border-radius-${border.radius}`];
if (size)
classNames.push(size);
if (icon && icon.element) {
classNames.push("icon");
classNames.push(`icon-${icon.position || "start"}`);
}
if (className)
classNames.push(className);
return classNames;
};
GetCookie = (name) => {
if (typeof window === "undefined")
return null;
const value = `; ${document.cookie}`;
const parts = value.split(`; ${name}=`);
if (parts.length === 2)
return parts.pop()?.split(";").shift();
return null;
};
GetOS = () => {
const userAgent = navigator.userAgent;
// İşletim sistemi bilgilerini tespit etmek için regex kullanıyoruz
if (userAgent.indexOf("Win") !== -1)
return "Windows";
if (userAgent.indexOf("Mac") !== -1)
return "MacOS";
if (userAgent.indexOf("X11") !== -1)
return "UNIX";
if (userAgent.indexOf("Linux") !== -1)
return "Linux";
if (userAgent.indexOf("Android") !== -1)
return "Android";
if (userAgent.indexOf("like Mac") !== -1)
return "iOS";
return "Bilinmeyen OS";
};
GetOSShortCutIcons = () => {
switch (this.GetOS()) {
case "MacOS":
return "⌘";
case "Windows":
return "ctrl";
default:
return "";
}
};
StringFormat = (value, ...args) => {
if (args[0].length === 0)
return value;
return value.replace(/{(\d+)}/g, (match, number) => {
const index = parseInt(number, 10);
return typeof args[index] !== "undefined" ? args[index] : match;
});
};
IsNullOrEmpty = (value) => {
if (value === null || value === undefined)
return true;
if (typeof value === "string" && value.trim() === "")
return true;
if (typeof value === "object" && value !== null && Object.keys(value).length === 0)
return true;
if (Array.isArray(value) && value.length === 0)
return true;
return false;
};
DeepEqual = (obj1, obj2) => {
if (Object.is(obj1, obj2))
return true; // Aynı referanssa true döndür
if (typeof obj1 !== "object" || typeof obj2 !== "object" || obj1 === null || obj2 === null) {
return false; // Eğer biri obje değilse ve eşit değilse false
}
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length)
return false; // Farklı uzunlukta anahtar varsa false
return keys1.every((key) => this.DeepEqual(obj1[key], obj2[key])); // Rekürsif karşılaştırma
};
}
export default new Utils();