From 9ccba1efb397debbc0f0690e36afd2d2fedf5c15 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 10 Oct 2024 17:50:48 -0400 Subject: [PATCH] Update README.md --- README.md | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index de5df93..92b06d4 100644 --- a/README.md +++ b/README.md @@ -3,19 +3,44 @@ [![Package Version](https://img.shields.io/hexpm/v/lenient_parse)](https://hex.pm/packages/lenient_parse) [![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/lenient_parse/) +A Gleam library providing lenient parsing functions for converting strings to float and integer values. This package offers more flexible parsing than the standard Gleam functions, similar to Python's built-in `float()` and `int()` functions. + +## Installation + + ```sh gleam add lenient_parse ``` ```gleam import lenient_parse -import gleam/float import gleam/io pub fn main() { - "1" |> float.parse |> io.debug - // Error(Nil) - "1" |> lenient_parse.to_float |> io.debug // Ok(1.0) + + "1.001" |> lenient_parse.to_float |> io.debug + // Ok(1.001) + + "+123.321" |> lenient_parse.to_float |> io.debug + // Ok(123.321) + + "-123.321" |> lenient_parse.to_float |> io.debug + // Ok(-123.321) + + "1_000_000.0" |> lenient_parse.to_float |> io.debug + // Ok(1000000.0) + + "123" |> lenient_parse.to_int |> io.debug + // Ok(123) + + "+123" |> lenient_parse.to_int |> io.debug + // Ok(123) + + "-123" |> lenient_parse.to_int |> io.debug + // Ok(-123) + + "1_000_000" |> lenient_parse.to_int |> io.debug + // Ok(1000000) } ```