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

object-accessors

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

object-accessors

Setup truly private variables, getters, setters

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Object-Accessor

Initially this module was developed for designing SDKs in a similar way you would in OOP based languages and therefore make the SDK more maintainable. Using this module you get:

  • ✅ truly private variables
  • ✅ getters
  • ✅ setters

to restrict the accessibility and to make sdk's across multiple languages more maintainble by designing them in a similar way.

Setup

npm install object-acessibility -s

Usage

function Client() {

  // Add a state
  const state = (state => {
    // q can't be modified
    state.q = 2;
    // "priate" ths is really private
    state.private = 100;

    // we could add something calculated here like
    // state.calced = this.state.private / 100;
    return state;
  })({});

  // Add Getters
  const getters = state => ({
    q: () => state.q,
    value: () => state.value,
    calculatedValue: () => (state.value / state.q * state.private)
  });

  // Add Setters
  const setters = state => ({
    value: (val) => {state.value = val}
  })

  // Use the accessibility lib
  return accessability({ getters, setters, state });
}

const testClient = Client();

console.log(testClient.value);
// undefined

// Set a value
testClient.value = 500;

console.log(testClient.value);
// 500

// We can't set values without a setter
testClient.q = 200
console.log(testClient.q);
// 2

// We can't access values without a getter
console.log(testClient.private)
// undefined

Keywords

FAQs

Package last updated on 14 Dec 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