Chance camelize to capitalize the first letter

This commit is contained in:
Paulo Gustavo Veiga 2021-12-14 21:34:40 -08:00
parent 643f91c18b
commit 6a6eb8fa63

View File

@ -32,7 +32,7 @@ class FeatureModel {
this._attributes = {}; this._attributes = {};
// Create type method ... // Create type method ...
this[`is${FeatureModel.camelize(type)}Model`] = () => true; this[`is${FeatureModel.capitalize(type)}Model`] = () => true;
} }
/** */ /** */
@ -40,17 +40,18 @@ class FeatureModel {
return { ...this._attributes }; return { ...this._attributes };
} }
static camelize(str) { static capitalize(str) {
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => (index === 0 ? word.toLowerCase() : word.toUpperCase())).replace(/\s+/g, ''); return str.charAt(0).toUpperCase() + str.slice(1);
} }
/** */ /** */
setAttributes(attributes) { setAttributes(attributes) {
for (const attr in attributes) {
const funName = `set${FeatureModel.camelize(attr)}`; Object.keys(attributes).forEach((attr) => {
const funName = `set${FeatureModel.capitalize(attr)}`;
const value = attributes[attr]; const value = attributes[attr];
this[funName](value); this[funName](value);
} });
} }
/** */ /** */