Socket
Book a DemoInstallSign in
Socket

defp

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

defp

Define object properties in an easier way

1.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

defp.js

NPM version Dependency Status Travis CI codecov

Define object properties in an easier way. Inspired by prr.

Install

npm i defp

Requirements

  • defp written in ES2015, use transpiler when needed
  • Add Object.assign polyfill if it's not available

Usage

const defp = require('defp')

defp(TARGET_OBJECT, KEY, [VALUE, [DESCRIPTOR_OPTIONS]])
defp(obj, 'foo', 'baz')

Equals to:

Object.defineProperty(obj, 'foo', {
  configurable: false,
  enumerable: false,
  writable: false,
  value: 'baz'
})

Descriptor options

defp(obj, 'foo', 'baz', 'cew')
// c === configurable
// e === enumerable
// w === writable

defp(obj, 'foo', {
  configurable: true,
  enumerable: true,
  writable: true,
  value: 'baz'
})

Equals:

Object.defineProperty(obj, 'foo', {
  configurable: true,
  enumerable: true,
  writable: true,
  value: 'baz'
})

getter and setter:

defp(obj, 'foo', {
  get () { return this._foo },
  set (val) { this._foo = val }
})

Overriding descriptor options for special key:

defp(obj, {
  privateVar: {
    enumerable: false,
    value: 'privateVar'
  },

  publicVar: 'publicVar'
}, 'ew')

Note:

  • If VALUE contains one of these keys: get, set, value, enumerable, configurable, defp will treat VALUE as a descriptor.

FAQs

Package last updated on 29 Mar 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

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.