UNPKG

string-utils-pro-sf

Version:

reverseString capitalizeWords toSnakeCase toKebabCase

24 lines (20 loc) 694 B
// index.js module.exports = { // Reverse a string reverseString: (str) => str.split('').reverse().join(''), // Capitalize the first letter of each word capitalizeWords: (str) => str.replace(/\b\w/g, (char) => char.toUpperCase()), // Convert a string to snake_case toSnakeCase: (str) => str .replace(/\s+/g, '_') .replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`) .toLowerCase(), // Convert a string to kebab-case toKebabCase: (str) => str .replace(/\s+/g, '-') .replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`) .toLowerCase(), };