Socket
Socket
Sign inDemoInstall

json5

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json5 - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

50

CHANGELOG.md

@@ -1,7 +0,18 @@

### Unreleased [[code][cNew], [diff][dNew]]
### v0.5.0 [[code][c0.5.0], [diff][d0.5.0]]
[cNew]: https://github.com/aseemk/json5/tree/develop
[dNew]: https://github.com/aseemk/json5/compare/master...develop
[c0.5.0]: https://github.com/aseemk/json5/tree/v0.5.0
[d0.5.0]: https://github.com/aseemk/json5/compare/v0.4.0...v0.5.0
This release includes major internal changes and public API enhancements.
- **Major:** JSON5 officially supports Node.js v4 LTS and v5. Support for
Node.js v0.6 and v0.8 have been dropped, while support for v0.10 and v0.12
remain.
- Fix: YUI Compressor no longer fails when compressing json5.js. ([#97])
- New: `parse` and the CLI provide line and column numbers when displaying error
messages. ([#101]; awesome work by [@amb26].)
### v0.4.0 [[code][c0.4.0], [diff][d0.4.0]]

@@ -21,9 +32,9 @@

See the [usage documentation](./README.md#usage) for more.
([#32][]; huge thanks and props [@aeisenberg][]!)
([#32]; huge thanks and props [@aeisenberg]!)
- New: `NaN` and `-NaN` are now allowed number literals.
([#30][]; thanks [@rowanhill][].)
([#30]; thanks [@rowanhill].)
- New: Duplicate object keys are now allowed; the last value is used.
This is the same behavior as JSON. ([#57][]; thanks [@jordanbtucker][].)
This is the same behavior as JSON. ([#57]; thanks [@jordanbtucker].)

@@ -33,3 +44,3 @@ - Fix: Properly handle various whitespace and newline cases now.

and JSON5 now accepts the same whitespace as JSON (stricter than ES5).
([#58][], [#60][], and [#63][]; thanks [@jordanbtucker][].)
([#58], [#60], and [#63]; thanks [@jordanbtucker].)

@@ -39,3 +50,3 @@ - New: Negative hexadecimal numbers (e.g. `-0xC8`) are allowed again.

It turns out they *are* valid in ES5, so JSON5 supports them now too.
([#36][]; thanks [@jordanbtucker][]!)
([#36]; thanks [@jordanbtucker]!)

@@ -54,3 +65,3 @@

in ES5. This has been [fixed in V8][v8-hex-fix] (and by extension, Chrome
and Node), so JSON5 officially rejects them now, too. ([#36][])
and Node), so JSON5 officially rejects them now, too. ([#36])

@@ -60,6 +71,6 @@ - New: Trailing decimal points in decimal numbers are allowed again.

They're allowed by ES5, and differentiating between integers and floats may
make sense on some platforms. ([#16][]; thanks [@Midar][].)
make sense on some platforms. ([#16]; thanks [@Midar].)
- New: `Infinity` and `-Infinity` are now allowed number literals.
([#30][]; thanks [@pepkin88][].)
([#30]; thanks [@pepkin88].)

@@ -71,3 +82,3 @@ - New: Plus signs (`+`) in front of numbers are now allowed, since it can

- Fix: unescaped newlines in strings are rejected now.
([#24][]; thanks [@Midar][].)
([#24]; thanks [@Midar].)

@@ -82,16 +93,16 @@

- New: Support hexadecimal numbers. (Thanks [@MaxNanasy][].)
- New: Support hexadecimal numbers. (Thanks [@MaxNanasy].)
- Fix: Reject octal numbers properly now. Previously, they were accepted but
improperly parsed as base-10 numbers. (Thanks [@MaxNanasy][].)
improperly parsed as base-10 numbers. (Thanks [@MaxNanasy].)
- **Breaking:** Reject "noctal" numbers now (base-10 numbers that begin with a
leading zero). These are disallowed by both JSON5 and JSON, as well as by
ES5's strict mode. (Thanks [@MaxNanasy][].)
ES5's strict mode. (Thanks [@MaxNanasy].)
- New: Support leading decimal points in decimal numbers.
(Thanks [@MaxNanasy][].)
(Thanks [@MaxNanasy].)
- **Breaking:** Reject trailing decimal points in decimal numbers now. These
are disallowed by both JSON5 and JSON. (Thanks [@MaxNanasy][].)
are disallowed by both JSON5 and JSON. (Thanks [@MaxNanasy].)

@@ -129,3 +140,3 @@ - **Breaking:** Reject omitted elements in arrays now. These are disallowed by

Let's consider this to be Douglas Crockford's original [json_parse.js][] — a
Let's consider this to be Douglas Crockford's original [json_parse.js] — a
parser for the regular JSON format.

@@ -143,2 +154,3 @@

[@jordanbtucker]: https://github.com/jordanbtucker
[@amb26]: https://github.com/amb26

@@ -154,1 +166,3 @@ [#16]: https://github.com/aseemk/json5/issues/16

[#63]: https://github.com/aseemk/json5/pull/63
[#97]: https://github.com/aseemk/json5/pull/97
[#101]: https://github.com/aseemk/json5/pull/101

@@ -20,4 +20,6 @@ // json5.js

var at, // The index of the current character
ch, // The current character
var at, // The index of the current character
lineNumber, // The current line number
columnNumber, // The current column number
ch, // The current character
escapee = {

@@ -47,2 +49,6 @@ "'": "'",

renderChar = function (chr) {
return chr === '' ? 'EOF' : "'" + chr + "'";
},
error = function (m) {

@@ -53,5 +59,9 @@

var error = new SyntaxError();
error.message = m;
// beginning of message suffix to agree with that provided by Gecko - see https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
error.message = m + " at line " + lineNumber + " column " + columnNumber + " of the JSON5 data. Still to read: " + JSON.stringify(text.substring(at - 1, at + 19));
error.at = at;
error.text = text;
// These two property names have been chosen to agree with the ones in Gecko, the only popular
// environment which seems to supply this info on JSON.parse
error.lineNumber = lineNumber;
error.columnNumber = columnNumber;
throw error;

@@ -65,3 +75,3 @@ },

if (c && c !== ch) {
error("Expected '" + c + "' instead of '" + ch + "'");
error("Expected " + renderChar(c) + " instead of " + renderChar(ch));
}

@@ -73,3 +83,8 @@

ch = text.charAt(at);
at += 1;
at++;
columnNumber++;
if (ch === '\n' || ch === '\r' && peek() !== '\n') {
lineNumber++;
columnNumber = 0;
}
return ch;

@@ -102,3 +117,3 @@ },

(ch < 'A' || ch > 'Z')) {
error("Bad identifier");
error("Bad identifier as unquoted key");
}

@@ -201,3 +216,3 @@

}
if (!isFinite(number)) {

@@ -385,3 +400,3 @@ error("Bad number");

}
error("Unexpected '" + ch + "'");
error("Unexpected " + renderChar(ch));
},

@@ -498,2 +513,4 @@

at = 0;
lineNumber = 1;
columnNumber = 1;
ch = ' ';

@@ -559,13 +576,13 @@ result = value();

function isWordChar(char) {
return (char >= 'a' && char <= 'z') ||
(char >= 'A' && char <= 'Z') ||
(char >= '0' && char <= '9') ||
char === '_' || char === '$';
function isWordChar(c) {
return (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9') ||
c === '_' || c === '$';
}
function isWordStart(char) {
return (char >= 'a' && char <= 'z') ||
(char >= 'A' && char <= 'Z') ||
char === '_' || char === '$';
function isWordStart(c) {
return (c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
c === '_' || c === '$';
}

@@ -606,6 +623,2 @@

isNaN = isNaN || function(val) {
return typeof val === 'number' && val !== val;
};
var objStack = [];

@@ -738,3 +751,3 @@ function checkForCircular(obj) {

nonEmpty = true;
var key = isWord(prop) ? prop : escapeString(prop);
key = isWord(prop) ? prop : escapeString(prop);
buffer += key + ":" + (indentStr ? ' ' : '') + value + ",";

@@ -741,0 +754,0 @@ }

{
"name": "json5",
"version": "0.4.0",
"version": "0.5.0",
"description": "JSON for the ES5 era.",

@@ -10,18 +10,26 @@ "keywords": [

"author": "Aseem Kishore <aseem.kishore@gmail.com>",
"license": "MIT",
"contributors": [
"Max Nanasy <max.nanasy@gmail.com>",
"Andrew Eisenberg <andrew@eisenberg.as>"
"Andrew Eisenberg <andrew@eisenberg.as>",
"Jordan Tucker <jordanbtucker@gmail.com>"
],
"main": "lib/json5.js",
"bin": "lib/cli.js",
"files": [
"lib/"
],
"dependencies": {},
"devDependencies": {
"mocha": "~1.0.3"
"gulp": "^3.9.1",
"gulp-jshint": "^2.0.0",
"jshint": "^2.9.1",
"jshint-stylish": "^2.1.0",
"mocha": "^2.4.5"
},
"scripts": {
"build": "./lib/cli.js -c package.json5",
"build": "node ./lib/cli.js -c package.json5",
"test": "mocha --ui exports --reporter spec"
},
"homepage": "http://json5.org/",
"license": "MIT",
"repository": {

@@ -28,0 +36,0 @@ "type": "git",

@@ -0,6 +1,5 @@

# JSON5 – Modern JSON
[![Build Status](https://travis-ci.org/aseemk/json5.png)](https://travis-ci.org/aseemk/json5)
# JSON5 – Modern JSON
JSON is an excellent data format, but we think it can be better.

@@ -20,4 +19,4 @@

The code here is a **reference JavaScript implementation** for both Node.js
and all browsers. It's based directly off of Douglas Crockford's own [JSON
implementation][json_parse.js], and it's both robust and secure.
and all browsers. It’s based directly off of Douglas Crockford’s own [JSON
implementation][json_parse.js], and it’s both robust and secure.

@@ -27,7 +26,7 @@

JSON isn't the friendliest to *write*. Keys need to be quoted, objects and
arrays can't have trailing commas, and comments aren't allowed — even though
JSON isn’t the friendliest to *write*. Keys need to be quoted, objects and
arrays can’t have trailing commas, and comments aren’t allowed — even though
none of these are the case with regular JavaScript today.
That was fine when JSON's goal was to be a great data format, but JSON's usage
That was fine when JSON’s goal was to be a great data format, but JSON’s usage
has expanded beyond *machines*. JSON is now used for writing [configs][ex1],

@@ -37,3 +36,3 @@ [manifests][ex2], even [tests][ex3] — all by *humans*.

[ex1]: http://plovr.com/docs.html
[ex2]: http://npmjs.org/doc/json.html
[ex2]: https://www.npmjs.org/doc/files/package.json.html
[ex3]: http://code.google.com/p/fuzztester/wiki/JSONFileFormat

@@ -48,3 +47,3 @@

The following is the exact list of additions to JSON's syntax introduced by
The following is the exact list of additions to JSON’s syntax introduced by
JSON5. **All of these are optional**, and **all of these come from ES5**.

@@ -54,5 +53,6 @@

- Object keys can be unquoted if they're valid [identifiers][mdn_variables].
- Object keys can be unquoted if they’re valid [identifiers][mdn_variables].
Yes, even reserved keywords (like `default`) are valid unquoted keys in ES5
[[§11.1.5](http://es5.github.com/#x11.1.5), [§7.6](http://es5.github.com/#x7.6)].
([More info](https://mathiasbynens.be/notes/javascript-identifiers))

@@ -79,8 +79,7 @@ *(TODO: Unicode characters and escape sequences aren’t yet supported in this

- Numbers can be hexadecimal (base 16). (But note that neither signed
hexadecimals nor hexadecimal floats are allowed by ES5.)
- Numbers can be hexadecimal (base 16).
- Numbers can begin or end with a (leading or trailing) decimal point.
- Numbers can include `Infinity` and `-Infinity`.
- Numbers can include `Infinity`, `-Infinity`, `NaN`, and `-NaN`.

@@ -126,3 +125,3 @@ - Numbers can begin with an explicit plus sign.

This implementation's own [package.json5](package.json5) is more realistic:
This implementation’s own [package.json5](package.json5) is more realistic:

@@ -135,3 +134,3 @@ ```js

name: 'json5',
version: '0.2.0',
version: '0.5.0',
description: 'JSON for the ES5 era.',

@@ -141,15 +140,26 @@ keywords: ['json', 'es5'],

contributors: [
// TODO: Should we remove this section in favor of GitHub's list?
// https://github.com/aseemk/json5/contributors
'Max Nanasy <max.nanasy@gmail.com>',
'Andrew Eisenberg <andrew@eisenberg.as>',
'Jordan Tucker <jordanbtucker@gmail.com>',
],
main: 'lib/json5.js',
bin: 'lib/cli.js',
files: ["lib/"],
dependencies: {},
devDependencies: {
mocha: '~1.0.3',
gulp: "^3.9.1",
'gulp-jshint': "^2.0.0",
jshint: "^2.9.1",
'jshint-stylish': "^2.1.0",
mocha: "^2.4.5"
},
scripts: {
build: './lib/cli.js -c package.json5',
build: 'node ./lib/cli.js -c package.json5',
test: 'mocha --ui exports --reporter spec',
// TODO: Would it be better to define these in a mocha.opts file?
},
homepage: 'http://json5.org/',
license: 'MIT',
repository: {

@@ -165,5 +175,5 @@ type: 'git',

Join the [Google Group](http://groups.google.com/group/json5) if you're
Join the [Google Group](http://groups.google.com/group/json5) if you’re
interested in JSON5 news, updates, and general discussion.
Don't worry, it's very low-traffic.
Don’t worry, it’s very low-traffic.

@@ -185,3 +195,3 @@ The [GitHub wiki](https://github.com/aseemk/json5/wiki) is a good place to track

```
```sh
npm install json5

@@ -196,3 +206,3 @@ ```

```
```html
<script src="json5.js"></script>

@@ -216,3 +226,3 @@ ```

It supports the native [`replacer` and `space` arguments][json-stringify],
as well. *(TODO: Any implemented `toJSON` methods aren't used today.)*
as well. *(TODO: Any implemented `toJSON` methods aren’t used today.)*

@@ -224,3 +234,3 @@ [json-stringify]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

If you're running this on Node, you can also register a JSON5 `require()` hook
If you’re running this on Node, you can also register a JSON5 `require()` hook
to let you `require()` `.json5` files just like you can `.json` files:

@@ -237,5 +247,5 @@

```sh
json5 -c path/to/foo.json5 # generates path/to/foo.json
```
$ json5 -c path/to/foo.json5 # generates path/to/foo.json
```

@@ -245,3 +255,3 @@

```
```sh
git clone git://github.com/aseemk/json5.git

@@ -264,3 +274,3 @@ cd json5

MIT License. © 2012 Aseem Kishore, and [others](
MIT License © 2012-2016 Aseem Kishore, and [others](
https://github.com/aseemk/json5/contributors).

@@ -280,4 +290,4 @@

new parser to implement these ideas this was within my reach!
This code is also modeled directly off of Doug's open-source [json_parse.js][]
parser. I'm super grateful for that clean and well-documented code.
This code is also modeled directly off of Doug’s open-source [json_parse.js][]
parser. I’m super grateful for that clean and well-documented code.

@@ -289,2 +299,6 @@ [json_parse.js]: https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js

[Andrew Eisenberg](https://github.com/aeisenberg) has contributed the `stringify` method.
[Andrew Eisenberg](https://github.com/aeisenberg) has contributed the
`stringify` method.
[Jordan Tucker](https://github.com/jordanbtucker) has aligned JSON5 more closely
with ES5 and is actively maintaining this project.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc