UNPKG

mr-case

Version:

55 functions to seamlessly transform strings, arrays, and object keys between different cases (camelCase, snake_case, kebab-case, PascalCase, Title Case, and more), clean and format text, extract URL components, and perform common text operations like mas

20 lines (14 loc) 669 B
// function textToCamel(text) { // if (typeof text !== 'string' || !text.trim()) throw new Error('Input must be a non-empty string'); // return text // .toLowerCase() // .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()); // } // module.exports = textToCamel; function textToCamel(text) { if (typeof text !== 'string' || !text.trim()) throw new Error('Input must be a non-empty string'); return text .replace(/[^a-zA-Z0-9]+(.)/g, (_, char) => char.toUpperCase()) .replace(/^./, firstChar => firstChar.toLowerCase()); // Ensure first letter is lowercase } module.exports = textToCamel;