node-libcurl
Version:
The fastest http(s) client (and much more) for Node.js - Node.js bindings for libcurl
42 lines (36 loc) • 1.86 kB
JavaScript
// The idea here is to conver a curl option name to a camel case one.
// For example, HSTSREADFUNCTION would become hstsReadFunction.
// This works by using the regexp below to break the option.
// When convertToDashCase is called for HSTSREADFUNCTION, it would first become (as the RegExp includes READ):
// HSTS_READFUNCTION
// Then (as the RegExp includes FUNCTION):
// HSTS_READ_FUNCTION
// and then the string is split on the `_`, and each item with index >= 1 has their first letter converted to uppercase
// the pieces are then joined back together, resulting in:
// hstsReadFunction
const regexp =
/^([A-Z]+)(FUNCTION|CONNECTS|DATA|RESOLVE|VALUE|ALIASES|REDIRS|CERT|KEY|MAX|AGE|REDIR|DELAY|AGENT|OPTIONS|TEXT|USERPWD|PASSWD|LEVEL|SVC|SOCKET|SSL|PUBLIC|LOCATION|LIST|(? convertToDashCase(piece))
.map((item) => (Array.isArray(item) ? item.join('_') : item))
.join('_')
.split('_')
.map((item, idx) =>
idx > 0
? item.charAt(0).toUpperCase() + item.slice(1).toLowerCase()
: item.toLowerCase(),
)
.join('')
}
module.exports = {
convertCurlConstantToCamelCase,
}