Добавление функции toRequestParamValue (#32)
This commit is contained in:
26
src/core/utils/__test__/toRequestParamValue.test.ts
Normal file
26
src/core/utils/__test__/toRequestParamValue.test.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
7
src/core/utils/toRequestParamValue.ts
Normal file
7
src/core/utils/toRequestParamValue.ts
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user