@raccoons-co/ethics
Version:
Clean code ethics.
102 lines (58 loc) • 2.8 kB
Markdown
[](https://badge.fury.io/js/@raccoons-co%2Fethics)
[](https://sonarcloud.io/summary/new_code?id=raccoons-co_ethics)
[](https://codecov.io/gh/raccoons-co/ethics)
[](https://dl.circleci.com/status-badge/redirect/gh/raccoons-co/ethics/tree/master)
Clean Code Ethics
#### Install library
```shell script
% npm i @raccoons-co/ethics
```
Strict
#### `Strict.notNull(...)`
>*public static notNull\<T>(reference: T, message?: string): NonNullable\<T>*
Ensures that an object reference is not null.
Returns the non-null reference that was validated.
Throws `NullPointerException` if reference is null.
#### `Strict.checkArgument(...)`
>*public static checkArgument(expression: boolean, message?: string): void*
Ensures the truth of an expression.
Throws `IllegalArgumentException` if expression is false.
Optional
#### `Optional.empty()`
>*public static empty\<T>(): Optional<Exclude<T, undefined>>*
Returns an empty optional with no present value to get.
#### `Optional.of(...)`
>*public static of\<T>(value: T): Optional<NonNullable\<T>>*
Returns an optional of given non-null value.
#### `Optional.ofNullable(...)`
>*public static ofNullable\<T>(value: T): Optional<NonNullable\<T>>*
Returns an optional of given non-null value, otherwise an empty optional.
#### Optional `isEmpty()`
>*public isEmpty(): boolean*
Returns status of value absence.
#### Optional `isPresent()`
>*public isPresent(): boolean*
Returns status of value presence.
#### Optional `get()`
>*public get(): T*
Returns the value if present or empty optional throws NoSuchElementException.
#### Optional `orElseThrow()`
>*public orElseThrow(): T*
Returns the value if present or empty optional throws NoSuchElementException.
#### Optional `orElse(...)`
>*public orElse(otherValue: T): T*
Returns the value if present or else returns other value.
#### Optional `ifPresent(...)`
>*public ifPresent(performAction: (value: T) => void): void*
Performs the given action with the value, otherwise does nothing.
#### Optional `ifPresentOrElse(...)`
>*public ifPresentOrElse(action: (value: T) => void, emptyAction: () => void): void*
Performs the given action with the value, otherwise performs the given empty-based action.
Immutable
#### Class Annotation `@Immutable`
Encapsulates instance of annotated class into `ImmutableObject` instance which prevents mutation
of the original class instance.