Добавление функции toRequestParamValue (#32)

This commit is contained in:
Nikolay
2020-12-28 10:33:04 +03:00
committed by GitHub
parent c051c23896
commit 82b91ed422
2 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,26 @@
import {toRequestParamValue} from '../toRequestParamValue';
describe('toRequestParamValue', () => {
it('Возвращает простые значения', () => {
expect(toRequestParamValue('trt')).toBe('trt');
expect(toRequestParamValue(0)).toBe(0);
expect(toRequestParamValue(false)).toBe(false);
});
it('Простые пустые значения возвращают undefined', () => {
expect(toRequestParamValue('')).toBeUndefined();
expect(toRequestParamValue(null)).toBeUndefined();
expect(toRequestParamValue(undefined)).toBeUndefined();
});
it('Возвращает заполненные объекты', () => {
expect(toRequestParamValue({foo: undefined})).toMatchObject({foo: undefined});
expect(toRequestParamValue({foo: 'bar'})).toMatchObject({foo: 'bar'});
expect(toRequestParamValue(['rtt'])).toEqual(['rtt']);
});
it('Пустые объекты возвращают undefined', () => {
expect(toRequestParamValue({})).toBeUndefined();
expect(toRequestParamValue([])).toBeUndefined();
});
});

View File

@ -0,0 +1,7 @@
import {isNotEmpty} from '../referers/common';
export function toRequestParamValue<T>(val: T): T;
export function toRequestParamValue<T>(val?: T): Undefinable<T>;
export function toRequestParamValue<T>(val?: T) {
return isNotEmpty(val) ? val : undefined;
}