Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Oct 10, 2024
1 parent 78f7ada commit 9ccba1e
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
```

0 comments on commit 9ccba1e

Please sign in to comment.