Skip to content

Commit a9999bc

Browse files
Merge pull request #38 from purescript-contrib/docs
Add documentation comments
2 parents aa83414 + 1331f81 commit a9999bc

File tree

4 files changed

+44
-5
lines changed

4 files changed

+44
-5
lines changed

.travis.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ node_js: stable
55
env:
66
- PATH=$HOME/purescript:$PATH
77
install:
8-
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
8+
- TAG=$(basename $(curl -Ls -o /dev/null -w %{url_effective} https://github.com/purescript/purescript/releases/latest))
99
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
1010
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1111
- chmod a+x $HOME/purescript
@@ -17,7 +17,7 @@ script:
1717
- bower install
1818
- npm run -s test
1919
after_success:
20-
- >-
21-
test $TRAVIS_TAG &&
22-
echo $GITHUB_TOKEN | pulp login &&
23-
echo y | pulp publish --no-push
20+
- >-
21+
test $TRAVIS_TAG &&
22+
echo $GITHUB_TOKEN | pulp login &&
23+
echo y | pulp publish --no-push

src/Data/Argonaut/Core.purs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,24 +114,31 @@ verbJsonType :: forall a b. b -> (a -> b) -> (b -> (a -> b) -> Json -> b) -> Jso
114114
verbJsonType def f g = g def f
115115

116116
-- Tests
117+
117118
isJsonType :: forall a. (Boolean -> (a -> Boolean) -> Json -> Boolean) -> Json -> Boolean
118119
isJsonType = verbJsonType false (const true)
119120

121+
-- | Check if the provided `Json` is the `null` value
120122
isNull :: Json -> Boolean
121123
isNull = isJsonType caseJsonNull
122124

125+
-- | Check if the provided `Json` is a `Boolean`
123126
isBoolean :: Json -> Boolean
124127
isBoolean = isJsonType caseJsonBoolean
125128

129+
-- | Check if the provided `Json` is a `Number`
126130
isNumber :: Json -> Boolean
127131
isNumber = isJsonType caseJsonNumber
128132

133+
-- | Check if the provided `Json` is a `String`
129134
isString :: Json -> Boolean
130135
isString = isJsonType caseJsonString
131136

137+
-- | Check if the provided `Json` is an `Array`
132138
isArray :: Json -> Boolean
133139
isArray = isJsonType caseJsonArray
134140

141+
-- | Check if the provided `Json` is an `Object`
135142
isObject :: Json -> Boolean
136143
isObject = isJsonType caseJsonObject
137144

@@ -144,60 +151,88 @@ toJsonType
144151
-> Maybe a
145152
toJsonType = verbJsonType Nothing Just
146153

154+
-- | Convert `Json` to the `Unit` value if the `Json` is the null value
147155
toNull :: Json -> Maybe Unit
148156
toNull = toJsonType caseJsonNull
149157

158+
-- | Convert `Json` to a `Boolean` value, if the `Json` is a boolean.
150159
toBoolean :: Json -> Maybe Boolean
151160
toBoolean = toJsonType caseJsonBoolean
152161

162+
-- | Convert `Json` to a `Number` value, if the `Json` is a number.
153163
toNumber :: Json -> Maybe Number
154164
toNumber = toJsonType caseJsonNumber
155165

166+
-- | Convert `Json` to a `String` value, if the `Json` is a string. To write a
167+
-- | `Json` value to a JSON string, see `stringify`.
156168
toString :: Json -> Maybe String
157169
toString = toJsonType caseJsonString
158170

171+
-- | Convert `Json` to an `Array` of `Json` values, if the `Json` is an array.
159172
toArray :: Json -> Maybe (Array Json)
160173
toArray = toJsonType caseJsonArray
161174

175+
-- | Convert `Json` to an `Object` of `Json` values, if the `Json` is an object.
162176
toObject :: Json -> Maybe (Object Json)
163177
toObject = toJsonType caseJsonObject
164178

165179
-- Encoding
166180

181+
-- | Construct `Json` from a `Boolean` value
167182
foreign import fromBoolean :: Boolean -> Json
183+
184+
-- | Construct `Json` from a `Number` value
168185
foreign import fromNumber :: Number -> Json
186+
187+
-- | Construct `Json` from a `String` value. If you would like to parse a string
188+
-- | of JSON into valid `Json`, see `jsonParser`.
169189
foreign import fromString :: String -> Json
190+
191+
-- | Construct `Json` from an array of `Json` values
170192
foreign import fromArray :: Array Json -> Json
193+
194+
-- | Construct `Json` from an object with `Json` values
171195
foreign import fromObject :: Object Json -> Json
172196

173197
-- Defaults
174198

199+
-- | The JSON null value represented as `Json`
175200
foreign import jsonNull :: Json
176201

202+
-- | The true boolean value represented as `Json`
177203
jsonTrue :: Json
178204
jsonTrue = fromBoolean true
179205

206+
-- | The false boolean value represented as `Json`
180207
jsonFalse :: Json
181208
jsonFalse = fromBoolean false
182209

210+
-- | The number zero represented as `Json`
183211
jsonZero :: Json
184212
jsonZero = fromNumber 0.0
185213

214+
-- | An empty string represented as `Json`
186215
jsonEmptyString :: Json
187216
jsonEmptyString = fromString ""
188217

218+
-- | An empty array represented as `Json`
189219
jsonEmptyArray :: Json
190220
jsonEmptyArray = fromArray []
191221

222+
-- | An empty object represented as `Json`
192223
jsonEmptyObject :: Json
193224
jsonEmptyObject = fromObject Obj.empty
194225

226+
-- | Constructs a `Json` array value containing only the provided value
195227
jsonSingletonArray :: Json -> Json
196228
jsonSingletonArray j = fromArray [j]
197229

230+
-- | Constructs a `Json` object value containing only the provided key and value
198231
jsonSingletonObject :: String -> Json -> Json
199232
jsonSingletonObject key val = fromObject (Obj.singleton key val)
200233

234+
-- | Converts a `Json` value to a JSON string. To retrieve a string from a `Json`
235+
-- | string value, see `fromString`.
201236
foreign import stringify :: Json -> String
202237

203238
foreign import _caseJson

src/Data/Argonaut/Gen.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import Data.NonEmpty ((:|))
1212
import Data.String.Gen (genUnicodeString)
1313
import Foreign.Object as Obj
1414

15+
-- | A generator for `Json` values. Especially useful for writing property-based
16+
-- | tests.
1517
genJson :: forall m. MonadGen m => MonadRec m => Lazy (m J.Json) => m J.Json
1618
genJson = Gen.resize (min 5) $ Gen.sized genJson'
1719
where

src/Data/Argonaut/Parser.purs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ import Data.Function.Uncurried (Fn3, runFn3)
66

77
foreign import _jsonParser :: forall a. Fn3 (String -> a) (Json -> a) String a
88

9+
-- | Parse a JSON string, constructing the `Json` value described by the string.
10+
-- | To convert a string into a `Json` string, see `fromString`.
911
jsonParser :: String -> Either String Json
1012
jsonParser j = runFn3 _jsonParser Left Right j

0 commit comments

Comments
 (0)