map-transform-cjs
Version:
MapTransform with CJS support
129 lines (126 loc) • 4.21 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/stateHelpers.ts
var stateHelpers_exports = {};
__export(stateHelpers_exports, {
clearUntouched: () => clearUntouched,
flipState: () => flipState,
getLastContext: () => getLastContext,
getRootFromState: () => getRootFromState,
getStateValue: () => getStateValue,
getTargetFromState: () => getTargetFromState,
goForward: () => goForward,
isNonvalue: () => isNonvalue,
isNonvalueState: () => isNonvalueState,
isUntouched: () => isUntouched,
markAsUntouched: () => markAsUntouched,
noopNext: () => noopNext,
popContext: () => popContext,
populateState: () => populateState,
pushContext: () => pushContext,
removeLastContext: () => removeLastContext,
revFromState: () => revFromState,
setStateValue: () => setStateValue,
setTargetOnState: () => setTargetOnState,
setValueFromState: () => setValueFromState,
stopIteration: () => stopIteration
});
module.exports = __toCommonJS(stateHelpers_exports);
// src/utils/xor.ts
function xor(a = false, b = false) {
return a ? !b : b;
}
// src/utils/stateHelpers.ts
var getLastContext = (state) => state.context[state.context.length - 1];
var removeLastContext = (state) => ({
...state,
context: state.context.slice(0, -1)
});
var pushContext = (state, value) => ({
...state,
context: [...state.context, value]
});
var popContext = (state) => ({
...state,
context: state.context.slice(0, -1),
value: state.context[state.context.length - 1]
});
var getRootFromState = (state) => state.context.length === 0 ? state.value : state.context[0];
var getTargetFromState = (state) => state.target;
function setTargetOnState(state, target) {
return {
...state,
target
};
}
var setStateValue = ({ untouched, ...state }, value, shouldPushContext = false) => shouldPushContext ? {
...pushContext(state, state.value),
value
} : { ...state, value };
var getStateValue = (state) => state.value;
var setValueFromState = (state, { value }, shouldPushContext = false) => setStateValue(state, value, shouldPushContext);
var isNonvalue = (value, nonvalues = [void 0]) => nonvalues.includes(value);
var isNonvalueState = (state, nonvalues = [void 0]) => isNonvalue(state.value, nonvalues);
var markAsUntouched = (state) => ({ ...state, untouched: true });
var clearUntouched = ({ untouched, ...state }) => state;
var isUntouched = ({ untouched }) => !!untouched;
var populateState = (data, { rev = false, noDefaults = false, target = void 0 }) => ({
context: [],
value: data,
target,
rev,
noDefaults
});
var goForward = (state) => state.rev || state.flip ? {
...state,
rev: false,
flip: false
} : state;
var flipState = (state, flip = true) => ({
...state,
flip: xor(state.flip, flip)
});
var stopIteration = (state) => ({ ...state, iterate: false });
var noopNext = async (state) => state;
var revFromState = (state, flip = false) => flip ? xor(state.rev, !state.flip) : xor(state.rev, state.flip);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
clearUntouched,
flipState,
getLastContext,
getRootFromState,
getStateValue,
getTargetFromState,
goForward,
isNonvalue,
isNonvalueState,
isUntouched,
markAsUntouched,
noopNext,
popContext,
populateState,
pushContext,
removeLastContext,
revFromState,
setStateValue,
setTargetOnState,
setValueFromState,
stopIteration
});
//# sourceMappingURL=stateHelpers.cjs.map