Skip to content

Update dependencies, fix JS warnings #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/.*
!/.gitignore
!/.jscsrc
!/.jshintrc
!/.travis.yml
/bower_components/
/node_modules/
Expand Down
17 changes: 17 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"preset": "grunt",
"disallowSpacesInFunctionExpression": null,
"requireSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInAnonymousFunctionExpression": null,
"requireSpacesInAnonymousFunctionExpression": {
"beforeOpeningRoundBrace": true,
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInsideObjectBrackets": null,
"requireSpacesInsideObjectBrackets": "all",
"validateQuoteMarks": "\"",
"requireCurlyBraces": null
}
19 changes: 19 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bitwise": true,
"eqeqeq": true,
"forin": true,
"freeze": true,
"funcscope": true,
"futurehostile": true,
"strict": "global",
"latedef": true,
"noarg": true,
"nocomma": true,
"nonew": true,
"notypeof": true,
"singleGroups": true,
"undef": true,
"unused": true,
"eqnull": true,
"predef": ["exports"]
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# purescript-argonaut-core

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

Core part of `purescript-argonaut` that contains basic types for `Json`, folds over them, tests, printer and parser.
Expand Down
8 changes: 4 additions & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
},
"license": "MIT",
"dependencies": {
"purescript-enums": "^1.0.0",
"purescript-functions": "^1.0.0",
"purescript-maps": "^1.0.0"
"purescript-enums": "^2.0.0",
"purescript-functions": "^2.0.0",
"purescript-maps": "^2.0.0"
},
"devDependencies": {
"purescript-strongcheck": "^1.0.0"
"purescript-strongcheck": "^2.0.0"
}
}
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"private": true,
"scripts": {
"clean": "rimraf output && rimraf .pulp-cache",
"build": "pulp build --censor-lib --strict",
"build": "jshint src && jscs src && pulp build --censor-lib --strict",
"test": "pulp test"
},
"devDependencies": {
"pulp": "^9.0.0",
"jscs": "^3.0.7",
"jshint": "^2.9.3",
"pulp": "^9.0.1",
"purescript-psa": "^0.3.9",
"purescript": "^0.9.1",
"rimraf": "^2.5.0"
"purescript": "^0.10.1",
"rimraf": "^2.5.4"
}
}
181 changes: 84 additions & 97 deletions src/Data/Argonaut/Core.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// module Data.Argonaut.Core
"use strict";

function id(x) {
return x;
return x;
}


