Something went wrong on our end
-
Julien MARGAIL authoredJulien MARGAIL authored
utils.ts 1.27 KiB
export const cleanHtml = (strHtml) => {
if (!strHtml) return ""
if (!isString(strHtml)) return ""
return strHtml.replace(/<\/?[^>]+(>|$)/g, "")
}
export const isBrowser = typeof window !== "undefined"
export const isBoolean = (val) => "boolean" === typeof val
export const isString = (val) => {
return Object.prototype.toString.call(val) === "[object String]"
}
export const isArray = (obj) => {
return Object.prototype.toString.call(obj) === "[object Array]"
}
export const isObject = (obj) => {
return Object.prototype.toString.call(obj) === "[object Object]"
}
// Thanks ChatGPT ;)
export const merge = (obj1: object, obj2: object): object => {
if (!obj1) return obj2
if (!obj2) return obj1
for (let key in obj2) {
if (obj2.hasOwnProperty(key)) {
if (obj1.hasOwnProperty(key)) {
if (isObject(obj1[key]) && isObject(obj2[key])) {
obj1[key] = merge(obj1[key], obj2[key])
} else if (isString(obj1[key]) && isString(obj2[key])) {
obj1[key] = obj1[key] + " " + obj2[key]
} else {
obj1[key] = obj2[key]
}
} else {
obj1[key] = obj2[key]
}
}
}
return obj1
}