
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
object-subset
Advanced tools
object-subset is a tool to conveniently create a subset of a given tool by defining corresponding fields.
Object-subset is a tool to conveniently create a subset of a given tool by defining corresponding fields. This is incredibly helpful if you are serving an API or other end point that is fetching data from your MongoDB, Elastic Search or any other database that is at least able to return the results as JSON. In most cases you do not want to return the raw data because first of all it may contain information that is not meant for the public and secondly just because we can, does not mean we should put an unnecessary high payload on the wire.
npm install object-subset
var objectSubset = require('object-subset');
var subset = objectSubset(keywords, doc);
Two parameters are needed: An array of keywords that the script should look for and the document where it should retrieve the information from. The array is one-dimensional. In most cases documents are more complex than that. Simple dot-notation is used to dig deeper. That also goes for nested-object, array and nested-arrays:
var doc = {
user: [{
name: John,
children: [{
name: 'Jane',
age: 9
}]
}]
};
var keywords = [
'user.name',
'user.children.name',
'user.children.age'
];
In this example our database is Elastic Search. ES is always also returning information like _id, _index and _type. It is in your interest to not make those information public in order to hide how you operate internally. Furthermore ES is capable of returning a large amount of data in an insanely short amount of time. But in a lot of cases we only need a small portion of that. In order to keep our payload small we should only select only the information we need.
var objectSubset = require('object-subset');
var doc = {
_id: 1,
_type: 'user',
_index: 'users',
_source: {
name: 'John',
age: 42,
creditCard: [{
type: 'VISA',
cardNumber: '4532043405899708'
}],
children: [{
name: 'Jane',
age: 9
}, {
name: 'Frank',
age: 13
}]
}
};
var keywords = [
'_source.name',
'_source.children.name',
'_source.children.age'
];
var subset = objectSubset(keywords, doc);
This will return the following:
{
"_source": {
"name":"John",
"children": [{
"name":"Jane",
"age":9
}, {
"name":"Frank",
"age":13
}]
}
}
FAQs
object-subset is a tool to conveniently create a subset of a given tool by defining corresponding fields.
The npm package object-subset receives a total of 8 weekly downloads. As such, object-subset popularity was classified as not popular.
We found that object-subset 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.