-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updates for 0.11 * Rename things, add docs * Add NullOrUndefined, refactor module and function names * Update README * Remove old docs
- Loading branch information
Showing
20 changed files
with
554 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Phil Freeman | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
purescript-foreign-generic uses code taken from the purescript-foreign library, | ||
which is used under the terms of the MIT license, below: | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 PureScript | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
## Module Data.Foreign.Class | ||
|
||
#### `Decode` | ||
|
||
``` purescript | ||
class Decode a where | ||
decode :: Foreign -> F a | ||
``` | ||
|
||
The `Decode` class is used to generate decoding functions | ||
of the form `Foreign -> F a` using `generics-rep` deriving. | ||
|
||
First, derive `Generic` for your data: | ||
|
||
```purescript | ||
import Data.Generic.Rep | ||
data MyType = MyType ... | ||
derive instance genericMyType :: Generic MyType _ | ||
``` | ||
|
||
You can then use the `genericDecode` and `genericDecodeJSON` functions | ||
to decode your foreign/JSON-encoded data. | ||
|
||
##### Instances | ||
``` purescript | ||
Decode Foreign | ||
Decode String | ||
Decode Char | ||
Decode Boolean | ||
Decode Number | ||
Decode Int | ||
(Decode a) => Decode (Array a) | ||
``` | ||
|
||
#### `Encode` | ||
|
||
``` purescript | ||
class Encode a where | ||
encode :: a -> Foreign | ||
``` | ||
|
||
The `Encode` class is used to generate encoding functions | ||
of the form `a -> Foreign` using `generics-rep` deriving. | ||
|
||
First, derive `Generic` for your data: | ||
|
||
```purescript | ||
import Data.Generic.Rep | ||
data MyType = MyType ... | ||
derive instance genericMyType :: Generic MyType _ | ||
``` | ||
|
||
You can then use the `genericEncode` and `genericEncodeJSON` functions | ||
to encode your data as JSON. | ||
|
||
##### Instances | ||
``` purescript | ||
Encode Foreign | ||
Encode String | ||
Encode Char | ||
Encode Boolean | ||
Encode Number | ||
Encode Int | ||
(Encode a) => Encode (Array a) | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Module Data.Foreign.Generic | ||
|
||
#### `defaultOptions` | ||
|
||
``` purescript | ||
defaultOptions :: Options | ||
``` | ||
|
||
Default decoding/encoding options: | ||
|
||
- Represent sum types as records with `tag` and `contents` fields | ||
- Unwrap single arguments | ||
- Don't unwrap single constructors | ||
|
||
#### `genericDecode` | ||
|
||
``` purescript | ||
genericDecode :: forall a rep. Generic a rep => GenericDecode rep => Options -> Foreign -> F a | ||
``` | ||
|
||
Read a value which has a `Generic` type. | ||
|
||
#### `genericEncode` | ||
|
||
``` purescript | ||
genericEncode :: forall a rep. Generic a rep => GenericEncode rep => Options -> a -> Foreign | ||
``` | ||
|
||
Generate a `Foreign` value compatible with the `readGeneric` function. | ||
|
||
#### `decodeJSON` | ||
|
||
``` purescript | ||
decodeJSON :: forall a. Decode a => String -> F a | ||
``` | ||
|
||
Decode a JSON string using a `Decode` instance. | ||
|
||
#### `encodeJSON` | ||
|
||
``` purescript | ||
encodeJSON :: forall a. Encode a => a -> String | ||
``` | ||
|
||
Decode a JSON string using a `Decode` instance. | ||
|
||
#### `genericDecodeJSON` | ||
|
||
``` purescript | ||
genericDecodeJSON :: forall a rep. Generic a rep => GenericDecode rep => Options -> String -> F a | ||
``` | ||
|
||
Read a value which has a `Generic` type from a JSON String | ||
|
||
#### `genericEncodeJSON` | ||
|
||
``` purescript | ||
genericEncodeJSON :: forall a rep. Generic a rep => GenericEncode rep => Options -> a -> String | ||
``` | ||
|
||
Write a value which has a `Generic` type as a JSON String | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.