{"library":"object-refs","title":"Minimal Bi-directional Object References","description":"object-refs is a minimalist JavaScript library designed to establish and manage bi-directional references between objects. It's particularly useful in scenarios where maintaining explicit links between related objects, where one object's reference to another implies a reciprocal reference, is critical for data integrity or graph-like structures. The current stable version is 0.4.0. Given its `0.x.x` versioning, it likely follows an agile release cadence, introducing features and potentially breaking changes in minor versions. Its key differentiator is its focus on being minimal and providing robust type definitions for TypeScript users since `v0.4.0`, enabling safer refactoring and development compared to manual reference management.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install object-refs"],"cli":null},"imports":["import { Refs } from 'object-refs';","const { Refs } = require('object-refs');","import type { RefCollection, Reference } from 'object-refs';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { Refs } from 'object-refs';\n\n// Define the properties that will hold the bi-directional references\nconst LEFT_REF = 'left';\nconst RIGHT_REF = 'right';\n\n// Create a new reference collection for 'connection' type references\nconst connectionRefs = new Refs({ \n  name: 'connection',\n  collection: 'connections',\n  target: LEFT_REF,\n  source: RIGHT_REF\n});\n\n// Example objects\nconst nodeA = { id: 'nodeA', connections: [] };\nconst nodeB = { id: 'nodeB', connections: [] };\n\n// Add a bi-directional reference between nodeA and nodeB\n// This will add nodeA to nodeB.connections and nodeB to nodeA.connections (via the ref properties)\nconnectionRefs.bind(nodeA, nodeB);\n\nconsole.log('Node A connections:', nodeA.connections.map(c => c.id));\n// Expected: Node A connections: [ 'nodeB' ]\n\nconsole.log('Node B connections:', nodeB.connections.map(c => c.id));\n// Expected: Node B connections: [ 'nodeA' ]\n\n// Clean up references\nconnectionRefs.unbind(nodeA, nodeB);\n\nconsole.log('Node A connections after unbind:', nodeA.connections.map(c => c.id));\n// Expected: Node A connections after unbind: []","lang":"typescript","description":"Demonstrates how to create a `Refs` instance, define reference properties, and establish/remove bi-directional links between two objects.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}