diff --git a/README.md b/README.md index b7fbb9e..b52aa5e 100644 --- a/README.md +++ b/README.md @@ -51,12 +51,12 @@ Thus, care must be taken when serializing structures containing function. ## Format -The output of `.serialize(..)` is a strict superset of standard JSON, +The output of `.serialize(..)` is a strict superset of [standard JSON](https://www.json.org/json-en.html), while the input format is a bit more relaxed than in several details. Extensions to JSON: - Recursion -- null types +- undefined / NaN - BigInt - Map / Set - Function diff --git a/package.json b/package.json index edb4a50..406906c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-serialize", - "version": "1.0.4", + "version": "1.0.5", "description": "experimental extended json serializaion...", "main": "serialize.js", "scripts": { diff --git a/serialize.js b/serialize.js index c7ee84d..07fddc3 100644 --- a/serialize.js +++ b/serialize.js @@ -35,6 +35,7 @@ * position? * (XXX move this note to diff.jx) * +* XXX do a revision of the JSON standard for things I could have forgotten... * * **********************************************************************/ @@ -267,7 +268,7 @@ module.eJSON = { 0: 'number', 1: 'number', 2: 'number', 3: 'number', 4: 'number', 5: 'number', 6: 'number', 7: 'number', 8: 'number', 9: 'number', - '.': 'number', '-': 'number', + '.': 'number', '-': 'number', '+': 'number', '[': 'array', '{': 'object', @@ -410,8 +411,11 @@ module.eJSON = { var j = i+1 while(j < str.length && (str[j] == '.' + || str[j] == 'e' || (str[j] >= '0' && str[j] <= '9'))){ + if(str.slice(j, j+2) == 'e+'){ + j++ } j++ } // BigInt... if(str[j] == 'n'){ diff --git a/test.js b/test.js index 9e5a1f0..0cba81f 100755 --- a/test.js +++ b/test.js @@ -45,6 +45,10 @@ var setups = test.Setups({ return ['123', json] }, 'number-neg': function(assert){ return ['-123', json] }, + //'number-pos': function(assert){ + // return ['+123', json] }, + 'number-exp': function(assert){ + return ['1e+100', json] }, 'number-zero': function(assert){ return ['0', json] }, 'float-a': function(assert){ @@ -196,6 +200,8 @@ test.Cases({ // numbers/floats... ['.123', '0.123'], ['123.', '123'], + ['+123', '123'], + ['123e100', '123e+100'], // string quotes... ["'abc'", '"abc"'],