zustand-storage
Version:
A universal solution combining @aivron/sync-storage and zust-api for React (web & desktop). It merges local persistence with a Zustand-inspired API to provide core storage operations, bulk actions, JSON support, TTL, and integrated React hooks.
66 lines (65 loc) • 2.15 kB
JavaScript
;
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.debounce = exports.shallowMerge = exports.deepMerge = void 0;
/**
* Deeply merges two objects.
* @param target - The target object.
* @param source - The source object.
* @returns The merged object.
*/
function deepMerge(target, source) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
var targetVal = target[key];
var sourceVal = source[key];
if (typeof targetVal === "object" && typeof sourceVal === "object" && targetVal && sourceVal) {
target[key] = deepMerge(__assign({}, targetVal), sourceVal);
}
else {
target[key] = sourceVal;
}
}
}
return target;
}
exports.deepMerge = deepMerge;
/**
* Shallowly merges two objects.
* @param target - The target object.
* @param source - The source object.
* @returns The merged object.
*/
function shallowMerge(target, source) {
return __assign(__assign({}, target), source);
}
exports.shallowMerge = shallowMerge;
/**
* Creates a debounced version of a function.
* @param func - The function to debounce.
* @param wait - The delay in milliseconds.
* @returns The debounced function.
*/
function debounce(func, wait) {
var timeout;
var debouncedFunction = function () {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
clearTimeout(timeout);
timeout = setTimeout(function () { return func.apply(void 0, args); }, wait);
};
return debouncedFunction;
}
exports.debounce = debounce;