Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gurgunday/gobj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gobj img.shields.io/bundlephobia/minzip/gobj

snugobject is a mutable JavaScript object with an immutable hidden class.

Works in the browser. No runtime dependencies. Drop-in* replacement to objects. Get more out of your JS engine.

gobj.gif

Installation

npm i gobj

Or import directly from a CDN:

import { Obj } from "https://cdn.jsdelivr.net/npm/gobj/+esm";

API

Obj

The Obj class creates a mutable JavaScript object with an immutable hidden class, powered by a Map and a Proxy.

Constructor

new Obj(data);
  • data (object, optional): The initial data to populate the object with.

The constructor may throw:

  • TypeError: If data is null.

Usage

import { Obj } from "gobj";

const obj = new Obj({
  name: "John Doe",
  age: 30,
});

console.log(obj.name); // Output: "John Doe"
console.log(obj.age); // Output: 30

obj.email = "[email protected]";
console.log(obj.email); // Output: "[email protected]"

delete obj.age; // Output: true
console.log(obj.age); // Output: undefined

console.log(Object.keys(obj)); // Output: ["name", "email"]
console.log(JSON.stringify(obj)); // Output: '{"name":"John Doe","email":"john@example.com"}'

Obj supports all standard object operations, including property access, modification, deletion, and iteration.

About

Mutable JavaScript object with an immutable hidden class

Resources

License

Stars

Watchers

Forks

Packages

No packages published