@colisweb/rescript-toolkit 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -304,6 +304,20 @@ module UnitMeasure = {
304
304
  })
305
305
  }
306
306
 
307
+ module EnergyCapacity = {
308
+ module Config = Toolkit__Utils_UnitMeasure.EnergyCapacity
309
+
310
+ module WithUnit = MakeWithUnit({
311
+ include Config
312
+ let errorPrefix = "EnergyCapacity with unit"
313
+ })
314
+
315
+ module KWh = Make({
316
+ include Config
317
+ let wrapValue = Config.wrapValue(#kWh)
318
+ })
319
+ }
320
+
307
321
  module Weight = {
308
322
  module Config = Toolkit__Utils_UnitMeasure.Weight
309
323
 
@@ -288,6 +288,19 @@ let optionalPosFloatWeightKg = (intl, value) => {
288
288
  }
289
289
  }
290
290
  }
291
+
292
+ let optionalPosFloatEnergyCapacityKWh = (intl, value) => {
293
+ switch value {
294
+ | "" => None
295
+ | v =>
296
+ switch v->Toolkit__Decoders.UnitMeasure.EnergyCapacity.WithUnit.decodeFromString {
297
+ | Ok(#kWh(_)) => None
298
+ | _ =>
299
+ Some(Intl.formatMessageWithValues(intl, Msg.wrongFormat, {"exemple": "'10 kWh' '0.5 kWh'"}))
300
+ }
301
+ }
302
+ }
303
+
291
304
  let requiredPosFloatWeightG = (intl, value) => {
292
305
  switch value {
293
306
  | "" => Some(Intl.formatMessage(intl, Msg.requiredValue))
@@ -216,6 +216,42 @@ module Volume = {
216
216
  }
217
217
  }
218
218
 
219
+ module EnergyCapacity = {
220
+ include Unit({
221
+ @deriving(jsConverter)
222
+ type unitEnum = [
223
+ | @as(`kWh`) #kWh
224
+ ]
225
+ })
226
+
227
+ type t = [
228
+ | #kWh(float)
229
+ ]
230
+
231
+ let wrapValue = (unit: unitEnum, value: float): t =>
232
+ switch unit {
233
+ | #kWh => #kWh(value)
234
+ }
235
+
236
+ let toValue = value =>
237
+ switch value {
238
+ | #kWh(value) => value
239
+ }
240
+
241
+ let display = (value, ~digits=2, ()) => {
242
+ open Js.Float
243
+ switch value {
244
+ | #kWh(v) => v->toFixedWithPrecision(~digits) ++ ` kWh`
245
+ }
246
+ }
247
+
248
+ let toString = value => {
249
+ switch value {
250
+ | #kWh(v) => v->Float.toString ++ ` kWh`
251
+ }
252
+ }
253
+ }
254
+
219
255
  module Currency = {
220
256
  include Unit({
221
257
  @deriving(jsConverter)