https://github.com/writetome51/typescript-base-class
An abstract Typescript/Javascript class with properties and methods that maybe every class should have
https://github.com/writetome51/typescript-base-class
abstract base-class class javascript typescript
Last synced: 2 months ago
JSON representation
An abstract Typescript/Javascript class with properties and methods that maybe every class should have
- Host: GitHub
- URL: https://github.com/writetome51/typescript-base-class
- Owner: writetome51
- License: mit
- Created: 2018-12-16T08:35:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-07T17:17:13.000Z (over 4 years ago)
- Last Synced: 2025-02-02T09:04:35.496Z (3 months ago)
- Topics: abstract, base-class, class, javascript, typescript
- Language: TypeScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BaseClass
An abstract Typescript/Javascript class with properties and methods that maybe
every class should have.## Properties
#### className: string (read-only)
## Methods
```
protected _createGetterAndOrSetterForEach(
propertyNames: string[],
configuration: IGetterSetterConfiguration
) : void
/*********************
Use this method when you have a bunch of properties that need getter and/or
setter functions that all do the same thing. You pass in an array of string
names of those properties, and the method attaches the same getter and/or
setter function to each property.
IGetterSetterConfiguration is this object:
{
get_setterFunction?: (
propertyName: string, index?: number, propertyNames?: string[]
) => Function,
// get_setterFunction takes the property name as first argument and
// returns the setter function. The setter function must take one
// parameter and return void.
get_getterFunction?: (
propertyName: string, index?: number, propertyNames?: string[]
) => Function
// get_getterFunction takes the property name as first argument and
// returns the getter function. The getter function must return something.
}
*********************/
protected _returnThis_after(voidExpression: any) : this
// voidExpression is executed, then function returns this.
// Even if voidExpression returns something, the returned data isn't used.protected _errorIfPropertyHasNoValue(
property: string, // can contain dot-notation, i.e., 'property.subproperty'
propertyNameInError? = ''
) : void
// If value of this[property] is undefined or null, it triggers fatal error:
// `The property "${propertyNameInError}" has no value.`
```## Explanation of syntax in above code examples
Variable declaration: `varName: type`
Function declaration: `functionName(...parameters): type_returned`When specifying a variable type must be a specific function:
`varName: (...parameters) => type_returned`Optional parameter in a function:
`parameterName? = (default_value)` or `parameterName?: type`Optional property in an object: `propertyName?: type`
Variable parsed inside a literal string:
```
`This is a string containing the value of ${varName}`
```## Installation
`npm i @writetome51/base-class`## Loading
```js
import { BaseClass } from '@writetome51/base-class';
```## License
[MIT](https://choosealicense.com/licenses/mit/)