Given a string, return a similar version of the string, but which is camel-cased and otherwise stripped of special characters, whitespace, etc. so that it is usable as an ECMAScript variable.
var JavaScript = require('machinepack-javascript');
// Given a string, return a similar version of the string, but which is camel-cased and otherwise stripped of special characters, whitespace, etc. so that it is usable as an ECMAScript variable.
JavaScript.coerceVarname({
string: 'foo-bar-baz',
force: false,
}).execSync();
The string to convert.
'foo-bar-baz'
Return a best guess varname even if the conversion fails?
false
An unexpected error occurred.
The specified string cannot be coerced into a valid ECMAScript 5.1-compatible variable name because it would collide with a JavaScript reserved word, or is otherwise invalid.
OK.
'fooBarBaz'