@provenanceio/wallet-utils
Version:
Typescript Utilities for Provenance Blockchain Wallet
21 lines (18 loc) • 948 B
JavaScript
// Capitalize and clean the passed in string/word
// Eg: "hello world" => "Hello World"
// Eg: "hEllO" => "Hello"
// Eg: "hELLo_wOrlD" => "Hello World"
export var capitalize = function capitalize() {
var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'default';
if (!str || typeof str !== 'string') return str; // Camel case work ('addressIndex' => 'Address Index')
if (type === 'camelcase') return str.replace(/([A-Z])/g, ' $1') // Insert a space before all caps
.replace(/^./, function (str) {
return str.toUpperCase();
}); // Uppercase the first character
if (type === 'uppercase') return str.toUpperCase(); // Uppercase the whole word
// Default word
return str.replaceAll('_', ' ').toLowerCase().split(' ').map(function (word) {
return word.charAt(0).toUpperCase() + word.substring(1);
}).join(' ');
};