Skip to content

Commit 576563b

Browse files
authored
Merge pull request #13 from purescript-contrib/bump
Update dependencies, fix JS warnings
2 parents ab2016d + b014950 commit 576563b

File tree

10 files changed

+172
-131
lines changed

10 files changed

+172
-131
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/.*
22
!/.gitignore
3+
!/.jscsrc
4+
!/.jshintrc
35
!/.travis.yml
46
/bower_components/
57
/node_modules/

.jscsrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"preset": "grunt",
3+
"disallowSpacesInFunctionExpression": null,
4+
"requireSpacesInFunctionExpression": {
5+
"beforeOpeningRoundBrace": true,
6+
"beforeOpeningCurlyBrace": true
7+
},
8+
"disallowSpacesInAnonymousFunctionExpression": null,
9+
"requireSpacesInAnonymousFunctionExpression": {
10+
"beforeOpeningRoundBrace": true,
11+
"beforeOpeningCurlyBrace": true
12+
},
13+
"disallowSpacesInsideObjectBrackets": null,
14+
"requireSpacesInsideObjectBrackets": "all",
15+
"validateQuoteMarks": "\"",
16+
"requireCurlyBraces": null
17+
}

.jshintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"bitwise": true,
3+
"eqeqeq": true,
4+
"forin": true,
5+
"freeze": true,
6+
"funcscope": true,
7+
"futurehostile": true,
8+
"strict": "global",
9+
"latedef": true,
10+
"noarg": true,
11+
"nocomma": true,
12+
"nonew": true,
13+
"notypeof": true,
14+
"singleGroups": true,
15+
"undef": true,
16+
"unused": true,
17+
"eqnull": true,
18+
"predef": ["exports"]
19+
}

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# purescript-argonaut-core
22

