🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

assign-properties

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

assign-properties

An Object.assign like utility that preserve descriptors

0.1.1
latest
npm
Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
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

Object

FAQs

Package last updated on 14 Feb 2020

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