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

@kingjs/object-ex

v1.0.30

Published

```js var objectEx = require('@kingjs/object-ex'); ``` --- Property descriptors are divided into classes named: - `field` - `function` - `accessor` - `property`

Downloads

11

Readme

@kingjs/object-ex

Usage

var objectEx = require('@kingjs/object-ex');

Property descriptors are divided into classes named:

  • field
  • function
  • accessor
  • property

Each class name is prefixed with various combinations to form an export:

  • set or define: Configurable or not configurable respectively.
  • hidden: Not enumerable, otherwise enumerable
  • const: Not writable, otherwise writable
  • lazy: Inject stub that will cache result on this at runtime.
  • static: Modifies lazy. Use if target and this are the same at runtime.

Each function ultimately calls @kingjs/property-descriptor.create.

Each class of exports supports different overrides. For example the following are equivalent:

defineFunction(target, 'foo', { value: function() { ... } })
defineFunction(target, { value: function foo() { ... } })
defineFunction(target, function foo() { ... })

Any properties specified in an override that takes a descriptor will override those properties implied by the prefix. For example, the following will produce an enumerable accessor:

defineHiddenAccessor(target, 'bar', { enumerable: true, get: () => ... })

Strings that appear where functions are expected will be used to construct an appropriate Function. For example, the following are equivalent:

// function lambda
defineFunction(target, 'foo', 'this.bar')
defineFunction(target, 'foo', function() { return this.bar; })

// get/set lambdas
defineFunction(target, 'foo', 'this.bar', 'this.bar = value')
defineAccessor(target, 'foo', 
  function() { return this.bar; })
  function(value) { this.bar = value; }
)

// function NOT expected so string treated as a value
defineField(target, 'foo', 'this.bar')
defineProperty(target, 'foo', { value: 'this.bar' })

Property API

These overrides are supported for all APIs, not just defineProperty:

defineProperty(target, namedFunction)
defineProperty(target, name, function)
defineProperty(target, name, { value: function, ... })

|API|lazy|static| |---|---|---| |defineProperty| |defineLazyProperty|x| |defineLazyStaticProperty|x|x|

Function API

The Function API family is just like the Property API family except all descriptors are tagged with function. So the following are equivalent:

defineFunction(target, namedFunction)
defineFunction(target, name, function)
defineFunction(target, name, { value: function, ... })
defineProperty(target, name, { value: function, function: true, ... })

|API|function|lazy|static| |---|---|---|---| |defineFunction|x| |defineLazyFunction|x|x| |defineLazyStaticFunction|x|x|x|

Field API

The Field family does not support passing a descriptor. Instead, the value is always wrapped in a descriptor as value. So the following are equivalent:

defineField(target, name, value)
defineProperty(target, name, { value })

|API|configurable|enumerable|writable| |---|---|---|---| |setField|x|x|x| |setHiddenField|x||x| |setConstField|x|x|| |setHiddenConstField|x|| |defineField||x|x| |defineHiddenField|||x| |defineConstField||x|| |defineHiddenConstField|||

Accessor API

These overrides are supported for all prefixes, not just defineAccessor:

defineAccessor(target, namedGetter[, namedSetter])
defineAccessor(target, name, getter[, setter])
defineAccessor(target, { namedGetter[, namedSetter], ... })
defineAccessor(target, name, { getter[, setter], ... })

|API|configurable|enumerable|lazy|static| |---|---|---|---|---| |setAccessor|x|x| |setHiddenAccessor|x| |setLazyAccessor|x|x|x| |setHiddenLazyAccessor|x||x| |setLazyStaticAccessor|x|x|x|x| |setHiddenLazyStaticAccessor|x||x|x| |defineAccessor||x| |defineHiddenAccessor| |defineLazyAccessor||x|x| |defineHiddenLazyAccessor|||x| |defineLazyStaticAccessor||x|x|x| |defineHiddenLazyStaticAccessor|||x|x|

Remarks

Install

With npm installed, run

$ npm install @kingjs/object-ex

License

MIT

Analytics