UNPKG

@sendgrid/helpers

Version:

Twilio SendGrid NodeJS internal helpers

15 lines (13 loc) 386 B
'use strict'; /** * Internal conversion helper */ module.exports = function strToSnakeCase(str) { if (typeof str !== 'string') { throw new Error('String expected for conversion to snake case'); } return str.trim().replace(/(\s*\-*\b\w|[A-Z])/g, function($1) { $1 = $1.trim().toLowerCase().replace('-', ''); return ($1[0] === '_' ? '' : '_') + $1; }).slice(1); };