Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

safetyfirst

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

safetyfirst

Safe nested lookups utilising tagged template literals functionality

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Safety First

Safe nested lookups with simple tagged template syntax

npm version

This library aims to enable safe nested lookups in manner similar to lodash/get and other such libraries but uses Tagged template literals to provide an alternate syntax.

Usage

// use whatever alias you like
const g = require('safetyfirst');

const target = {
    foo: {
        bar: {
            baz: 'quux'
            corge: ['grault']
        }
    }
};

// mirrors basic lookup functionality
g`${target}.foo.bar.baz` === 'quux'
g`${target}[foo].bar.baz` === 'quux'
g`${target}['foo'].bar.baz` === 'quux'

// normally target.waldo.fred would have thrown an error
g`${target}.waldo.fred` === undefined

// interpolation 
const bar = 'bar';
g`${target}.foo.${bar}.baz` === 'quux'
g`${target}.foo[${bar}].baz` === 'quux'

// array lookups
g`${target}.foo.bar.corge[0]` === 'grault'

Keywords

safe

FAQs

Package last updated on 25 Apr 2016

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