From a942eef23b1596bca7bab6796f7b3cf2ef1956ac Mon Sep 17 00:00:00 2001 From: Igor Kamyshev Date: Tue, 30 Jul 2024 16:44:54 +0700 Subject: [PATCH] Make smaller --- packages/contracts/package.json | 2 +- packages/contracts/src/index.ts | 27 +++++---------------------- 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 1b788f8..9498c6b 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -32,7 +32,7 @@ "size-limit": [ { "path": "./dist/contracts.js", - "limit": "797 B" + "limit": "774 B" } ] } diff --git a/packages/contracts/src/index.ts b/packages/contracts/src/index.ts index 2bd5e47..d141c26 100644 --- a/packages/contracts/src/index.ts +++ b/packages/contracts/src/index.ts @@ -42,12 +42,7 @@ export type Contract = { * bool.isData(true) === true; * bool.isData(42) === false; */ -export const bool: Contract = createSimpleContract( - (x: unknown): x is boolean => { - return typeof x === 'boolean'; - }, - 'boolean' -); +export const bool: Contract = createSimpleContract('boolean'); /** * _Contract_ that checks if a value is a number. @@ -56,12 +51,7 @@ export const bool: Contract = createSimpleContract( * num.isData(42) === true; * num.isData('42') === false; */ -export const num: Contract = createSimpleContract( - (x: unknown): x is number => { - return typeof x === 'number'; - }, - 'number' -); +export const num: Contract = createSimpleContract('number'); /** * _Contract_ that checks if a value is a string. @@ -70,12 +60,7 @@ export const num: Contract = createSimpleContract( * str.isData('hello') === true; * str.isData(42) === false; */ -export const str: Contract = createSimpleContract( - (x: unknown): x is string => { - return typeof x === 'string'; - }, - 'string' -); +export const str: Contract = createSimpleContract('string'); /** * Function that creates a _Contract_ that checks if a value is equal to a given value. @@ -354,10 +339,8 @@ export function tuple(...contracts: Array>): any { // -- utils -function createSimpleContract( - check: (x: unknown) => x is T, - exepctedType: string -): Contract { +function createSimpleContract(exepctedType: string): Contract { + const check = (x: unknown): x is T => typeof x === exepctedType; return { isData: check, getErrorMessages: createGetErrorMessages(check, (actual) => [