Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
lodash-id
makes it easy to manipulate id-based resources with lodash or lowdb
getById
insert
upsert
updateById
updateWhere
replaceById
removeById
removeWhere
createId
# with lodash
npm install lodash lodash-id --save
# with lowdb
npm install lowdb lodash-id --save
Note lodash-id
is also compatible with underscore
In the API examples, we're assuming db
to be:
const db = {
posts: [
{id: 1, body: 'one', published: false},
{id: 2, body: 'two', published: true}
],
comments: [
{id: 1, body: 'foo', postId: 1},
{id: 2, body: 'bar', postId: 2}
]
}
getById(collection, id)
Finds and returns document by id or undefined.
const post = _.getById(db.posts, 1)
insert(collection, document)
Adds document to collection, sets an id and returns created document.
const post = _.insert(db.posts, { body: 'New post' })
If the document already has an id, and it is the same as an existing document in the collection, an error is thrown.
_.insert(db.posts, { id: 1, body: 'New post' })
_.insert(db.posts, { id: 1, title: 'New title' }) // Throws an error
upsert(collection, document)
Adds document to collection, sets an id and returns created document.
const post = _.upsert(db.posts, { body: 'New post' })
If the document already has an id, it will be used to insert or replace.
_.upsert(db.posts, { id: 1, body: 'New post' })
_.upsert(db.posts, { id: 1, title: 'New title' })
_.getById(db.posts, 1) // { id: 1, title: 'New title' }
updateById(collection, id, attrs)
Finds document by id, copies properties to it and returns updated document or undefined.
const post = _.updateById(db.posts, 1, { body: 'Updated body' })
updateWhere(collection, whereAttrs, attrs)
Finds documents using _.where
, updates documents and returns updated documents or an empty array.
// Publish all unpublished posts
const posts = _.updateWhere(db.posts, { published: false }, { published: true })
replaceById(collection, id, attrs)
Finds document by id, replaces properties and returns document or undefined.
const post = _.replaceById(db.posts, 1, { foo: 'bar' })
removeById(collection, id)
Removes document from collection and returns it or undefined.
const comment = _.removeById(db.comments, 1)
removeWhere(collection, whereAttrs)
Removes documents from collection using _.where
and returns removed documents or an empty array.
const comments = _.removeWhere(db.comments, { postId: 1 })
id
Overwrite it if you want to use another id property.
_.id = '_id'
createId(collectionName, doc)
Called by lodash-id when a document is inserted. Overwrite it if you want to change id generation algorithm.
_.createId = (collectionName, item) => `${collectionName}-${item.prop}-${Date.now()}`
See details changes for each version in the release notes.
MIT - Typicode :cactus:
FAQs
Use JavaScript objects as databases
The npm package lodash-id receives a total of 182,465 weekly downloads. As such, lodash-id popularity was classified as popular.
We found that lodash-id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.