Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! Stringify refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
skad0 committed Feb 22, 2017
1 parent 46397fe commit b68e799
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 4 additions & 2 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ const JSON5 = require('json5');

const format = require('./format');

const DEFAULTS = { exportType: 'json5', space: 4 };

const generators = {
json5: (obj, space) => JSON5.stringify(obj, null, space),
json: (obj, space) => JSON.stringify(obj, null, space),
commonjs: (obj, space) => `module.exports = ${JSON.stringify(obj, null, space)};\n`,
es2015: (obj, space) => `export default ${JSON.stringify(obj, null, space)};\n`
};
// Aliases
generators.es6 = generators.es2015;

/**
Expand All @@ -24,8 +27,7 @@ generators.es6 = generators.es2015;
* @returns {String}
*/
module.exports = function (decl, opts) {
const defaults = { exportType: 'json5', space: 4 };
const options = Object.assign(defaults, opts);
const options = Object.assign({}, DEFAULTS, opts);

assert(options.format, 'You must declare target format');
assert(generators.hasOwnProperty(options.exportType), 'Specified format isn\'t supported');
Expand Down
6 changes: 1 addition & 5 deletions test/stringify/enb.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const test = require('ava');
const BemCell = require('@bem/cell');
const BemEntityName = require('@bem/entity-name');
const JSON5 = require('json5');

const stringify = require('../../lib/stringify');
Expand All @@ -9,10 +8,7 @@ const obj = {
format: 'enb',
decl: [{ block: 'block', elem: 'elem', mod: 'mod', val: 'val' }]
};
const cell = new BemCell({
entity: new BemEntityName({ block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' }),
tech: null
});
const cell = BemCell.create({ block: 'block', elem: 'elem', modName: 'mod', modVal: 'val' });

test('should throws error if no format given', t => {
t.throws(() => stringify(cell),
Expand Down

0 comments on commit b68e799

Please sign in to comment.