Skip to content

Clean ​

Essential building blocks of Clean Architecture: creation of business entities, business types (NewType), use cases, repositories, and more. Makes it easier to structure your code according to Clean Architecture principles for better maintainability and testability.

How to import? ​

The library exposes the DClean and C namespaces from the main entry or via direct import (tree-shaking friendly), which lets you only load what you need.

typescript
import { DClean, C } from "@duplojs/utils";
import * as DClean from "@duplojs/utils/clean";
import * as C from "@duplojs/utils/clean";

Primitives ​

Primitives let you handle base types (String, Number, Date, …) in business code.

Constraints ​

Constraints allow adding additional rules on primitives.

castConstraint ​

Extends a constrained value with compatible constraints without re-validating it.

toMapDataParser ​

Converts a Clean handler into a DataParser mapped to a wrapped object.

NewType ​

Creates a NewType (brand) backed by a DataParser or primitive handler, with optional constraints.

Entities ​

Represents business data structures.

unwrapEntity ​

Turns an entity into a plain object with its metadata.

Maybe ​

Defines an explicit business contract to represent a present (some) or absent (none) entity.

Flag ​

Dynamically adds information (flag) on an entity, with strict typing.

Evidence ​

Defines a typed business flow marker, added through appendEvidence.

Repository ​

Declares a repository contract using a semantic wrapper around createPort.

Port ​

Declares a port (contract) and type-checks the implementation.

UseCase ​

Declares a use case with dependencies (repositories or other use cases).

chainedFunction ​

Declares an aggregate of linked business actions that must run in order.

Operations on primitives ​

equal ​

Compares two wrapped primitives (or a primitive and a raw value) with a type guard.

matchWithString ​

Performs exhaustive matching with raw string keys and passes the narrowed original Clean primitive.

matchWithNumber ​

Performs exhaustive matching with raw number keys and passes the narrowed original Clean primitive.

add ​

Adds two Number (supports the curried version).

subtract ​

Subtracts a number from a Number (supports the curried version).

multiply ​

Multiplies a Number (supports the curried version).

divide ​

Divides a Number (supports the curried version).

min ​

Returns the minimum of a Number tuple.

max ​

Returns the maximum of a Number tuple.

greaterThan ​

Checks whether a Number is strictly greater than a threshold.

lessThan ​

Checks whether a Number is strictly less than a threshold.

concat ​

Concatenates String (supports the curried version).

length ​

Returns the length of a String as a Number.

lengthEqual ​

Checks whether the length of a String equals a value.

lengthGreaterThan ​

Checks whether the length of a String is greater than a value.

lengthLessThan ​

Checks whether the length of a String is less than a value.

dateGreaterThan ​

Checks whether a Date is after a threshold.

dateLessThan ​

Checks whether a Date is before a threshold.

dateAddTime ​

Adds a Time duration to a Date.

dateSubtractTime ​

Subtracts a Time duration from a Date.

dateMin ​

Returns the smallest date in a list.

dateMax ​

Returns the largest date in a list.

timeGreaterThan ​

Checks whether a Time is strictly greater than a threshold.

timeLessThan ​

Checks whether a Time is strictly less than a threshold.

timeMin ​

Returns the smallest duration in a list.

timeMax ​

Returns the largest duration in a list.

sort ​

Sorts an array of primitives (String, Number, Date, or Time) in "ASC" / "DSC".

Released under the MIT license.