• Stars
    star
    265
  • Rank 154,577 (Top 4 %)
  • Language
    JavaScript
  • License
    The Unlicense
  • Created about 6 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Exception-free nested nullable attribute accessor

mb

goat

Exception-free nested nullable attribute accessor. An alternative to facebookincubator/idx in 38 bytes.


Install

Just copy/paste this function into your project:

var mb=p=>o=>p.map(c=>o=(o||{})[c])&&o

Alternatively, you can download mb.js.

Use

var getHello = mb(["a", "b", 0, "hello"]);
var getHelloLength = mb(["a", "b", 0, "hello", "length"]);

var obj1 = {
  a: {
    b: [{ hello: "world" }]
  }
};

var obj2 = {
  c: {
    d: "e"
  }
};

getHello(obj1); // world
getHelloLength(obj1); // 5

getHello(obj2); // undefined
getHelloLength(obj2); // undefined

Contribution and Code-Golfing

  1. Clone and shorten current code.
  2. Please open test.html in your browser and open console to see if all the tests pass.

Contributors

More Repositories

1

react-snowstorm

A Snow Effect component for React.
JavaScript
224
star
2

jsgs

Javascript implementation of the Pico-8 fantasy console
JavaScript
134
star
3

redux-shared-worker

A higher order Redux store that runs the actual store in a SharedWorker or WebWorker.
JavaScript
71
star
4

Headhunter-Savar

71
star
5

Kangaroo

A simple bookmarks manager built with react and backbone with flux architechure.
JavaScript
47
star
6

tweet-storm

JavaScript
40
star
7

muuvie

A simple movie search app using omdb api
JavaScript
37
star
8

glitchyglitch-client

Source code for glitchyglitch.com's client application.
JavaScript
11
star
9

elm-weather

Elm
10
star
10

threedify

Automatically creates 3d views of webpages
CSS
7
star
11

fffonts

A Google fonts viewer written in elm
Elm
6
star
12

Ore

Stateful Stores that tuned for high performance by utilizing Immutablejs and internal emit loop, for your Flux applications.
JavaScript
5
star
13

rc-tracker

RC Inventory&Log management app
JavaScript
4
star
14

elm-pad

Elm
4
star
15

storaj

A simple localstorage helper that written in Coffeescript
CoffeeScript
4
star
16

hnReader

Hacker news reader app for mac
CoffeeScript
3
star
17

nvim-config

neovim config
Lua
3
star
18

duolove

Lua
3
star
19

simpubl

Simple publish/subscribe implementation with javascript
JavaScript
2
star
20

electronic

JavaScript
2
star
21

elm-flow-webpack-example

A minimal example of using elm with webpack and flow typed javascript
JavaScript
2
star
22

To-do-List

CSS
2
star
23

cutting-edge-react

React + Redux + Webpack counter example.
JavaScript
2
star
24

edf-parser

An edf parser defined in Kaitai Struct
C++
2
star
25

multi-axis-slider

A multi axis slider implementation
2
star
26

dotfiles

My dotfiles.
Shell
1
star
27

SAP1

JavaScript
1
star
28

dewpoint_calculator

TypeScript
1
star
29

create-next-auth-app

Create a Next.js app with authentication using NextAuth.js
TypeScript
1
star