MCPcopy
hub / github.com/autoNumeric/autoNumeric / camelize

Method camelize

src/AutoNumericHelper.js:1339–1363  ·  view source on GitHub ↗

* Return a 'camelized' version of the given string. * By default, this assume that : * - the separators are hyphens '-', * - the 'data-' string should be removed, and * - that the very first word should not be capitalized. * * @example camelize('data-currency-symbol') =

(str, separator = '-', removeData = true, skipFirstWord = true)

Source from the content-addressed store, hash-verified

1337 * @returns {string|null}
1338 */
1339 static camelize(str, separator = '-', removeData = true, skipFirstWord = true) {
1340 if (this.isNull(str)) {
1341 return null;
1342 }
1343
1344 if (removeData) {
1345 str = str.replace(/^data-/, '');
1346 }
1347
1348 // Cut the string into words
1349 const words = str.split(separator);
1350
1351 // Capitalize each word
1352 let result = words.map(word => `${word.charAt(0).toUpperCase()}${word.slice(1)}`);
1353
1354 // Then concatenate them back
1355 result = result.join('');
1356
1357 if (skipFirstWord) {
1358 // Skip the very first letter
1359 result = `${result.charAt(0).toLowerCase()}${result.slice(1)}`;
1360 }
1361
1362 return result;
1363 }
1364
1365 /**
1366 * Return the text component of the given DOM element.

Calls 1

isNullMethod · 0.95

Tested by

no test coverage detected