New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

sleeve

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sleeve

failsafe object property checker

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

sleeve

always have an ace up your sleeve

explore, search for and read Javascript object nested properties without many a nasty error
npm version

Installation:

npm install --save sleeve

Usage:

const s = require('sleeve');

Syntax:

s(object, "chain.of.properties.that.can.be.rather.long", fallbackValue)

Examples:
const user = {
    name: "John",
    login: "jjohanson",
    contacts: {
        phoneNumber: "(555)834-1337"
    },
    location:{},
    data: {
        a:{
            b: ""
        }
    }
};
not okay:
const email = user && user.contacts && user.contacts.email && user.contacts.email.primaryEmail ? user.contacts.email.primaryEmail : "no email provided";
okay:

fallbacks:

const email = s(user, "contacts.email.primaryEmail", "no email provided");
console.log(email);  // "no email provided"

property checking:

let countryCode;
if (!s(user, "location.country.code")) {
    countryCode = "US";
}

reading value:

console.log(s(user, "data.a.b.c.going.too.deep")); // null

callback function:

s(user, "i.do.not.know.where.to.go", () => console.log("this is a fail"));

Keywords

object

FAQs

Package last updated on 08 Jul 2018

Did you know?

Socket

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.

Install

Related posts