Socket
Socket
Sign inDemoInstall

assign-properties

Package Overview
Dependencies
2
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    assign-properties

An Object.assign like utility that preserve descriptors


Version published
Weekly downloads
16
increased by6.67%
Maintainers
1
Install size
15.7 kB
Created
Weekly downloads
 

Readme

Source

assignProperties

Build Status Coverage Status WebReflection status

An Object.assign like utility that preserve descriptors, as in accessors or value, or configurable, or writable, etc.

import assignProperties from 'assign-properties';
const assignProperties = require('assign-properties');
// <script src="https://unpkg.com/assign-properties">

Same Object.assign API

// the issue with assign is that copies are values
const before = Object.assign({}, {get random() { return Math.random() }});

// mixins are broken this way
before.random === before.random; // true

// with assignProperties, everything is fine
const after = assignProperties({}, {get random() { return Math.random() }});

// the getter is passed along instead of being lost in the process
after.random === after.random; // false

Object spread suffers the same issue

const base = {get random() { return Math.random() }};
const spread = {...base};
spread.random === spread.random; // true

So, if you want to bring accessors to the mix, this module is your stop.

Keywords

FAQs

Last updated on 14 Feb 2020

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc