data-lube
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

Data Lube

Simplify Data Manipulation in JavaScript

Working with complex data structures and ensuring data integrity can be challenging.
With "data-lube", a powerful JavaScript library, you can simplify the process of deep copying and deep freezing objects, helping you maintain data consistency and avoid unexpected changes.
This library offers easy-to-use functions such as deep copy and deep freeze, allowing you to work with data structures without worrying about unintended modifications.

installation

npm i data-lube
pnpm i data-lube
bun i data-lube

How to use

Easy deep copy

import { deepCopy } from "data-lube"

var origin = {
	a: [ 1, 2 ],
    d: new Date
	n: null,
	o: { k: "v" },
	s: "string",
	u: void 0
}
var clone: typeof origin = deepCopy(origin)

Easy comparison and type evaluation

import { deepEqual } from "data-lube"

var origin = {
	a: [ 1, 2 ],
	n: null,
	o: { k: "v" },
	s: "string"
} as const
var clone: any = JSON.parse(JSON.stringify(origin))
if (deepEqual(origin, clone)) {
    clone.a = [] // Cannot assign to 'a' because it is a read-only property.ts(2540)
}

Easy deep freeze

import { deepFreeze } from "data-lube"

var freezed = deepFreeze({
	a: [ 1, 2 ],
	n: null,
	o: { k: "v" },
	s: "string"
})
freezed.a = [] // Cannot assign to 'a' because it is a read-only property.ts(2540)

// @ts-ignore
freezed.a = [] // TypeError: Cannot assign to read only property 'a' of object '#<Object>'

Package Sidebar

Install

npm i data-lube

Weekly Downloads

2

Version

1.4.1

License

MIT

Unpacked Size

25.9 kB

Total Files

18

Last publish

Collaborators

  • artxe2