Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/singleware/class
Class visibility package.
https://github.com/singleware/class
async browser class decorators javascript member-visibility oop singleware typescript
Last synced: 4 days ago
JSON representation
Class visibility package.
- Host: GitHub
- URL: https://github.com/singleware/class
- Owner: Singleware
- License: mit
- Created: 2018-07-14T14:56:19.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-31T19:09:27.000Z (almost 6 years ago)
- Last Synced: 2024-11-07T19:09:43.533Z (8 days ago)
- Topics: async, browser, class, decorators, javascript, member-visibility, oop, singleware, typescript
- Language: JavaScript
- Size: 64.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Class
This package provides some decorators to ensure the class member visibility at runtime.
## How it works
When the JS run all decorators defined for your class will wrap the original methods to check its access rules, before pass the control back to the original method if the called method is private or protected, the wrapper goes check the context to determine if the current call is granted or not.
## Usage
```ts
import * as Class from '@singleware/class';@Class.Describe()
class Example extends Class.Null {
@Class.Private()
private privateProperty = '';@Class.Protected()
@Class.Property()
protected protectedProperty = '';@Class.Public()
@Class.Property()
public publicProperty = '';@Class.Private()
private privateMethod(): void {}@Class.Protected()
protected protectedMethod(): void {}@Class.Public()
public publicMethod(): void {}
}
```### Decorators
| Name | Description |
| --------- | ------------------------------------------------------------------------------------ |
| Describe | Wraps the decorated class to ensure its rules at runtime. |
| Private | Makes the decorated member as private, visible only by its class. |
| Protected | Makes the decorated member as protected, visible on by its class and derived classes |
| Public | Makes the decorated member as public, visible by every class. |
| Property | Makes the decorates member as enumerable to use with loop statements like for... |### Methods
| Name | Description |
| ------- | ------------------------------------------------------------------ |
| perform | Performs the specified callback using the specified context rules. |
| resolve | Resolves the given wrapped context to the original context. |## Install
Using npm:
```sh
npm i @singleware/class
```## License
[MIT © Silas B. Domingos](https://balmante.eti.br)