Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Expose the "compact" and "namedExports" options (#45)
Browse files Browse the repository at this point in the history
* update rollup-pluginutils to support null values in json

* Expose the "compact" option

* Expose the "namedExports" option
  • Loading branch information
realityking authored and lukastaegert committed Sep 13, 2018
1 parent e9c01b9 commit 2a528e3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
8 changes: 7 additions & 1 deletion README.md
Expand Up @@ -47,7 +47,13 @@ export default {

// specify indentation for the generated default export —
// defaults to '\t'
indent: ' '
indent: ' ',

// ignores indent and generates the smallest code
compact: true, // Default: false

// generate a named export for every property of the JSON object
namedExports: true // Default: true
})
]
};
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Expand Up @@ -17,7 +17,12 @@ export default function json (options = {}) {
}

return {
code: dataToEsm(data, {preferConst: options.preferConst, indent}),
code: dataToEsm(data, {
preferConst: options.preferConst,
compact: options.compact,
namedExports: options.namedExports,
indent
}),
map: {mappings: ''}
};
}
Expand Down
1 change: 1 addition & 0 deletions test/samples/form/compact.js
@@ -0,0 +1 @@
export var validKey=true;export var nested={subKey:"ok"};export var array=[1,"2"];export default{validKey:validKey,"invalid-key": 1,nested:nested,array:array,"function": "not used","null": null};
13 changes: 13 additions & 0 deletions test/samples/form/namedExports.js
@@ -0,0 +1,13 @@
export default {
validKey: true,
"invalid-key": 1,
nested: {
subKey: "ok"
},
array: [
1,
"2"
],
"function": "not used",
"null": null
};
14 changes: 14 additions & 0 deletions test/test.js
Expand Up @@ -138,6 +138,20 @@ describe('rollup-plugin-json', () => {
read('samples/form/customIndent.js')
);
});

it('generates correct code with compact=true', () => {
assert.deepEqual(
json({ compact: true }).transform(read('samples/form/input.json'), 'input.json').code + '\n',
read('samples/form/compact.js')
);
});

it('generates correct code with namedExports=false', () => {
assert.deepEqual(
json({ namedExports: false }).transform(read('samples/form/input.json'), 'input.json').code + '\n',
read('samples/form/namedExports.js')
);
});
});

function read (file) {
Expand Down

0 comments on commit 2a528e3

Please sign in to comment.