Socket
Book a DemoInstallSign in
Socket

find-value-locations

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-value-locations

Given an object, and a value, return a tuple of the property name, and the object on which it is an own property.

latest
Source
npmnpm
Version
2.1.1
Version published
Maintainers
0
Created
Source

find-value-locations Version Badge

github actions coverage License Downloads

npm badge

Given an object, and a value, return a tuple of the property name, the object on which it is an own property, and the property descriptor.

Works with string keys, Symbol keys, both enumerable and non-enumerable keys, and crawls up the prototype chain to find the exact object it's located on.

Example

var findValue = require('find-value-locations');
var assert = require('assert');

var value = {};

function Foo() {}
function Bar() {}
function Baz() {}

Object.prototype.property = value;
Function.prototype.property = value;

Bar.prototype = Baz;

Foo.prototype = new Bar();
Foo.prototype.property = value;
var symbol = Symbol('a symbol property');
Foo.prototype[symbol] = value;

var tuples = findValue(new Foo(), value);

assert.deepEqual(tuples, [
	[Foo.prototype, 'property', Object.getOwnPropertyDescriptor(Foo.prototype, 'property')],
	[Foo.prototype, symbol, Object.getOwnPropertyDescriptor(Foo.prototype, symbol)],
	[Function.prototype, 'property', Object.getOwnPropertyDescriptor(Function.prototype, 'property')],
	[Object.prototype, 'property', Object.getOwnPropertyDescriptor(Object.prototype, 'property')]
]);

Tests

Simply clone the repo, npm install, and run npm test

Keywords

find

FAQs

Package last updated on 29 Dec 2024

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