Skip to content

Commit

Permalink
feat(utils): add getMaybeBooleanFromRichBoolean()
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Mar 14, 2024
1 parent b88d022 commit f4d7b59
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export { customDayjs } from './utils/customDayjs'
export { getCoordinates, coordinatesAreDistinct } from './utils/coordinates'
export { getHashFromCollection } from './utils/getHashFromCollection'
export { getLocalizedDayjs } from './utils/getLocalizedDayjs'
export { getMaybeBooleanFromRichBoolean } from './utils/getMaybeBooleanFromRichBoolean'
export { getOptionsFromIdAndName } from './utils/getOptionsFromIdAndName'
export { getOptionsFromLabelledEnum } from './utils/getOptionsFromLabelledEnum'
export { getPseudoRandomString } from './utils/getPseudoRandomString'
Expand Down
24 changes: 24 additions & 0 deletions src/utils/__tests__/getMaybeBooleanFromRichBoolean.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from '@jest/globals'

import { RichBoolean } from '../../constants'
import { getMaybeBooleanFromRichBoolean } from '../getMaybeBooleanFromRichBoolean'

describe('utils/getMaybeBooleanFromRichBoolean()', () => {
it('should return `true` for `RichBoolean.TRUE`', () => {
const result = getMaybeBooleanFromRichBoolean(RichBoolean.TRUE)

expect(result).toBe(true)
})

it('should return `false` for `RichBoolean.FALSE`', () => {
const result = getMaybeBooleanFromRichBoolean(RichBoolean.FALSE)

expect(result).toBe(false)
})

it('should return `undefined` for `RichBoolean.BOTH`', () => {
const result = getMaybeBooleanFromRichBoolean(RichBoolean.BOTH)

expect(result).toBeUndefined()
})
})
14 changes: 14 additions & 0 deletions src/utils/getMaybeBooleanFromRichBoolean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { RichBoolean } from '../constants'

export function getMaybeBooleanFromRichBoolean(richBoolean: RichBoolean): boolean | undefined {
switch (richBoolean) {
case RichBoolean.FALSE:
return false

case RichBoolean.TRUE:
return true

default:
return undefined
}
}

0 comments on commit f4d7b59

Please sign in to comment.