2023-04-07 15:36:47 +00:00
|
|
|
import { UserRole } from "interfaces/user";
|
|
|
|
|
|
2021-04-30 19:13:04 +00:00
|
|
|
/**
|
|
|
|
|
* Capitalizes the words of the string passed in.
|
|
|
|
|
* @param str un-capitalized string
|
|
|
|
|
*/
|
|
|
|
|
const capitalize = (str: string): string => {
|
|
|
|
|
return str.replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
|
|
|
};
|
|
|
|
|
|
2023-04-07 15:36:47 +00:00
|
|
|
const capitalizeRole = (str: UserRole): UserRole => {
|
|
|
|
|
if (str === "observer_plus") {
|
|
|
|
|
return "Observer+";
|
|
|
|
|
}
|
|
|
|
|
if (str === "gitops") {
|
|
|
|
|
return "GitOps";
|
|
|
|
|
}
|
|
|
|
|
return str.replace(/\b\w/g, (letter) => letter.toUpperCase()) as UserRole;
|
|
|
|
|
};
|
|
|
|
|
|
2023-05-18 20:40:04 +00:00
|
|
|
export const STYLIZATIONS_AND_ACRONYMS = [
|
|
|
|
|
"macOS",
|
|
|
|
|
"osquery",
|
|
|
|
|
"MySQL",
|
|
|
|
|
"MDM",
|
|
|
|
|
"REST",
|
|
|
|
|
"API",
|
|
|
|
|
"JSON",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// fleetdm.com/handbook/marketing/content-style-guide#sentence-case
|
|
|
|
|
// * doesn't recognize proper nouns!
|
|
|
|
|
export const enforceFleetSentenceCasing = (s: string) => {
|
|
|
|
|
const resArr = s.split(" ").map((word, i) => {
|
|
|
|
|
if (!STYLIZATIONS_AND_ACRONYMS.includes(word)) {
|
|
|
|
|
const lowered = word.toLowerCase();
|
|
|
|
|
if (i === 0) {
|
|
|
|
|
// title case the first word
|
|
|
|
|
return lowered[0].toUpperCase() + lowered.slice(1);
|
|
|
|
|
}
|
|
|
|
|
return lowered;
|
|
|
|
|
}
|
|
|
|
|
return word;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return resArr.join(" ").trim();
|
|
|
|
|
};
|
2021-04-30 19:13:04 +00:00
|
|
|
export default {
|
|
|
|
|
capitalize,
|
2023-04-07 15:36:47 +00:00
|
|
|
capitalizeRole,
|
2021-04-30 19:13:04 +00:00
|
|
|
};
|