Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

private-proxy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

private-proxy

Convert any object into one that supports private properties, using the familiar Object API for getting and setting keys.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Features

  • Convert any object into one that supports private, immutable properties.
  • Leverages the Proxy object.
  • Objects retain original prototype.
  • Objects are inspectable, and non-private properties are mutable/inspectable.

Getting Started

yarn install private-proxy

const pp = require('private-proxy');

const myObject = pp({});

myObject.dog = 'Fido';
console.log(myObject);
//=> {}

console.log(myObject.dog);
//=> 'Fido'

Examples

Works with any objects, included classes
const pp = require('private-proxy');

class Person {
  constructor(name) {
    this.name = name; //Non-private property
  }
}

const me = pp(new Person('Rob')); //Any properties defined hereafter are private

Object keeps prototype
console.log(me);
//=> Person { name: 'Rob' }
Any property not defined before conversion can be set, but not inspected
me.age = 30; // me.age is a private property as it was not defined prior to conversion
console.log(me);
//=> Person { name: 'Rob' }
But can be accessed directly
console.log(me.age);
//=> 30
Non-private properties remain mutable
me.name = 'Joey';
console.log(me);
//=> Person { name: 'Joey' }
Private properties are immutable
me.age = 35;
console.log(me.age);
//=> 30
Undefined properties return undefined
console.log(me.dog);
//=> undefined

Keywords

FAQs

Package last updated on 07 May 2018

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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc