omni-tools/src/utils/string.ts

24 lines
623 B
TypeScript
Raw Normal View History

2024-06-25 09:35:44 +01:00
export function capitalizeFirstLetter(string: string | undefined) {
if (!string) return '';
2024-06-23 01:26:04 +01:00
return string.charAt(0).toUpperCase() + string.slice(1);
}
2024-06-27 16:51:40 +00:00
export function isNumber(number: any) {
return !isNaN(parseFloat(number)) && isFinite(number);
2024-06-27 18:55:20 +01:00
}
2024-07-09 21:58:08 +01:00
export const replaceSpecialCharacters = (str: string) => {
return str
2025-02-27 13:05:38 +00:00
.replace(/\\"/g, '"')
2024-07-09 21:58:08 +01:00
.replace(/\\n/g, '\n')
.replace(/\\t/g, '\t')
.replace(/\\r/g, '\r')
.replace(/\\b/g, '\b')
.replace(/\\f/g, '\f')
.replace(/\\v/g, '\v');
};
export function reverseString(input: string): string {
return input.split('').reverse().join('');
}