2023-07-07 07:42:14 +00:00
|
|
|
export const sanitise = (str) => {
|
|
|
|
let ret = ""
|
2023-07-04 08:05:08 +00:00
|
|
|
|
2023-07-07 07:42:14 +00:00
|
|
|
const value = str?.trim()
|
2023-07-04 08:05:08 +00:00
|
|
|
|
2023-07-07 07:42:14 +00:00
|
|
|
const sanitised = ["tt", "thingtime"]
|
|
|
|
|
|
|
|
const suffixes = [".", " "]
|
|
|
|
|
|
|
|
// find combination of sanitised + suffixes which str starts with
|
2023-07-04 08:05:08 +00:00
|
|
|
|
2023-07-07 07:42:14 +00:00
|
|
|
const match = sanitised.find((s) => value?.startsWith(s))
|
|
|
|
const withSuffix = suffixes.find(
|
|
|
|
(s) => match?.length && value[match?.length] === s
|
|
|
|
)
|
|
|
|
const noSuffix = match && value?.length === match?.length
|
|
|
|
|
|
|
|
if (match && withSuffix) {
|
|
|
|
ret = value?.slice(match.length + 1)
|
|
|
|
} else if (!noSuffix) {
|
|
|
|
ret = value
|
|
|
|
}
|
|
|
|
console.log("nik thingtime sanitis 1", match, withSuffix, ret)
|
2023-07-04 08:05:08 +00:00
|
|
|
|
2023-07-07 07:42:14 +00:00
|
|
|
return ret
|
2023-07-04 08:05:08 +00:00
|
|
|
}
|