From 86fefe0e1773aee43ad04727a2edbe6cb6dcf0f6 Mon Sep 17 00:00:00 2001 From: shayan javani Date: Mon, 3 Oct 2022 20:45:43 +0330 Subject: added from_base_string to int module --- src/gleam_stdlib.mjs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/gleam_stdlib.mjs') diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs index cde1052..2fafcd9 100644 --- a/src/gleam_stdlib.mjs +++ b/src/gleam_stdlib.mjs @@ -57,6 +57,15 @@ export function int_to_base_string(int, base) { return int.toString(base).toUpperCase(); } +export function int_from_base_string(string, base) { + const result = parseInt(string, base) + if (isNaN(result)) { + return new Error(Nil) + } else { + return new Ok(result) + } +} + export function string_replace(string, target, substitute) { if (typeof string.replaceAll !== "undefined") { return string.replaceAll(target, substitute); -- cgit v1.2.3