[DependsOn] Added action's name conversion to the type [a-z0-9-]+
const actionRegistryMap = {};
class ActionRegistry {
+
/**
* Default action name
* */
return action;
}
+ /**
+ * Function to remove symbols that don't match to the pattern
+ * @param {string} target - target string
+ * @param {RegExp} pattern - pattern for correct symbols
+ * */
+ static _replaceForbiddenSymbols(target, pattern) {
+ return target.replace(new RegExp(pattern + '|.', 'g'),
+ (match) => (match === pattern ? match : ''));
+ }
+
+ /**
+ * Function to develop action's name (includes a-z, 0-9, -)
+ * @param {string} name - action name
+ * @returns {string} correct action name (according to nameRegex)
+ * */
+ static _refactorName(name) {
+ const nameRegex = /^[a-z0-1-]+$/;
+ let resultName = name;
+ if (name.trim().search(nameRegex) === -1) {
+ resultName = resultName.toLocaleLowerCase();
+ resultName = this._replaceForbiddenSymbols(resultName, nameRegex);
+ console.warn(`[DependsOn]: Action's name ${name} was overridden by ${resultName} (name includes a-z, 0-9, -)`);
+ }
+ return resultName;
+ }
+
/**
* @param {string} name - is action name
- * @param {function} actionFn - function to set state (queryresult: any) => void
+ * @param {function} actionFn - function to set state (queryResult: any) => void
* @returns {function} actual actionCb after register
* */
static register(name, actionFn) {
+ name = this._refactorName(name);
if (typeof actionFn !== 'function') {
throw new Error(`[DependsOn]: Action ${actionFn} is not a valid action definition`);
}
