Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions test/utilities/integrity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { insist } from '../../tools/integrity';

describe('integrity', () => {
it('should insist', () => {
(() => insist({}, 'a')).should.throw(TypeError);
(() => insist({ a: 1 }, 'a', 'b')).should.throw(TypeError);
(() => insist({ a: 1, b: 2 }, 'a', 'b')).should.not.throw();
});
});
16 changes: 16 additions & 0 deletions tools/integrity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @description Insist that the provided data has the required properties.
* @param thing to encourage to have data
* @param args arguments to ensure
*/
export const insist = (thing: Record<string, unknown>, ...args: string[]) => {
if (!thing || !Object.keys(thing).length) {
throw new TypeError('The provided data does not have the required properties.');
}

args.forEach((arg) => {
if (!thing[arg]) {
throw new TypeError('The provided data does not have the required properties.');
}
});
};
1 change: 1 addition & 0 deletions tools/utilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* istanbul ignore file */

export * from './integrity';
export * from './timeDate';
export * from './translation';