@@ -45,16 +45,18 @@ All modules implement identical functionality:
4545- ** debounce** : Function execution delay with cancellation
4646- ** isEmail** : Email validation using regex patterns
4747- ** formatCurrency** : Localized currency formatting
48+ - ** clamp** : Constrain a number within an inclusive [ min, max] range
49+ - ** throttle** : Limit function execution to at most once per wait period
4850
4951## API Parity Contract
5052
5153This section defines the formal contract for cross-platform API consistency in KompKit.
5254
5355### What is Guaranteed
5456
55- - ** Function names** are identical across all platforms (` debounce ` , ` isEmail ` , ` formatCurrency ` ).
57+ - ** Function names** are identical across all platforms (` debounce ` , ` isEmail ` , ` formatCurrency ` , ` clamp ` , ` throttle ` ).
5658- ** Behavioral semantics** are identical: given the same inputs, all platforms produce the same observable output.
57- - ** Default values** are identical: ` wait = 250ms ` , ` currency = "EUR " ` , ` locale = "en-US" ` .
59+ - ** Default values** are identical: ` wait = 250ms ` , ` currency = "USD " ` , ` locale = "en-US" ` .
5860- ** Error handling philosophy** is consistent: invalid inputs that cannot produce a meaningful result throw/throw-equivalent errors. Silent fallbacks are not permitted.
5961- ** Cancel capability** : ` debounce ` returns an object with a ` cancel() ` method on all platforms, allowing callers to discard pending executions (required for safe use in component lifecycles).
6062
@@ -70,9 +72,11 @@ This section defines the formal contract for cross-platform API consistency in K
7072Every utility follows the same mental model regardless of platform:
7173
7274```
73- debounce(action, options) → Debounced<T> (with .cancel())
74- isEmail(value) → Boolean
75- formatCurrency(amount, options) → String
75+ debounce(action, options) → Debounced<T> (with .cancel())
76+ isEmail(value) → Boolean
77+ formatCurrency(amount, options) → String
78+ clamp(value, min, max) → Number
79+ throttle(fn, wait) → Throttled<T> (with .cancel())
7680```
7781
7882A developer familiar with the TypeScript API should be able to use the Kotlin or Dart API with only idiomatic adjustments — not conceptual re-learning.
@@ -120,9 +124,21 @@ export function isEmail(value: string): boolean;
120124
121125export function formatCurrency(
122126 amount : number ,
123- currency ? : string , // default: "EUR "
127+ currency ? : string , // default: "USD "
124128 locale ? : string , // default: "en-US"
125129): string ;
130+
131+ export function clamp(value : number , min : number , max : number ): number ;
132+
133+ export interface Throttled <T extends (... args : any []) => void > {
134+ (... args : Parameters <T >): void ;
135+ cancel(): void ;
136+ }
137+
138+ export function throttle<T extends (... args : any []) => void >(
139+ fn : T ,
140+ wait : number , // must be > 0
141+ ): Throttled <T >;
126142```
127143
128144** Kotlin:**
@@ -143,9 +159,22 @@ fun isEmail(value: String): Boolean
143159
144160fun formatCurrency (
145161 amount : Double ,
146- currency : String = "EUR ",
162+ currency : String = "USD ",
147163 locale : String = "en-US ", // converted internally to java.util.Locale
148164): String
165+
166+ fun clamp (value : Double , min : Double , max : Double ): Double
167+
168+ class Throttled <T >(private val invoke : (T ) -> Unit ) {
169+ operator fun invoke (value : T ): Unit
170+ fun cancel (): Unit
171+ }
172+
173+ fun <T > throttle (
174+ waitMs : Long , // must be > 0
175+ scope : CoroutineScope , // platform constraint: structured concurrency
176+ action : (T ) -> Unit ,
177+ ): Throttled <T >
149178```
150179
151180** Dart:**
@@ -165,9 +194,21 @@ bool isEmail(String value);
165194
166195String formatCurrency(
167196 num amount, {
168- String currency = "EUR ",
197+ String currency = "USD ",
169198 String locale = "en-US",
170199});
200+
201+ double clamp(double value, double min, double max);
202+
203+ class Throttled<T> {
204+ void call(T arg);
205+ void cancel();
206+ }
207+
208+ Throttled<T> throttle<T>(
209+ void Function(T) fn,
210+ Duration wait, // must be > Duration.zero
211+ );
171212```
172213
173214### Platform-Specific Adaptations
@@ -180,20 +221,26 @@ While maintaining API consistency, we leverage platform strengths:
180221- ** setTimeout/clearTimeout** for timing control
181222- ** Intl.NumberFormat** for currency formatting
182223- ** RegExp** for email validation
224+ - ** Math.min/Math.max** for clamp
225+ - ** setTimeout/clearTimeout** for throttle timer
183226
184227#### Kotlin Implementation
185228
186229- ** Coroutines** for asynchronous debounce operations
187230- ** Job cancellation** for timing control
188231- ** NumberFormat/Currency** for localized formatting
189232- ** Regex** for email validation
233+ - ** Double.coerceIn** for clamp
234+ - ** Coroutine delay + Job** for throttle wait period
190235
191236#### Dart/Flutter Implementation
192237
193238- ** Timer** for debounce scheduling and cancellation
194239- ** intl package** (` NumberFormat.currency ` ) for localized formatting
195240- ** RegExp** for email validation
196241- ** Null safety** with full type-safe APIs
242+ - ** num.clamp** for clamp
243+ - ** Timer** for throttle scheduling (same as debounce)
197244
198245## Build System Architecture
199246
@@ -272,16 +319,20 @@ android.yml:
272319
273320` ` `
274321packages/core/web/tests/
275- └── core.test.ts # All utility tests
322+ ├── core.test.ts # debounce, isEmail, formatCurrency tests
323+ ├── clamp.test.ts # clamp unit tests
324+ └── throttle.test.ts # throttle unit tests
276325
277326packages/core/android/src/test/kotlin/com/kompkit/core/
278- └── CoreTests.kt # All utility tests
327+ └── CoreTests.kt # All utility tests (incl. ThrottleTests, ClampTests)
279328
280329packages/core/flutter/test/
281330├── kompkit_core_test.dart # Integration tests
282331├── debounce_test.dart # Debounce unit tests
283332├── validate_test.dart # Validation unit tests
284- └── format_test.dart # Formatting unit tests
333+ ├── format_test.dart # Formatting unit tests
334+ ├── clamp_test.dart # Clamp unit tests
335+ └── throttle_test.dart # Throttle unit tests
285336```
286337
287338### Test Coverage
0 commit comments