Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/justinwoo/purescript-tortellini
An easy ini library for PureScript
https://github.com/justinwoo/purescript-tortellini
ini purescript
Last synced: about 2 months ago
JSON representation
An easy ini library for PureScript
- Host: GitHub
- URL: https://github.com/justinwoo/purescript-tortellini
- Owner: justinwoo
- License: mit
- Created: 2017-12-24T14:41:45.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-04-25T02:41:02.000Z (over 5 years ago)
- Last Synced: 2024-10-11T11:39:48.853Z (2 months ago)
- Topics: ini, purescript
- Language: PureScript
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PureScript-Tortellini
[![Build Status](https://travis-ci.org/justinwoo/purescript-tortellini.svg?branch=master)](https://travis-ci.org/justinwoo/purescript-tortellini)
A library for writing and reading from ini files.
*Disclaimer:* this library does not aim to provide flexible ini support. Only what's easy.
## Assumptions
The main way I work with ini files is to declare that the top level must be a record, with each section header being a label and the section body being a record type at that field.
Each section is then a record of the values, where `key=value` with no spaces, with the following representations:
* Boolean: true or false, unquoted
* Int: 1 as the number not wrapped in anything
* String: string, unquoted
* Array: members represented as their types, with a comma delimiter## Tl;dr
```hs
testDoc :: String
testDoc = """
[section1]
fruit=apple
isRed=true
seeds=4
children=banana,grape,pineapple
[section2]
bat=grey
[WOWSECTION]
[麻婆豆腐]
"""type TestIni =
{ section1 ::
{ fruit :: String
, isRed :: Boolean
, seeds :: Int
, children :: Array String
}
, section2 ::
{ bat :: String
}
, "WOWSECTION" ::
{}
, "麻婆豆腐" ::
{}
}
-- ...
suite "parsellIni" do
test "works" do
case parsellIni testDoc of
Left e -> failure $ show e
Right (result :: TestIni) -> do
equal result.section1.fruit "apple"
equal result.section1.isRed true
equal result.section1.seeds 4
equal result.section1.children ["banana","grape","pineapple"]
equal result.section2.bat "grey"
```## Extra notes
Things someone might add if they really want it:
* Nullary Sum to String generic to work with enumerable values
* Do you really need this though?...
* Escaping characters
* Multiline escaping
* Whatever other "nice to have" featuresThings that I won't support unless someone has a good idea:
* Records nested in sections. Who wants this anyway?
* Nested arrays. What even?