You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

hidden-state

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hidden-state

Attach hidden state to object instances

1.1.1
Source
npm
Version published
Maintainers
1
Created
Source

hidden-state

Attach hidden state to object instances.

Example

import hiddenState from 'hidden-state';

const hidden = hiddenState('Point');

class Point {

  constructor(x, y) {
    hidden(this, { x, y });
  }

  toString() {
    let { x, y } = hidden(this);
    return `<${ x }:${ y }>`;
  }

  add(point) {
    let { x: x1, y: y1 } = hidden(this);
    let { x: x2, y: y2 } = hidden(point);
    return new Point(x1 + x2, y1 + y2);
  }

  static isPoint(obj) {
    return hidden.hasState(obj);
  }

}

Install

npm install hidden-state

API

hiddenState(description?)

Creates a new hidden function for accessing the hidden state of an object. The optional description argument is used to customize TypeError messages.

hidden(obj)

Returns the hidden state associated with the specified object. If the object does not have hidden state then a TypeError is thrown.

hidden(obj, state)

Initializes the hidden state for an object.

hidden.hasState(obj)

Returns a boolean value indicating whether the object has associated hidden state.

FAQs

Package last updated on 01 Jan 2019

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