summaryrefslogtreecommitdiff
path: root/elm/Lib/Util.elm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-04-06 17:01:14 +0200
committerYorhel <git@yorhel.nl>2020-04-06 17:01:17 +0200
commit91c5ca72e9c90c5a60f71e53a68c980094a59da8 (patch)
tree18fd78ab58ae08440ed9e2f70335851c51093a9e /elm/Lib/Util.elm
parent6b04feb79ced4571150a64c19fd70539aa4596fb (diff)
Release::Edit: Consider GTIN code as a string for validation/editing
Problem is that the 'uint' validation does not allow leading zeros, which are very valid as part of GTIN codes, thus resulting in an error when validating a normalized GTIN code.
Diffstat (limited to 'elm/Lib/Util.elm')
-rw-r--r--elm/Lib/Util.elm8
1 files changed, 2 insertions, 6 deletions
diff --git a/elm/Lib/Util.elm b/elm/Lib/Util.elm
index a40a997c..f840d003 100644
--- a/elm/Lib/Util.elm
+++ b/elm/Lib/Util.elm
@@ -42,12 +42,8 @@ selfCmd : msg -> Cmd msg
selfCmd m = Task.perform (always m) (Task.succeed True)
-formatGtin : Int -> String
-formatGtin n = if n == 0 then "" else String.fromInt n |> String.padLeft 12 '0'
-
-
-- Based on VNDBUtil::gtintype()
-validateGtin : String -> Int
+validateGtin : String -> Bool
validateGtin =
let check = String.fromInt
>> String.reverse
@@ -60,4 +56,4 @@ validateGtin =
|| (n >= 2000000000000 && n < 3000000000000)
|| n >= 9770000000000
|| modBy 10 (check n) /= 0
- in String.filter Char.isDigit >> String.toInt >> Maybe.andThen (\n -> if inval n then Nothing else Just n) >> Maybe.withDefault 0
+ in String.filter Char.isDigit >> String.toInt >> Maybe.map (not << inval) >> Maybe.withDefault False