const camelToSnakeCase = (text) => { if (!(typeof text === "string" || text instanceof String)) { console.error(`string expected, ${typeof text} provided`) return text } return text.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`) } camelToSnakeCase("camelCaseToSnakeCase") // camel_case_to_snake_case