@raccoons-co/ethics
TypeScript icon, indicating that this package has built-in type declarations

0.4.3 • Public • Published

npm version Maintainability Rating codecov CircleCI

Clean Code Ethics

Install library

% 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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.4.32latest

Version History

VersionDownloads (Last 7 Days)Published
0.4.32
0.4.21
0.4.11
0.4.01
0.3.10
0.3.00
0.2.40
0.2.30
0.2.20
0.2.00
0.1.10

Package Sidebar

Install

npm i @raccoons-co/ethics

Weekly Downloads

5

Version

0.4.3

License

MIT

Unpacked Size

77.4 kB

Total Files

37

Last publish

Collaborators

  • iselo