3.3.6 • Published 5 years ago

lives v3.3.6

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

lives

Build Status Coverage Status Minified Size

A variable lives here

Save yourself from messy & unreliable nested object checking.

  • Tiny w/ zero dependencies (500B minified)
  • 100% test coverage
  • Works in Node.js and legacy browser environments
  • Includes useful helper functions for different use cases
npm i --save lives

Usage

Lives(attempt)

const lives = require('lives');

const hello = {
  a: {
    b: {
      c: 'Hello'
    }
  }
};

const missing = {
  a: null
};

if (lives(() => hello.a.b.c)) {
  console.log(hello.a.b.c, 'World!'); // Hello World!
}

Lives.key(target, key)

if (lives.key(hello, 'a.b.c')) {
  console.log(hello.a.b.c, 'World!'); // Hello World!
}

Lives.not(attempt)

if (lives.not(() => missing.a.b.c)) {
  throw new Error('Variable is missing!');
}

Lives.get(attempt)

console.log(lives.get(() => hello.a.b.c), 'World!'); // Hello World!

lives.get(() => missing.a.b.c); // undefined

Lives.or(attempt, fallback)

console.log(lives.or(() => missing.a.b.c, 'Hello'), 'World!'); // Hello World!

Lives.is(attempt, type)

lives.is(() => hello.a.b.c, 'string'); // True

lives.is(() => hello.a.b.c, 'boolean'); // False

lives.is(() => missing.a.b.c, 'string'); // False

lives.is(() => missing.a.b.c, 'undefined'); // True
3.3.6

5 years ago

3.3.5

5 years ago

3.3.4

5 years ago

3.3.3

5 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago