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

sole-entry

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sole-entry

Get the sole entry of an object.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

sole-entry

Get the sole entry of an object.

Pretty much just const [entry] = Object.entries(obj);, but asserts that entry is the only entry.

Install

$ yarn add sole-entry

Usage

const soleEntry = require('sole-entry');

// Returns ['foo', 1];
const entry = soleEntry({foo: 1});

// This throws.
soleEntry({foo: 1, bar: 2});

// So does this.
soleEntry({});

// This throws with a custom message.
soleEntry({}, 'This object has no sole.');

API

soleEntry(obj, [message])

Returns the sole entry of obj, or throws if it does not have exactly one entry.

obj

  • Type: object

message

An object. Hopefully with one and only one entry.

  • Type: 'string'

An optional message to throw. Defaults to '"obj" must have one and only one property.'.

License

MIT © Matthew Fernando Garcia

FAQs

Package last updated on 13 Aug 2019

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