Socket
Book a DemoInstallSign in
Socket

mosdef

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mosdef

Add property getters.

latest
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

mosdef -- Functional conveniences for property definitions.

Add property getters.

let o = {}
mosdef(o, 'key', () => 'my value')

Set a single getter for many keys.

let p = {} // private object
let o = {}
mosdef(o, ['key1', 'key2'], key => p[key])

Can do setters as well.

let p = {} // private object
let o = {}
mosdef(o, ['key1', 'key2'], {
  get: key => p[key],
  set: (value, key) => { p[key] = value }
})

Can use a table for mapping instead. Can also run through multiple objects.

let p = {} // private object
let o = {}
let o2 = {}

let getPrivate = key => p[key]
let setPrivate = (value, key) => { p[key] = value }
let trySelf = (key, obj) => obj['_' + key] || p[key]

mosdef([o, o2], {
  key1: {get: getPrivate, set: setPrivate},
  key2: getPrivate,
  key3: trySelf
})

FAQs

Package last updated on 27 Feb 2017

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