
Security News
Cline CLI npm Package Compromised via Suspected Cache Poisoning Attack
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.
get-or-else
Advanced tools
Simple Get Or Else module written in JavaScript ES5.
Request an object property at a given namespace with a backup value, incase the desired namespace does not yield a result.
Useful if you have an untrustworthy data source. It will probably save you a bit of if, else-ery.
var getOrElse = require("get-or-else");
window.a = {x:4};
getOrElse({ get: [window,'a.b.c'], else: {} });
// {} - does not exist, so `else` is used
getOrElse({ get: [window,'a'], else: {} })
// {x:4} - does exist, so expected value is returned
see this repo get-or-else-demo
import React from 'react';
import ReactDOM from 'react-dom';
import getOrElse from 'get-or-else';
const data = {
salutation: 'Mr',
name: {
first: 'James'
}
};
const salutation = getOrElse({
get: [data,'salutation'],
else: false
});
const BaseComponent = () => {
return (
<h1>We have been expecting you
{salutation && <span> {salutation} </span>}
<span> {getOrElse({ get:[data,'name.first'], else:''})}</span>
<span> {getOrElse({ get:[data,'name.last'], else:''})}</span>
</h1>
);
};
ReactDOM.render(<BaseComponent />, document.getElementById('root'));
// Renders `<h1>We have been expecting you<span> Mr </span><span>James</span><span></span></h1>`
// data.name.last does not exist so it does not display
IE 9 or greater - Array.every on Mozilla's compatibility chart
/**
* @param {Object} getOrElseObj
* @param {Array} getOrElseObj.get
* @param {Object} getOrElseObj.get[0] - the root object to your namespace.
* e.g. this, window, someObj (Must exist).
* @param {String} getOrElseObj.get[1] - a string representation of the namespace you
* are targeting to get it's property. e.g. 'a.b.c.d'
* @returns {Object} the item you hope for `get`, or a backup item `else` if it does not exist.
* @example
* GIVEN
* window.a = {x:4}
*
* getOrElse({ get: [window,'a.b.c'], else: {} }) // {} - does not exist, so `else` is used
* getOrElse({ get: [window,'a'], else: {} }) // {x:4} - does exist, so expected value is returned
*/
var getOrElse = function( getOrElseObj ) {
if (!getOrElseObj.get[0]) return getOrElseObj.else;
var contextObj = getOrElseObj.get[0];
var namespace = getOrElseObj.get[1].split('.');
var value = contextObj; // reassigns to obj[key] on each array.every iteration
return (
namespace.every( function( key ) {
return (value = value[key]) != undefined
})
) ? value : getOrElseObj.else;
};
module.exports = getOrElse;
Given you have Node installed, cd into this folder and:
npm install
npm test
FAQs
Get Or Else in Javascript
The npm package get-or-else receives a total of 3 weekly downloads. As such, get-or-else popularity was classified as not popular.
We found that get-or-else 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
A compromised npm publish token was used to push a malicious postinstall script in cline@2.3.0, affecting the popular AI coding agent CLI with 90k weekly downloads.

Product
Socket is now scanning AI agent skills across multiple languages and ecosystems, detecting malicious behavior before developers install, starting with skills.sh's 60,000+ skills.

Product
Socket now supports PHP with full Composer and Packagist integration, enabling developers to search packages, generate SBOMs, and protect their PHP dependencies from supply chain threats.