Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/dataToEsm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export interface Options {
}

// convert data object into separate named exports (and default)
export default function dataToNamedExports<T extends { [key: string]: any }>(
data: T | Array<T>,
options: Options = {}
): string {
export default function dataToNamedExports(data: any, options: Options = {}): string {
const t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
const _ = options.compact ? '' : ' ';
const n = options.compact ? '' : '\n';
Expand Down
12 changes: 10 additions & 2 deletions test/dataToEsm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('dataToEsm', function() {
);
});

it('supports null serialize', function() {
it('serializes null', function() {
expect(dataToEsm({ null: null })).toEqual('export default {\n\t"null": null\n};\n');
});

Expand All @@ -61,8 +61,16 @@ describe('dataToEsm', function() {
);
});

it('default only for non-objects', function() {
it('exports default only for arrays', function() {
const arr = ['a', 'b'];
expect(dataToEsm(arr)).toEqual('export default [\n\t"a",\n\t"b"\n];');
});

it('exports default only for null', function() {
expect(dataToEsm(null)).toEqual('export default null;');
});

it('exports default only for primitive values', function() {
expect(dataToEsm('some string')).toEqual('export default "some string";');
});
});