Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
get-else-set
Advanced tools
getElseSet is a utility function to check if a property (of any nested level) exists. If the property does not exist, the value is set to 'null' or a value of your choice.
getElseSet is a utility function to check if a property (of any nested level) exists. If the property does not exist, the value is set to 'null' or a value of your choice.
This is useful when mapping over and restructuring JSON objects that have near similar properties, but some may be undefined.
For example, you may have a NoSQL collection where a few documents in the collection are missing a property. Using getElseSet you can restructure your documents, and when met by an undefined property you can set it to 'null' or a value of your choice.
I developed this to assist with migrating from a NoSQL DB to SQL DB in which the NoSQL documents were not all the same.
Use it synchronously or asynchronously!
`
// Synchronous
getElseSet.sync(checkPropertyArray, object, setValue[Optional, default is null])
// Asynchronous
getElseSet.async(checkPropertyArray, object, setValue[Required], callback)
`
Example Data Here Example Script Here or below.
`
'use strict'
const getElseSet = require('../getElseSet');
const fs = require('fs');
// The properties you want to check for. In our example, we use nested properties.
const myCheckArray = [
'data.type',
'data.attributes.title',
'data.attributes.body'
]
// Get data function. You can use anything to pull in your JSON data.
fs.readFile('./example.data.json', 'utf8', (err, data) => {
let jsonRes = JSON.parse(data);
jsonRes.map(o => {
// #### Synchronous Example!
getElseSet.sync(myCheckArray, o, 'Sync Function: Replaced value!')
/*
Output:
[
{
data_type: 'articles',
data_attributes_title: 'JSON API paints my bikeshed!',
data_attributes_body: 'The shortest article. Ever.'
},
{
data_type: 'articles',
data_attributes_title: 'JSON API paints my bikeshed!',
Replaced Value -> data_attributes_body: 'Sync Function: Replaced value!'
}
]
*/
// #### Asynchronous Example!
getElseSet.async(myCheckArray, o, 'Async Function: Replaced value!', result => {
/*
Output:
[
{
data_type: 'articles',
data_attributes_title: 'JSON API paints my bikeshed!',
data_attributes_body: 'The shortest article. Ever.'
},
{
data_type: 'articles',
data_attributes_title: 'JSON API paints my bikeshed!',
Replaced Value -> data_attributes_body: 'Async Function: Replaced value!'
}
]
*/
})
})
})
`
FAQs
getElseSet is a utility function to check if a property (of any nested level) exists. If the property does not exist, the value is set to 'null' or a value of your choice.
The npm package get-else-set receives a total of 1 weekly downloads. As such, get-else-set popularity was classified as not popular.
We found that get-else-set 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.