3-
[![Latest release](http://img.shields.io/bower/v/purescript-argonaut-core.svg)](https://github.com/purescript-contrib/purescript-argonaut-core/releases)
3+
[![Latest release](http://img.shields.io/github/release/purescript-contrib/purescript-argonaut-core.svg)](https://github.com/purescript-contrib/purescript-argonaut-core/releases)
44
[![Build Status](https://travis-ci.org/purescript-contrib/purescript-argonaut-core.svg?branch=master)](https://travis-ci.org/purescript-contrib/purescript-argonaut-core)
5-
[![Dependency Status](https://www.versioneye.com/user/projects/563a993c1d47d40019000870/badge.svg?style=flat)](https://www.versioneye.com/user/projects/563a993c1d47d40019000870)
65
[![Maintainer: slamdata](https://img.shields.io/badge/maintainer-slamdata-lightgrey.svg)](http://github.com/slamdata)
76

87
Core part of `purescript-argonaut` that contains basic types for `Json`, folds over them, tests, printer and parser.

bower.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
},
1919
"license": "MIT",
2020
"dependencies": {
21-
"purescript-enums": "^1.0.0",
22-
"purescript-functions": "^1.0.0",
23-
"purescript-maps": "^1.0.0"
21+
"purescript-enums": "^2.0.0",
22+
"purescript-functions": "^2.0.0",
23+
"purescript-maps": "^2.0.0"
2424
},
2525
"devDependencies": {
26-
"purescript-strongcheck": "^1.0.0"
26+
"purescript-strongcheck": "^2.0.0"
2727
}
2828
}

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build --censor-lib --strict",
5+
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^9.0.0",
9+
"jscs": "^3.0.7",
10+
"jshint": "^2.9.3",
11+
"pulp": "^9.0.1",
1012
"purescript-psa": "^0.3.9",
11-
"purescript": "^0.9.1",
12-
"rimraf": "^2.5.0"
13+
"purescript": "^0.10.1",
14+
"rimraf": "^2.5.4"
1315
}
1416
}

src/Data/Argonaut/Core.js

Lines changed: 84 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// module Data.Argonaut.Core
1+
"use strict";
22

33
function id(x) {
4-
return x;
4+
return x;
55
}
6-
76

8-
exports.fromNull = function() {
9-
return null;
7+
exports.fromNull = function () {
8+
return null;
109
};
1110

1211
exports.fromBoolean = id;
@@ -17,104 +16,92 @@ exports.fromObject = id;
1716

1817
exports.jsonNull = null;
1918

20-
exports.stringify = function(j) {
21-
return JSON.stringify(j);
19+
exports.stringify = function (j) {
20+
return JSON.stringify(j);
2221
};
2322

24-
exports._foldJson = function(isNull, isBool, isNum, isStr, isArr, isObj, j) {
25-
if (j == null) return isNull(null);
26-
else if (typeof j === 'boolean') return isBool(j);
27-
else if (typeof j === 'number') return isNum(j);
28-
else if (typeof j === 'string') return isStr(j);
29-
else if (Object.prototype.toString.call(j) === '[object Array]')
30-
return isArr(j);
31-
else return isObj(j);
23+
var objToString = Object.prototype.toString;
24+
var objKeys = Object.keys;
25+
26+
function isArray(a) {
27+
return objToString.call(a) === "[object Array]";
28+
}
29+
30+
exports._foldJson = function (isNull, isBool, isNum, isStr, isArr, isObj, j) {
31+
if (j == null) return isNull(null);
32+
else if (typeof j === "boolean") return isBool(j);
33+
else if (typeof j === "number") return isNum(j);
34+
else if (typeof j === "string") return isStr(j);
35+
else if (objToString.call(j) === "[object Array]")
36+
return isArr(j);
37+
else return isObj(j);
3238
};
3339

3440
function _compare(EQ, GT, LT, a, b) {
35-
function isArray(a) {
36-
return Object.prototype.toString.call(a) === '[object Array]';
37-
}
38-
function keys(o) {
39-
var a = [];
40-
for (var k in o) {
41-
a.push(k);
42-
}
43-
return a;
44-
}
45-
46-
if (a == null) {
47-
if (b == null) return EQ;
48-
else return LT;
49-
} else if (typeof a === 'boolean') {
50-
if (typeof b === 'boolean') {
51-
// boolean / boolean
52-
if (a === b) return EQ;
53-
else if (a == false) return LT;
54-
else return GT;
55-
} else if (b == null) return GT;
56-
else return LT;
57-
} else if (typeof a === 'number') {
58-
if (typeof b === 'number') {
59-
if (a === b) return EQ;
60-
else if (a < b) return LT;
61-
else return GT;
62-
} else if (b == null) return GT;
63-
else if (typeof b === 'boolean') return GT;
64-
else return LT;
65-
} else if (typeof a === 'string') {
66-
if (typeof b === 'string') {
67-
if (a === b) return EQ;
68-
else if (a < b) return LT;
69-
else return GT;
70-
} else if (b == null) return GT;
71-
else if (typeof b === 'boolean') return GT;
72-
else if (typeof b === 'number') return GT;
73-
else return LT;
74-
} else if (isArray(a)) {
75-
if (isArray(b)) {
76-
for (var i = 0; i < Math.min(a.length, b.length); i++) {
77-
var c = _compare(EQ, GT, LT, a[i], b[i]);
78-
79-
if (c !== EQ) return c;
80-
}
81-
if (a.length === b.length) return EQ;
82-
else if (a.length < b.length) return LT;
83-
else return GT;
84-
} else if (b == null) return GT;
85-
else if (typeof b === 'boolean') return GT;
86-
else if (typeof b === 'number') return GT;
87-
else if (typeof b === 'string') return GT;
88-
else return LT;
89-
}
41+
if (a == null) {
42+
if (b == null) return EQ;
43+
else return LT;
44+
} else if (typeof a === "boolean") {
45+
if (typeof b === "boolean") {
46+
// boolean / boolean
47+
if (a === b) return EQ;
48+
else if (a === false) return LT;
49+
else return GT;
50+
} else if (b == null) return GT;
51+
else return LT;
52+
} else if (typeof a === "number") {
53+
if (typeof b === "number") {
54+
if (a === b) return EQ;
55+
else if (a < b) return LT;
56+
else return GT;
57+
} else if (b == null) return GT;
58+
else if (typeof b === "boolean") return GT;
59+
else return LT;
60+
} else if (typeof a === "string") {
61+
if (typeof b === "string") {
62+
if (a === b) return EQ;
63+
else if (a < b) return LT;
64+
else return GT;
65+
} else if (b == null) return GT;
66+
else if (typeof b === "boolean") return GT;
67+
else if (typeof b === "number") return GT;
68+
else return LT;
69+
} else if (isArray(a)) {
70+
if (isArray(b)) {
71+
for (var i = 0; i < Math.min(a.length, b.length); i++) {
72+
var ca = _compare(EQ, GT, LT, a[i], b[i]);
73+
if (ca !== EQ) return ca;
74+
}
75+
if (a.length === b.length) return EQ;
76+
else if (a.length < b.length) return LT;
77+
else return GT;
78+
} else if (b == null) return GT;
79+
else if (typeof b === "boolean") return GT;
80+
else if (typeof b === "number") return GT;
81+
else if (typeof b === "string") return GT;
82+
else return LT;
83+
} else {
84+
if (b == null) return GT;
85+
else if (typeof b === "boolean") return GT;
86+
else if (typeof b === "number") return GT;
87+
else if (typeof b === "string") return GT;
88+
else if (isArray(b)) return GT;
9089
else {
91-
if (b == null) return GT;
92-
else if (typeof b === 'boolean') return GT;
93-
else if (typeof b === 'number') return GT;
94-
else if (typeof b === 'string') return GT;
95-
else if (isArray(b)) return GT;
96-
else {
97-
var akeys = keys(a);
98-
var bkeys = keys(b);
99-
100-
var keys = akeys.concat(bkeys).sort();
101-
102-
for (var i = 0; i < keys.length; i++) {
103-
var k = keys[i];
104-
105-
if (a[k] === undefined) return LT;
106-
else if (b[k] === undefined) return GT;
107-
108-
var c = _compare(EQ, GT, LT, a[k], b[k]);
109-
110-
if (c !== EQ) return c;
111-
}
112-
113-
if (akeys.length === bkeys.length) return EQ;
114-
else if (akeys.length < bkeys.length) return LT;
115-
else return GT;
116-
}
90+
var akeys = objKeys(a);
91+
var bkeys = objKeys(b);
92+
if (akeys.length < bkeys.length) return LT;
93+
else if (akeys.length > bkeys.length) return GT;
94+
var keys = akeys.concat(bkeys).sort();
95+
for (var j = 0; j < keys.length; j++) {
96+
var k = keys[j];
97+
if (a[k] === undefined) return LT;
98+
else if (b[k] === undefined) return GT;
99+
var ck = _compare(EQ, GT, LT, a[k], b[k]);
100+
if (ck !== EQ) return ck;
101+
}
102+
return EQ;
117103
}
118-
};
104+
}
105+
}
119106

120107
exports._compare = _compare;

src/Data/Argonaut/Core.purs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,15 @@ foreign import data JNull :: *
8888
foreign import data Json :: *
8989

9090
-- | Case analysis for `Json` values. See the README for more information.
91-
foldJson :: forall a.
92-
(JNull -> a) -> (JBoolean -> a) -> (JNumber -> a) ->
93-
(JString -> a) -> (JArray -> a) -> (JObject -> a) ->
94-
Json -> a
91+
foldJson
92+
:: forall a
93+
. (JNull -> a)
94+
-> (JBoolean -> a)
95+
-> (JNumber -> a)
96+
-> (JString -> a)
97+
-> (JArray -> a)
98+
-> (JObject -> a)
99+
-> Json -> a
95100
foldJson a b c d e f json = runFn7 _foldJson a b c d e f json
96101

97102
-- | A simpler version of `foldJson` which accepts a callback for when the
@@ -153,8 +158,11 @@ isObject = isJsonType foldJsonObject
153158

154159
-- Decoding
155160

156-
toJsonType :: forall a. (Maybe a -> (a -> Maybe a) -> Json -> Maybe a) ->
157-
Json -> Maybe a
161+
toJsonType
162+
:: forall a
163+
. (Maybe a -> (a -> Maybe a) -> Json -> Maybe a)
164+
-> Json
165+
-> Maybe a
158166
toJsonType = verbJsonType Nothing Just
159167

160168
toNull :: Json -> Maybe JNull
@@ -190,6 +198,7 @@ foreign import jsonNull :: Json
190198

191199
jsonTrue :: Json
192200
jsonTrue = fromBoolean true
201+
193202
jsonFalse :: Json
194203
jsonFalse = fromBoolean false
195204

@@ -223,18 +232,26 @@ instance showJNull :: Show JNull where
223232
show _ = "null"
224233

225234
instance eqJson :: Eq Json where
226-
eq j1 j2 = (compare j1 j2) == EQ
235+
eq j1 j2 = compare j1 j2 == EQ
227236

228237
instance ordJson :: Ord Json where
229238
compare a b = runFn5 _compare EQ GT LT a b
230239

231240
instance showJson :: Show Json where
232241
show = stringify
233242

234-
-- Foreigns
235-
236243
foreign import stringify :: Json -> String
237-
foreign import _foldJson :: forall z. Fn7 (JNull -> z) (JBoolean -> z)
238-
(JNumber -> z) (JString -> z) (JArray -> z)
239-
(JObject -> z) Json z
244+
245+
foreign import _foldJson
246+
:: forall z
247+
. Fn7
248+
(JNull -> z)
249+
(JBoolean -> z)
250+
(JNumber -> z)
251+
(JString -> z)
252+
(JArray -> z)
253+
(JObject -> z)
254+
Json
255+
z
256+
240257
foreign import _compare :: Fn5 Ordering Ordering Ordering Json Json Ordering

src/Data/Argonaut/Parser.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// module Data.Argonaut.Parser
1+
"use strict";
22

3-
exports._jsonParser = function(fail, succ, s) {
4-
try {
5-
return succ(JSON.parse(s));
6-
}
7-
catch(e) {
8-
return fail(e.message);
9-
}
3+
exports._jsonParser = function (fail, succ, s) {
4+
try {
5+
return succ(JSON.parse(s));
6+
}
7+
catch (e) {
8+
return fail(e.message);
9+
}
1010
};

0 commit comments

Comments
 (0)