systemjs-plugin-json
Advanced tools
Comparing version
27
json.js
@@ -5,3 +5,10 @@ /* | ||
define({ | ||
// this code allows named exports of valid identifiers in json to work with rollup | ||
// so you can effectively "pick" a json value and have the other base-level json values excluded | ||
// not comprehensive of course | ||
function isValidIdentifier(exportName) { | ||
return exportName.match(/^[a-zA-Z_$][0-9a-zA-Z_$]*$/); | ||
} | ||
module.exports = { | ||
translate: function(load) { | ||
@@ -13,9 +20,2 @@ var json = JSON.parse(load.source); | ||
var namedExports = Object.keys(json); | ||
// this code allows named exports of valid identifiers in json to work with rollup | ||
// so you can effectively "pick" a json value and have the other base-level json values excluded | ||
// not comprehensive of course | ||
function isValidIdentifier (exportName) { | ||
return exportName.match(/^[a-zA-Z_$][0-9a-zA-Z_$]*$/); | ||
} | ||
var validIdentifiers = namedExports.filter(isValidIdentifier); | ||
@@ -31,6 +31,8 @@ | ||
namedExports.forEach(function (exportName) { | ||
if (validIdentifiers.indexOf(exportName) !== -1) | ||
if (validIdentifiers.indexOf(exportName) !== -1) { | ||
output.push(exportName + ': ' + exportName + ',\n'); | ||
else | ||
} | ||
else { | ||
output.push(JSON.stringify(exportName) + ': ' + JSON.stringify(json[exportName]) + ',\n'); | ||
} | ||
}); | ||
@@ -48,5 +50,6 @@ | ||
instantiate: function(load) { | ||
if (!this.builder) | ||
if (!this.builder) { | ||
return JSON.parse(load.source); | ||
} | ||
} | ||
}); | ||
} |
{ | ||
"name": "systemjs-plugin-json", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"main": "json", | ||
"scripts": { | ||
"test": "serve ." | ||
}, | ||
"repository": { | ||
@@ -13,3 +16,7 @@ "type": "git", | ||
}, | ||
"homepage": "https://github.com/systemjs/plugin-json" | ||
"homepage": "https://github.com/systemjs/plugin-json", | ||
"devDependencies": { | ||
"serve": "^3.2.7", | ||
"systemjs": "^0.20.5" | ||
} | ||
} |
plugin-json | ||
=========== | ||
[](https://cdnjs.com/libraries/systemjs-plugin-json) | ||
@@ -7,1 +8,10 @@ | ||
Testing this project | ||
-------------------- | ||
```sh | ||
npm test | ||
``` | ||
browse to <http://localhost:3000/test.html> and open the browser's development console. | ||
You should see the json object logged. |
3597
8.08%7
16.67%45
7.14%17
142.86%2
Infinity%