keeweb/app/scripts/util/formatting/string-format.js

36 lines
736 B
JavaScript
Raw Normal View History

2019-09-15 08:11:11 +02:00
const StringFormat = {
camelCaseRegex: /-./g,
capFirst(str) {
if (!str) {
return '';
}
return str[0].toUpperCase() + str.substr(1);
},
pad(num, digits) {
let str = num.toString();
while (str.length < digits) {
str = '0' + str;
}
return str;
},
padStr(str, len) {
while (str.length < len) {
str += ' ';
}
return str;
},
camelCase(str) {
2020-06-01 16:53:51 +02:00
return str.replace(this.camelCaseRegex, (match) => match[1].toUpperCase());
2020-05-05 20:47:15 +02:00
},
pascalCase(str) {
2020-06-01 16:53:51 +02:00
return this.capFirst(str.replace(this.camelCaseRegex, (match) => match[1].toUpperCase()));
2019-09-15 08:11:11 +02:00
}
};
2019-09-15 14:16:32 +02:00
export { StringFormat };