Added delta functions
Some checks failed
Build / Build NPM Project (push) Successful in 42s
Build / Publish Documentation (push) Failing after 4s
Build / Tag Version (push) Successful in 8s

This commit is contained in:
2025-07-30 14:34:59 -04:00
parent c3d8d75ba3
commit 1b6fe42f78
2 changed files with 4 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.26.24",
"version": "0.26.25",
"description": "Utility library",
"author": "Zak Timson",
"license": "MIT",

View File

@ -1,4 +1,4 @@
type Delta = { [key: string]: any | Delta | null };
export type Delta = { [key: string]: any | Delta | null };
/**
* Applies deltas in order to modify `target`.
@ -6,7 +6,7 @@ type Delta = { [key: string]: any | Delta | null };
* @param deltas - List of deltas to apply
* @returns Mutated target
*/
function applyDeltas(target: any, deltas: Delta[]): any {
export function applyDeltas(target: any, deltas: Delta[]): any {
for(const delta of deltas) {
for(const [key, value] of Object.entries(delta)) {
if(value === null) {
@ -30,7 +30,7 @@ function applyDeltas(target: any, deltas: Delta[]): any {
* @param target - Modified object
* @returns Delta to revert changes
*/
function calcDelta(old: any, target: any): Delta {
export function calcDelta(old: any, target: any): Delta {
const delta: Delta = {};
const keys = new Set([...Object.keys(old || {}), ...Object.keys(target || {})]);
for(const key of keys) {