New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

haccessed

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

haccessed

Snoop on your objects and see what they're up to

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

HACCESSED

Snoop on your objects and see what they're up to

npm version Build Status Coverage Status

About

Haccessed is a function that "hijacks" an object, clones it, and exposes a "hidden" __print__ method. This __print__ method will return the original object filtering out un-accessed properties. It does this by using the Object.defineProperty method, which keeps the original object intact whilst monitoring lookups on properties.

Compatibility

This module is wrapped in UMD, and will work in any JavaScript environment that supports ES5 features.

You can:

  • Bundle it in your webpack build.
  • require it in node.
  • Use it in rewire or jest.mock.
  • require it AMD style for requirejs.

Use Cases

  • Validate which fields of an API are being actively used.
  • Inject into a test to validate lookups.
  • Verify that fields aren't being used after a deprecation.
  • Ensure pseudo-private _hidden fields aren't getting called.

Simple Example

const haccessed = require('haccessed');
const myObject = { id: 123, name: 'joel' };
const hijacked = haccessed(myObject);

hijacked.id; // referencing the id

hijacked.__print__(); // => { id: 123 }

Complex Example

const haccessed = require('haccessed');
const myObject = {
  id: 1,
  name: 'joel',
  address: {
    zip: '55555',
    state: 'wa'
  },
  friends: [{
    id: 2,
    name: 'bob'
  }, {
    id: 3,
    name: 'jane'
  } , {
    id: 4,
    name: 'sue'
  }]
};
const hijacked = haccessed(myObject);

hijacked.id;
hijacked.address.state;
hijacked.friends[0].name;

hijacked.__print__();
/*
{
  id: 1,
  address: {
    state: 'wa'
  },
  friends: [{ name: 'bob' }]
}
*/

TODO

  • eslint
  • travis-ci
  • More fully-featured interface (accessed, inaccessed, unavailable)
  • More edgcase tests
  • Code coverage

Keywords

FAQs

Package last updated on 27 Apr 2017

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