Comparing version 0.0.1 to 0.0.2
@@ -8,7 +8,7 @@ /** | ||
var removeComments = function (x) { | ||
x = x.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*)/g, function (m, g1) { | ||
x = x.replace(/\\"|"(?:\\"|[^"])*"|(\/\*[\s\S]*?\*\/)/g, function (m, g1) { | ||
return !g1 ? m : ""; // if g1 is not set/matched, re-insert it, else remove | ||
}); | ||
x = x.replace(/\\"|"(?:\\"|[^"])*"|(\/\*[\s\S]*?\*\/)/g, function (m, g1) { | ||
x = x.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*)/g, function (m, g1) { | ||
return !g1 ? m : ""; // if g1 is not set/matched, re-insert it, else remove | ||
@@ -15,0 +15,0 @@ }); |
@@ -49,4 +49,29 @@ /** | ||
}); | ||
let jsonxString = `{ | ||
// keys are not necessary to be quoted | ||
name: "jsonx", | ||
/* This is also a comment. */ | ||
url: "http://jsonx.org", | ||
/* | ||
Here is some more comments | ||
which span across multi lines. | ||
*/ | ||
"languages-bindings": ["Javascript", "Golang",], | ||
/* | ||
Tailing comma is not a problem. | ||
Multiline text also works. | ||
*/ | ||
description: \`Multiline text is translated into an array | ||
of strings. JSONx makes JSON easier to use for | ||
configuration files.\`, | ||
}`; | ||
console.log(JSON.stringify(JSON.parse(jsonx.toJSON(jsonxString)), null, 2)); | ||
}); | ||
})(); |
{ | ||
"name": "jsonx-js", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "JSONx javascript binding.", | ||
@@ -5,0 +5,0 @@ "main": "jsonx.js", |
# JSONx-js | ||
JSONx javascript binding. | ||
* `JSONx` is a superset of `JSON`, meaning a valid `JSON` string is automatically a valid `JSONx` string. | ||
* `JSONx` is not intended to replace `JSON`, instead, it is intended to be translated to `JSON`. | ||
* `JSONx-js` is the Javascript binding of `JSONx`. It helps to translate a `JSONx` string to a `JSON` string. | ||
## Installation | ||
`npm install jsonx-js` | ||
`npm install jsonx-js` | ||
## Examples | ||
```javascript | ||
{ | ||
// keys are not necessary to be quoted | ||
name: "jsonx", | ||
/* This is also a comment. */ | ||
url: "http://jsonx.org", | ||
/* | ||
Here is some more comments | ||
which span across multi lines. | ||
*/ | ||
"languages-bindings": ["Javascript", "Golang",], | ||
/* | ||
Tailing comma is not a problem. | ||
Multiline text also works. | ||
*/ | ||
description: `Multiline text is translated into an array | ||
of strings. JSONx makes JSON easier to use for | ||
configuration files.`, | ||
} | ||
``` | ||
The `JSONx` above should produce the following `JSON`: | ||
```JSON | ||
{ | ||
"name": "jsonx", | ||
"url": "http://jsonx.org", | ||
"languages-bindings": [ | ||
"Javascript", | ||
"Golang" | ||
], | ||
"description": [ | ||
"Multiline text is translated into an array", | ||
"of strings. JSONx makes JSON easier to use for", | ||
"configuration files." | ||
] | ||
} | ||
``` | ||
# Code in Node.js | ||
```javascript | ||
var jsonx = require('jsonx-js'); | ||
var jsonxString = '...'; | ||
var jsonString = jsonx.toJSON(jsonxString); | ||
console.log(jsonString); | ||
``` | ||
# Code in browsers | ||
```html | ||
<script src="path/to/jsonx.js"> | ||
<script> | ||
var jsonxString = '...'; | ||
var jsonString = jsonx.toJSON(jsonxString); | ||
console.log(jsonString); | ||
</script> | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6504
108
70