use-wizard
Version:
A dead-easy-to-use light-weight react hook to handle multi-paths wizards (and simple wizards too) and navigate into them.
37 lines • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getNextStepWhenItsLast = void 0;
function getNextStepWhenItsLast(options, step) {
var index = 0;
for (var _i = 0, options_1 = options; _i < options_1.length; _i++) {
var option = options_1[_i];
if (typeof option !== "string") {
if (isElementInObjectShallow(option, step)) {
if (typeof options[index + 1] !== "string") {
throw new Error("Wizard: an element following an object must always be a string, there must always be a step between two objects");
}
return options[index + 1];
}
for (var _a = 0, _b = Object.values(option); _a < _b.length; _a++) {
var obj = _b[_a];
var nextStepWhenItsLast = getNextStepWhenItsLast(obj, step);
if (!!nextStepWhenItsLast) {
return nextStepWhenItsLast;
}
}
}
index++;
}
return "";
}
exports.getNextStepWhenItsLast = getNextStepWhenItsLast;
function isElementInObjectShallow(object, step) {
for (var _i = 0, _a = Object.values(object); _i < _a.length; _i++) {
var elements = _a[_i];
if (elements.includes(step)) {
return true;
}
}
return false;
}
//# sourceMappingURL=getNextStepWhenItsLast.js.map