Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* Power JSON | ||
* @version 1.0.0-alpha | ||
* | ||
* @browserSupport | ||
* Browsers: | ||
* IE >= 11 | ||
* Edge All | ||
* Firefox >= 6 | ||
* Chrome >= 21 | ||
* Safari >= 7.1 | ||
* Opera >= 15 | ||
* | ||
* Nodejs: | ||
* Nodejs >= 6 | ||
* | ||
* @feature | ||
* 1. comment support | ||
* 2. {id: 1} instead of {"id": 1} (No quotes) | ||
* 3. single quote support (support both '' and "") | ||
* 4. multi-line string support | ||
* 5. operator support, e.g. {id: 2 * (1 + 1)} | ||
* 6. file support e.g. {file: new File('./myfile.txt')} | ||
* 7. GET support e.g. {file: new GET('http://www.xxx.com')} | ||
* 8. import support e.g. {anotherPJFile: new PJSON('./file2.pjson')} | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const parser = require('./parser/pjson.browser.js'); | ||
|
||
function parse(pjson) { | ||
return parser.parse(pjson) | ||
} | ||
|
||
function stringify(pjson) { | ||
return JSON.stringify(pjson); | ||
} | ||
|
||
window.PJSON = { | ||
parse, | ||
stringify | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
'use strict'; | ||
|
||
const path = require('path'), | ||
fs = require('fs'); | ||
|
||
const parser = require('./parser/pjson.node.js'); | ||
|
||
function parse(pjson) { | ||
return parser.parse(pjson, { | ||
filepath: '' | ||
}) | ||
} | ||
|
||
function parseFile(filepath) { | ||
if (path.extname(filepath) === '') { | ||
filepath = filepath + '.pjson'; | ||
} | ||
|
||
return new Promise(function(res, rej) { | ||
const pjsonFile = fs.readFile(filepath, function(err, pjsonFile) { | ||
if (err) { | ||
rej(); | ||
return; | ||
} | ||
res(parser.parse(pjsonFile.toString(), { | ||
filepath | ||
})) | ||
}) | ||
}) | ||
} | ||
|
||
function parseFileSync(filepath) { | ||
if (path.extname(filepath) === '') { | ||
filepath = filepath + '.pjson'; | ||
} | ||
|
||
const pjsonFile = fs.readFileSync(filepath).toString(); | ||
return parser.parse(pjsonFile, { | ||
filepath | ||
}) | ||
} | ||
|
||
function stringify(pjson) { | ||
return JSON.stringify(pjson); | ||
} | ||
|
||
function stringifyFile(filepath, pjson) { | ||
if (path.extname(filepath) === '') { | ||
filepath = filepath + '.pjson'; | ||
} | ||
|
||
return new Promise(function(res, rej) { | ||
fs.writeFile(filepath, JSON.stringify(pjson), function(err) { | ||
if (err) { | ||
rej(); | ||
return; | ||
} | ||
res(); | ||
}) | ||
}) | ||
} | ||
|
||
function stringifyFileSync(filepath, pjson) { | ||
if (path.extname(filepath) === '') { | ||
filepath = filepath + '.pjson'; | ||
} | ||
|
||
fs.writeFileSync(filepath, JSON.stringify(pjson)); | ||
} | ||
|
||
module.exports = { | ||
parse, | ||
parseFile, | ||
parseFileSync, | ||
stringify, | ||
stringifyFile, | ||
stringifyFileSync | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.