UNPKG

rykit-v3

Version:

A powerful Node.js utility library for Minecraft server status, color manipulation, encryption, file operations, and more

66 lines (57 loc) 1.59 kB
class StringUtils { // Kelime değiştirme replaceWord(text, oldWord, newWord) { return text.replace(new RegExp(oldWord, "g"), newWord); } // String dizisini birleştirme joinStrings(array, separator = " ") { return array.join(separator); } // UUID oluşturma generateUUID() { return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => { const r = (Math.random() * 16) | 0; const v = c === "x" ? r : (r & 0x3) | 0x8; return v.toString(16); }); } // Renk dönüşümleri rgbToHex(r, g, b) { return `#${[r, g, b] .map((x) => { const hex = x.toString(16); return hex.length === 1 ? "0" + hex : hex; }) .join("")}`; } hexToRgb(hex) { const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex); return result ? { r: parseInt(result[1], 16), g: parseInt(result[2], 16), b: parseInt(result[3], 16), } : null; } // Timestamp formatting formatTimestamp(timestamp) { const date = new Date(timestamp); return date.toLocaleString(); } // String case conversions toTitleCase(str) { return str.replace( /\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase() ); } toCamelCase(str) { return str .replace(/(?:^\w|[A-Z]|\b\w)/g, (letter, index) => index === 0 ? letter.toLowerCase() : letter.toUpperCase() ) .replace(/\s+/g, ""); } } export default StringUtils;