From 147f3cf0c7486506ff07cd1211a1ab88c85e7ee8 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Mon, 21 Dec 2020 00:06:32 +0100 Subject: [PATCH] feat: Add RecordObject. --- src/index.ts | 1 + src/util/RecordObject.ts | 11 +++++++++++ test/unit/util/RecordObject.test.ts | 12 ++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 src/util/RecordObject.ts create mode 100644 test/unit/util/RecordObject.test.ts diff --git a/src/index.ts b/src/index.ts index a81b04b3d..4d9ee40f5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/util/RecordObject.ts b/src/util/RecordObject.ts new file mode 100644 index 000000000..ad8d26872 --- /dev/null +++ b/src/util/RecordObject.ts @@ -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 { + public constructor(record: Record = {}) { + // eslint-disable-next-line no-constructor-return + return record; + } +} diff --git a/test/unit/util/RecordObject.test.ts b/test/unit/util/RecordObject.test.ts new file mode 100644 index 000000000..cc9582854 --- /dev/null +++ b/test/unit/util/RecordObject.test.ts @@ -0,0 +1,12 @@ +import { RecordObject } from '../../../src/util/RecordObject'; + +describe('RecordObject', (): void => { + it('returns an empty record when created without parameters.', async(): Promise => { + expect(new RecordObject()).toStrictEqual({}); + }); + + it('returns the passed record.', async(): Promise => { + const record = { abc: 'def' }; + expect(new RecordObject(record)).toBe(record); + }); +});