Skip to content

Commit

Permalink
feat: Add RecordObject.
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenVerborgh committed Dec 21, 2020
1 parent eb6ba03 commit 147f3cf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export * from './util/AsyncHandler';
export * from './util/HeaderUtil';
export * from './util/PathUtil';
export * from './util/QuadUtil';
export * from './util/RecordObject';
export * from './util/SequenceHandler';
export * from './util/StreamUtil';
export * from './util/WaterfallHandler';
11 changes: 11 additions & 0 deletions src/util/RecordObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Helper class for instantiating multiple objects with Components.js.
* See https://github.com/LinkedSoftwareDependencies/Components.js/issues/26
*/
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class RecordObject implements Record<string, any> {
public constructor(record: Record<string, string> = {}) {
// eslint-disable-next-line no-constructor-return
return record;
}
}
12 changes: 12 additions & 0 deletions test/unit/util/RecordObject.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { RecordObject } from '../../../src/util/RecordObject';

describe('RecordObject', (): void => {
it('returns an empty record when created without parameters.', async(): Promise<void> => {
expect(new RecordObject()).toStrictEqual({});
});

it('returns the passed record.', async(): Promise<void> => {
const record = { abc: 'def' };
expect(new RecordObject(record)).toBe(record);
});
});

0 comments on commit 147f3cf

Please sign in to comment.