Package Exports
- @raccoons-co/ethics
- @raccoons-co/ethics/lib/main/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@raccoons-co/ethics) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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.