Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
20 lines
454 B
JavaScript
20 lines
454 B
JavaScript
class Utils {
|
|
getDate() {
|
|
return new Date().toString();
|
|
}
|
|
|
|
format(template, ...values) {
|
|
return template.replace(/%(\d+)/g, (match, index) => {
|
|
const value = values[Number(index) - 1];
|
|
return value === undefined ? match : value;
|
|
});
|
|
}
|
|
|
|
escapeHtml(text) {
|
|
const entities = {"&": "&", "<": "<", ">": ">", "\"": """, "'": "'"};
|
|
return text.replace(/[&<>"']/g, (char) => entities[char]);
|
|
}
|
|
}
|
|
|
|
module.exports = Utils;
|