
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
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
import getOrElse from 'get-or-else';
export const name = (state = {}, action = {}) => {
switch(action.type) {
case 'SET_NAME':
return {
...state,
...getOrElse({ get: [action,'payload.name'], else: {} });
};
default:
return state;
}
};
see this repo get-or-else-demo
import React from 'react';
import ReactDOM from 'react-dom';
import getOrElse from 'get-or-else';
const nameObj = {
salutation: 'Mr',
name: {
first: 'James'
}
};
const salutation = getOrElse({ get: [nameObj,'salutation'], else: false });
const NameComponent = () => {
return (
<h1>
We have been expecting you
{salutation && <span> {salutation} </span>}
<span> {getOrElse({ get: [nameObj,'name.first'], else: '' })}</span>
<span> {getOrElse({ get: [nameObj,'name.last'], else: '' })}</span>
</h1>
);
};
ReactDOM.render(<NameComponent />, document.getElementById('root'));
/* NameComponent Renders `
<h1>
We have been expecting you
<span> Mr </span>
<span>James</span>
<span></span>
</h1>`
nameObj.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
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
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.