funcunit
Version:
<!-- @hide title
55 lines (40 loc) • 1.58 kB
Markdown
{Object} System.jsonOptions
StealJS.config
Provides options that can be applied to JSON loading. The JSON extension has the following options:
{Function} [transform] A function that allows you to transform the JSON object that will be used as the module value.
```js
System.config({
jsonOptions: {
transform: function(load, data) {
// Delete secret data
delete data._secret;
return data;
}
}
});
```
{Object} load The load object for this module. Use this if you need to know the module's name or other metadata to determine how to transform it.
{Object} data The raw JSON data parsed by `JSON.parse`.
{Object} The object that will be used as the module's value.
## Use
**jsonOptions** is useful when your app (or one of your dependencies is importing a JSON file that isn't meant to be exposed in production. For example many packages do:
```
var pkg = require("./package.json");
```
Which will be imported by Steal. However the package.json contains metadata include paths on your filesystem that you likely don't want exposed by a web-server.
Typically code only needs their version for a few properties, such as the **version**. Using the *transform* function we can remote all others:
```
System.config({
jsonOptions: {
transform: function(load, data) {
// Delete every prop by `version`
// Only allow the version prop to be exposed
return {
version: data.version
};
}
}
});
```
When compiled every other property will be excluded from the build.