exports.fromNull = function() {
return null;
exports.fromNull = function () {
return null;
};

exports.fromBoolean = id;
Expand All @@ -17,104 +16,92 @@ exports.fromObject = id;

exports.jsonNull = null;

exports.stringify = function(j) {
return JSON.stringify(j);
exports.stringify = function (j) {
return JSON.stringify(j);
};

exports._foldJson = function(isNull, isBool, isNum, isStr, isArr, isObj, j) {
if (j == null) return isNull(null);
else if (typeof j === 'boolean') return isBool(j);
else if (typeof j === 'number') return isNum(j);
else if (typeof j === 'string') return isStr(j);
else if (Object.prototype.toString.call(j) === '[object Array]')
return isArr(j);
else return isObj(j);
var objToString = Object.prototype.toString;
var objKeys = Object.keys;

function isArray(a) {
return objToString.call(a) === "[object Array]";
}

exports._foldJson = function (isNull, isBool, isNum, isStr, isArr, isObj, j) {
if (j == null) return isNull(null);
else if (typeof j === "boolean") return isBool(j);
else if (typeof j === "number") return isNum(j);
else if (typeof j === "string") return isStr(j);
else if (objToString.call(j) === "[object Array]")
return isArr(j);
else return isObj(j);
};

function _compare(EQ, GT, LT, a, b) {
function isArray(a) {
return Object.prototype.toString.call(a) === '[object Array]';
}
function keys(o) {
var a = [];
for (var k in o) {
a.push(k);
}
return a;
}

if (a == null) {
if (b == null) return EQ;
else return LT;
} else if (typeof a === 'boolean') {
if (typeof b === 'boolean') {
// boolean / boolean
if (a === b) return EQ;
else if (a == false) return LT;
else return GT;
} else if (b == null) return GT;
else return LT;
} else if (typeof a === 'number') {
if (typeof b === 'number') {
if (a === b) return EQ;
else if (a < b) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === 'boolean') return GT;
else return LT;
} else if (typeof a === 'string') {
if (typeof b === 'string') {
if (a === b) return EQ;
else if (a < b) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === 'boolean') return GT;
else if (typeof b === 'number') return GT;
else return LT;
} else if (isArray(a)) {
if (isArray(b)) {
for (var i = 0; i < Math.min(a.length, b.length); i++) {
var c = _compare(EQ, GT, LT, a[i], b[i]);

if (c !== EQ) return c;
}
if (a.length === b.length) return EQ;
else if (a.length < b.length) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === 'boolean') return GT;
else if (typeof b === 'number') return GT;
else if (typeof b === 'string') return GT;
else return LT;
}
if (a == null) {
if (b == null) return EQ;
else return LT;
} else if (typeof a === "boolean") {
if (typeof b === "boolean") {
// boolean / boolean
if (a === b) return EQ;
else if (a === false) return LT;
else return GT;
} else if (b == null) return GT;
else return LT;
} else if (typeof a === "number") {
if (typeof b === "number") {
if (a === b) return EQ;
else if (a < b) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === "boolean") return GT;
else return LT;
} else if (typeof a === "string") {
if (typeof b === "string") {
if (a === b) return EQ;
else if (a < b) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === "boolean") return GT;
else if (typeof b === "number") return GT;
else return LT;
} else if (isArray(a)) {
if (isArray(b)) {
for (var i = 0; i < Math.min(a.length, b.length); i++) {
var ca = _compare(EQ, GT, LT, a[i], b[i]);
if (ca !== EQ) return ca;
}
if (a.length === b.length) return EQ;
else if (a.length < b.length) return LT;
else return GT;
} else if (b == null) return GT;
else if (typeof b === "boolean") return GT;
else if (typeof b === "number") return GT;
else if (typeof b === "string") return GT;
else return LT;
} else {
if (b == null) return GT;
else if (typeof b === "boolean") return GT;
else if (typeof b === "number") return GT;
else if (typeof b === "string") return GT;
else if (isArray(b)) return GT;
else {
if (b == null) return GT;
else if (typeof b === 'boolean') return GT;
else if (typeof b === 'number') return GT;
else if (typeof b === 'string') return GT;
else if (isArray(b)) return GT;
else {
var akeys = keys(a);
var bkeys = keys(b);

var keys = akeys.concat(bkeys).sort();

for (var i = 0; i < keys.length; i++) {
var k = keys[i];

if (a[k] === undefined) return LT;
else if (b[k] === undefined) return GT;

var c = _compare(EQ, GT, LT, a[k], b[k]);

if (c !== EQ) return c;
}

if (akeys.length === bkeys.length) return EQ;
else if (akeys.length < bkeys.length) return LT;
else return GT;
}
var akeys = objKeys(a);
var bkeys = objKeys(b);
if (akeys.length < bkeys.length) return LT;
else if (akeys.length > bkeys.length) return GT;
var keys = akeys.concat(bkeys).sort();
for (var j = 0; j < keys.length; j++) {
var k = keys[j];
if (a[k] === undefined) return LT;
else if (b[k] === undefined) return GT;
var ck = _compare(EQ, GT, LT, a[k], b[k]);
if (ck !== EQ) return ck;
}
return EQ;
}
};
}
}

exports._compare = _compare;
41 changes: 29 additions & 12 deletions src/Data/Argonaut/Core.purs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ foreign import data JNull :: *
foreign import data Json :: *

-- | Case analysis for `Json` values. See the README for more information.
foldJson :: forall a.
(JNull -> a) -> (JBoolean -> a) -> (JNumber -> a) ->
(JString -> a) -> (JArray -> a) -> (JObject -> a) ->
Json -> a
foldJson
:: forall a
. (JNull -> a)
-> (JBoolean -> a)
-> (JNumber -> a)
-> (JString -> a)
-> (JArray -> a)
-> (JObject -> a)
-> Json -> a
foldJson a b c d e f json = runFn7 _foldJson a b c d e f json

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

-- Decoding

toJsonType :: forall a. (Maybe a -> (a -> Maybe a) -> Json -> Maybe a) ->
Json -> Maybe a
toJsonType
:: forall a
. (Maybe a -> (a -> Maybe a) -> Json -> Maybe a)
-> Json
-> Maybe a
toJsonType = verbJsonType Nothing Just

toNull :: Json -> Maybe JNull
Expand Down Expand Up @@ -190,6 +198,7 @@ foreign import jsonNull :: Json

jsonTrue :: Json
jsonTrue = fromBoolean true

jsonFalse :: Json
jsonFalse = fromBoolean false

Expand Down Expand Up @@ -223,18 +232,26 @@ instance showJNull :: Show JNull where
show _ = "null"

instance eqJson :: Eq Json where
eq j1 j2 = (compare j1 j2) == EQ
eq j1 j2 = compare j1 j2 == EQ

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

instance showJson :: Show Json where
show = stringify

-- Foreigns

foreign import stringify :: Json -> String
foreign import _foldJson :: forall z. Fn7 (JNull -> z) (JBoolean -> z)
(JNumber -> z) (JString -> z) (JArray -> z)
(JObject -> z) Json z

foreign import _foldJson
:: forall z
. Fn7
(JNull -> z)
(JBoolean -> z)
(JNumber -> z)
(JString -> z)
(JArray -> z)
(JObject -> z)
Json
z

foreign import _compare :: Fn5 Ordering Ordering Ordering Json Json Ordering
16 changes: 8 additions & 8 deletions src/Data/Argonaut/Parser.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// module Data.Argonaut.Parser
"use strict";

exports._jsonParser = function(fail, succ, s) {
try {
return succ(JSON.parse(s));
}
catch(e) {
return fail(e.message);
}
exports._jsonParser = function (fail, succ, s) {
try {
return succ(JSON.parse(s));
}
catch (e) {
return fail(e.message);
}
};
Loading