Skip to content

Commit

Permalink
feat: initial implementation
Browse files Browse the repository at this point in the history
Credits goes to OpenAI o1-preview + Cursor with Claude 3.5 Sonet

`o1-preview` generated bunch of syntax that doesn't exist.
I had to only use cursor.dev pretrained on Gleam to fix syntax errors and provide docs for stdlib on further iterations.

You can find creation session at https://chatgpt.com/share/66f5db20-c7fc-8004-b7d6-db55d720f6c8
  • Loading branch information
Guria committed Sep 26, 2024
0 parents commit 35b0ab9
Show file tree
Hide file tree
Showing 7 changed files with 1,074 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: test

on:
push:
branches:
- master
- main
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
otp-version: "27.0.1"
gleam-version: "1.5.1"
rebar3-version: "3"
# elixir-version: "1.15.4"
- run: gleam deps download
- run: gleam test
- run: gleam format --check src test
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.beam
*.ez
/build
erl_crash.dump
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# gleojson

[![Package Version](https://img.shields.io/hexpm/v/gleojson)](https://hex.pm/packages/gleojson)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/gleojson/)

**gleojson** is a GeoJSON parsing and encoding library for Gleam, following the [RFC 7946](https://tools.ietf.org/html/rfc7946) specification. It provides types and utility functions to encode and decode GeoJSON objects such as Points, LineStrings, Polygons, and more.

## Installation

Add **gleojson** to your Gleam project:

```sh
gleam add gleojson
```

## Usage

```gleam
pub fn main() {
let json_string = "{
\"type\": \"Feature\",
\"geometry\": {
\"type\": \"Point\",
\"coordinates\": [125.6, 10.1]
},
\"properties\": {
\"name\": \"Dinagat Islands\"
}
}"
// Decode the JSON string into a GeoJSON object
let result = json.decode(from: json_string, using: gleojson.geojson_decoder)
case result {
Ok(geojson) -> {
// Successfully decoded GeoJSON
let encoded = gleojson.encode_geojson(geojson)
// encoded is now a Dynamic representation of the GeoJSON object
// You can use it for further processing or encoding back to JSON
}
Error(errors) -> {
todo
// Handle decoding errors
// errors contains information about what went wrong during decoding
}
}
}
```

Further documentation can be found at https://hexdocs.pm/gleojson.

## Development

```
gleam build
gleam test
```
14 changes: 14 additions & 0 deletions gleam.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = "gleojson"
version = "0.1.0"

description = "A Gleam library for encoding and decoding GeoJSON"
licences = ["MIT"]
repository = { type = "github", user = "guria", repo = "gleojson" }
links = [{ title = "RFC7946", href = "https://datatracker.ietf.org/doc/html/rfc7946" }]

[dependencies]
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
gleam_json = ">= 2.0.0 and < 3.0.0"

[dev-dependencies]
gleeunit = ">= 1.0.0 and < 2.0.0"
13 changes: 13 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file was generated by Gleam
# You typically do not need to edit this file

packages = [
{ name = "gleam_json", version = "2.0.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleam_json", source = "hex", outer_checksum = "CB10B0E7BF44282FB25162F1A24C1A025F6B93E777CCF238C4017E4EEF2CDE97" },
{ name = "gleam_stdlib", version = "0.40.0", build_tools = ["gleam"], requirements = [], otp_app = "gleam_stdlib", source = "hex", outer_checksum = "86606B75A600BBD05E539EB59FABC6E307EEEA7B1E5865AFB6D980A93BCB2181" },
{ name = "gleeunit", version = "1.2.0", build_tools = ["gleam"], requirements = ["gleam_stdlib"], otp_app = "gleeunit", source = "hex", outer_checksum = "F7A7228925D3EE7D0813C922E062BFD6D7E9310F0BEE585D3A42F3307E3CFD13" },
]

[requirements]
gleam_json = { version = ">= 2.0.0 and < 3.0.0" }
gleam_stdlib = { version = ">= 0.34.0 and < 2.0.0" }
gleeunit = { version = ">= 1.0.0 and < 2.0.0" }
Loading

0 comments on commit 35b0ab9

Please sign in to comment.