mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 01:20:24 +03:00
Added function to parse optional boolean to string
This commit is contained in:
parent
a3bd10bc82
commit
1c39e3402b
2 changed files with 21 additions and 1 deletions
|
@ -30,3 +30,7 @@ export const equals = (value: any) => (otherValue: any) => value === otherValue;
|
||||||
export type BooleanString = 'true' | 'false';
|
export type BooleanString = 'true' | 'false';
|
||||||
|
|
||||||
export const parseBooleanToString = (value: boolean): BooleanString => (value ? 'true' : 'false');
|
export const parseBooleanToString = (value: boolean): BooleanString => (value ? 'true' : 'false');
|
||||||
|
|
||||||
|
export const parseOptionalBooleanToString = (value?: boolean): BooleanString | undefined => (
|
||||||
|
value === undefined ? undefined : parseBooleanToString(value)
|
||||||
|
);
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
import { capitalize, nonEmptyValueOrNull, parseBooleanToString, rangeOf } from '../../src/utils/utils';
|
import {
|
||||||
|
capitalize,
|
||||||
|
nonEmptyValueOrNull,
|
||||||
|
parseBooleanToString,
|
||||||
|
parseOptionalBooleanToString,
|
||||||
|
rangeOf,
|
||||||
|
} from '../../src/utils/utils';
|
||||||
|
|
||||||
describe('utils', () => {
|
describe('utils', () => {
|
||||||
describe('rangeOf', () => {
|
describe('rangeOf', () => {
|
||||||
|
@ -58,4 +64,14 @@ describe('utils', () => {
|
||||||
expect(parseBooleanToString(value)).toEqual(expectedResult);
|
expect(parseBooleanToString(value)).toEqual(expectedResult);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('parseOptionalBooleanToString', () => {
|
||||||
|
it.each([
|
||||||
|
[undefined, undefined],
|
||||||
|
[true, 'true'],
|
||||||
|
[false, 'false'],
|
||||||
|
])('parses value as expected', (value, expectedResult) => {
|
||||||
|
expect(parseOptionalBooleanToString(value)).toEqual(expectedResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue