3.0.5 • Published 2 years ago

proto-decorator v3.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

Proto Decorator

A decorator for setting a property on the class prototype (previously known as typescript-proto-decorator).

Coverage Status

NPM

Compatibility

  • Typescript - full
  • Spec-compliant decorator proposal - full
  • Babel (current proposal) - full
  • Babel (legacy) - full

API

/**
 * Sets a value on the class' prototype
 * @param value The value to set
 * @param options Options to set. Defaults to configurable, enumerable and writable.
 */
function Proto(value: any, options?: Pick<PropertyDescriptor, 'configurable' | 'enumerable' | 'writable'>): PropertyDecorator;

Usage

import {Proto} from 'proto-decorator';

class MyClass {
  
  // set MyClass.prototype.foo = 'bar'
  @Proto('bar')
  public foo: string;
  
  // set MyClass.prototype.count = 1; It will be non-enumerable, non-writable.
  @Proto(1, {writable: false, enumerable: false})
  public readonly count: number;
}

Shortcuts

  • You can use @Proto.immutable as a shortcut for {configurable: false, enumerable: true, writable: false}.
  • You can use @Proto.hidden as a shortcut for {configurable: true, enumerable: false, writable: true}.
  • You can use @Proto.immutableHidden as a shortcut for {configurable: false, enumerable: false, writable: false}.

The UMD global name is ProtoDecorator.

3.0.5

2 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.1.0

5 years ago