{"library":"lodash-id","title":"lodash-id: ID-based Resource Manipulation for Lodash/Lowdb","description":"lodash-id is a utility package that extends Lodash and Underscore with methods for manipulating collections of JavaScript objects based on a unique `id` property, effectively turning them into simple in-memory databases. It provides a set of CRUD-like operations such as `getById`, `insert`, `upsert`, `updateById`, `removeById`, and `removeWhere`. The package normalizes ID comparisons, allowing both string and integer IDs to be treated equivalently since version `0.12.0`. The current stable version is `0.14.1`. Releases are infrequent but address compatibility and feature refinements. Its primary differentiator is its integration as a Lodash mixin, simplifying common data management patterns within existing Lodash-based applications or in conjunction with `lowdb`. It does not handle data persistence directly since `v0.14.0`, delegating that responsibility to `lowdb` or custom implementations.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install lodash-id"],"cli":null},"imports":["const _ = require('lodash');\n_.mixin(require('lodash-id'));","const post = _.getById(db.posts, 1);","_.id = '_id';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const _ = require('lodash');\n_.mixin(require('lodash-id'));\n\nconst db = {\n  posts: [\n    { id: 1, title: 'First Post', published: false },\n    { id: 2, title: 'Second Post', published: true }\n  ]\n};\n\n// Insert a new document\nconst newPost = _.insert(db.posts, { title: 'Third Post' });\nconsole.log('Inserted post:', newPost); // { id: 3, title: 'Third Post' }\n\n// Get a document by ID\nconst post1 = _.getById(db.posts, 1);\nconsole.log('Got post by ID 1:', post1); // { id: 1, title: 'First Post', published: false }\n\n// Update a document by ID\n_.updateById(db.posts, newPost.id, { published: true });\nconsole.log('Updated post:', _.getById(db.posts, newPost.id)); // { id: 3, title: 'Third Post', published: true }\n\n// Upsert a document (replaces if ID exists, inserts if not)\n_.upsert(db.posts, { id: 1, title: 'First Post Updated', category: 'News' });\nconsole.log('Upserted post 1:', _.getById(db.posts, 1)); // { id: 1, title: 'First Post Updated', category: 'News' }\n\n// Remove a document by ID\nconst removedPost = _.removeById(db.posts, 2);\nconsole.log('Removed post by ID 2:', removedPost); // { id: 2, title: 'Second Post', published: true }\nconsole.log('Remaining posts:', db.posts); // [{ id: 1, title: 'First Post Updated', category: 'News' }, { id: 3, title: 'Third Post', published: true }]\n","lang":"javascript","description":"Demonstrates how to initialize lodash-id and perform basic CRUD operations like insert, get, update, upsert, and remove on an in-memory collection.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}