npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

private-fields

v1.0.2

Published

What private fields does this object have?

Downloads

35

Readme

private-fields Version Badge

dependency status dev dependency status License Downloads

npm badge

What private fields, methods, or accessors does this class have?

:warning: :rotating_light: :warning: DISCLAIMER This capability - observing the existence, name, and in many cases, contents of class private fields/methods/accessors - is not supposed to exist. The inability to in any way interact with private fields is a critical part of their design in the JavaScript language, and is the only thing that makes them truly "private".

This is possible because node, in v12.5+ as of this writing, directly exposes the v8 engine's internal debugger protocol via the core inspector module. This should not be exposed to runtime code - it's meant for Chrome's devtools to be able to use, for debugging only. It will not work in any other environment.

Please do not use this for any non-debugging purpose. Private fields, methods, and accessors, just like closed-over variables, variable names, or function argument names, are an internal implementation detail, and they can and likely will be changed in a non-semver-major update, because by definition they are not breaking changes - since they're not observable. Consider yourself warned.

Note: this package will work down to node v8.3, but private fields support was added in node v12.0, and private methods/accessors were added in node v14.6.

Getting started

npm install --save private-fields

Usage/Examples

import getPrivateFields from 'private-fields';
import assert from 'assert';

const objectValue = { a: 1 };
const symbolValue = Symbol.iterator;
class C {
	#x;
	#y = 3;
	#foo() {}
	get #z() {}
	set #z(v) {}

	#object = objectValue;
	#symbol = symbolValue;
}

const fields = await getPrivateFields(new C());
assert.deepEqual(fields, [
	{
		name: '#foo',
		type: 'function',
		description: '#foo() {}', // functions are not provided, but their toString is
	},
	{
		name: '#z',
		get: { type: 'function', description: 'get #z() {}' },
		set: { type: 'function', description: 'set #z(v) {}' },
	},
	{
		name: '#x',
		value: undefined,
	},
	{
		name: '#y',
		value: 3,
	},
	{
		name: '#object',
		clonedValue: { a: 1 },
	},
	{
		name: '#symbol',
		clonedValue: Symbol(Symbol.iterator),
	},
]);

const [, , , , object, symbol] = fields;

assert.notEqual(object, objectValue); // the original object is not provided
assert.deepEqual(object, objectValue); // but its properties are cloned

assert.notEqual(symbol.clonedValue, Symbol.iterator); // symbols are not provided
assert.equal(symbol.description, Symbol.iterator.description); // but a symbol with the same description is

Tests

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