Skip to content

Commit

Permalink
refactor(utils): created context for utility modules
Browse files Browse the repository at this point in the history
  • Loading branch information
glebcha committed Nov 28, 2023
1 parent 3e793bb commit cf27697
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/getBody.spec.ts → src/utils/getBody/getBody.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
import { suite } from 'uvu';
import * as assert from 'uvu/assert';

import { query } from '../../mock';

import { getBody } from './getBody';
import { query } from './mock';

const getBodySuite = suite('getBody');
const clientSuite = suite('Safe JSON Stringify');

getBodySuite('should output object with formatted sql string', async () => {
clientSuite('should output object with formatted sql string', async () => {
const result = getBody(query);

assert.equal(result.length, 22);
});

getBodySuite.run();
clientSuite.run();
File renamed without changes.
1 change: 1 addition & 0 deletions src/utils/getBody/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { getBody } from './getBody';
14 changes: 10 additions & 4 deletions src/getType.ts → src/utils/getType.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface CheckFunctions {
[checkType: string]: (value: unknown) => boolean
[checkType: string]: (value: unknown) => boolean
}

const modifier = (type: string) => (item: unknown) => Object.prototype.toString.call(item) === `[object ${type}]`;
Expand All @@ -13,16 +13,22 @@ const checkTypes: Array<string> = [
'AsyncFunction',
'Number',
'Boolean',
'Object',
'Symbol',
'Null',
'Promise',
];
const specialCheckFunctions = { Date: (value: unknown): boolean => (value instanceof Date) };
const specialCheckFunctions = {
Date: (value: unknown): boolean => (value instanceof Date),
Object: isObject,
};

const checkFunctions: CheckFunctions = checkTypes.reduce((checkers, type) => ({
const checkFunctions = checkTypes.reduce<CheckFunctions & typeof specialCheckFunctions>((checkers, type) => ({
...checkers,
[type]: modifier(type),
}), { ...specialCheckFunctions });

function isObject(income: unknown): income is Record<string | number | symbol, unknown> {
return Object.prototype.toString.call(income) === '[object Object]';
}

export { checkFunctions as is };

0 comments on commit cf27697

Please sign in to comment.