redux-feature-generator
Version:
Generate Redux feature code from the command line
49 lines (48 loc) • 1.4 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.validName = exports.replaceAll = exports.lowercase = exports.capitalize = void 0;
/**
* Capitalize the first letter of a string
* @param {string} name any string
* @returns string
*/
const capitalize = (name) => {
if (name.length > 0) {
return name[0].toUpperCase() + name.substring(1);
}
return "";
};
exports.capitalize = capitalize;
/**
* Lowercase the first letter of a string
* @param {string} name any string
* @returns string
*/
const lowercase = (name) => {
if (name.length > 0) {
return name[0].toLowerCase() + name.substring(1);
}
return "";
};
exports.lowercase = lowercase;
/**
* Replace all instances of a string with another string
* @param {string} str the string to search within
* @param {string} find the string the find
* @param {string} replace the string the exchange 'find' with
* @returns string
*/
const replaceAll = (str, find, replace) => {
var escapedFind = find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
return str.replace(new RegExp(escapedFind, 'g'), replace);
};
exports.replaceAll = replaceAll;
/**
* validName
* @param {string} featureName the name of the feature to check
* @returns boolean
*/
const validName = (featureName) => {
return /^[a-zA-Z0-9]*$/.test(featureName);
};
exports.validName = validName;
;