reconstruct-descriptors
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

reconstruct-descriptors

Build Status

Deeply reconstruct any object iterating over its property descriptors.

Install

reconstruct-descriptors is published on NPM Registry, so you can install it using any node package manager.

npm install reconstruct-descriptors
 
# If you're using Yarn. 
yarn add reconstruct-descriptors

Usage

This module exports a function that receives an object and a function to iterate over property descriptors.

import reconstruct from 'reconstruct-descriptors'
 
const immutable = (object) => reconstruct(object, (descriptor, property) => ({
  [property]: {
    ...descriptor,
    writable: false,
    configurable: false
  }
}))
 
const user = immutable({ name: 'Ryan' })
 
user.name = 'Bruno'
console.log(user.name) // 'Ryan'
 
delete user.name
console.log(user.name) // 'Ryan'

License

Released under MIT license. You can see it here.

/reconstruct-descriptors/

    Package Sidebar

    Install

    npm i reconstruct-descriptors

    Weekly Downloads

    62

    Version

    0.3.0

    License

    MIT

    Unpacked Size

    10.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • vitorluizc