https://github.com/alorel/typescript-proto-decorator
Sets a value on a class' prototype
https://github.com/alorel/typescript-proto-decorator
decorator prototype typescript
Last synced: 2 days ago
JSON representation
Sets a value on a class' prototype
- Host: GitHub
- URL: https://github.com/alorel/typescript-proto-decorator
- Owner: Alorel
- License: mit
- Created: 2017-11-19T05:41:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T20:45:40.000Z (over 2 years ago)
- Last Synced: 2024-10-11T01:11:42.610Z (7 months ago)
- Topics: decorator, prototype, typescript
- Language: JavaScript
- Homepage:
- Size: 2.02 MB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Proto Decorator
A decorator for setting a property on the class prototype
(previously known as [typescript-proto-decorator](https://www.npmjs.com/package/typescript-proto-decorator)).[](https://coveralls.io/github/Alorel/typescript-proto-decorator?branch=3.0.5)
[](https://www.npmjs.com/package/proto-decorator)
# Compatibility
- Typescript - full
- Spec-compliant decorator proposal - full
- Babel (current proposal) - full
- Babel (legacy) - full# API
```typescript
/**
* 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): PropertyDecorator;
```# Usage
```typescript
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`.