1.0.30 • Published 5 years ago

@kingjs/object-ex v1.0.30

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

@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, ... })
APIlazystatic
defineProperty
defineLazyPropertyx
defineLazyStaticPropertyxx

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, ... })
APIfunctionlazystatic
defineFunctionx
defineLazyFunctionxx
defineLazyStaticFunctionxxx

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 })
APIconfigurableenumerablewritable
setFieldxxx
setHiddenFieldxx
setConstFieldxx
setHiddenConstFieldx
defineFieldxx
defineHiddenFieldx
defineConstFieldx
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], ... })
APIconfigurableenumerablelazystatic
setAccessorxx
setHiddenAccessorx
setLazyAccessorxxx
setHiddenLazyAccessorxx
setLazyStaticAccessorxxxx
setHiddenLazyStaticAccessorxxx
defineAccessorx
defineHiddenAccessor
defineLazyAccessorxx
defineHiddenLazyAccessorx
defineLazyStaticAccessorxxx
defineHiddenLazyStaticAccessorxx

Remarks

Install

With npm installed, run

$ npm install @kingjs/object-ex

License

MIT

Analytics

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago