feat: add conversions to boolean and make mandatory
Some checks failed
/ test (pull_request) Failing after 16s

This commit is contained in:
Glen Whitney 2025-04-12 07:46:15 -07:00
parent f38a2d5e88
commit 4b81fbe6e2
3 changed files with 9 additions and 1 deletions

View file

@ -1 +1,2 @@
export * as typeDefinition from './BooleanT.js'
export * as type from './type.js'

View file

@ -4,7 +4,9 @@ import math from '#nanomath'
describe('number type operations', () => {
it('converts to number', () => {
assert.strictEqual(math.number(2.637), 2.637)
assert(isNaN(math.number(NaN)))
assert.strictEqual(math.number(true), 1)
assert.strictEqual(math.number(false), 0)
assert.strictEqual(math.number(), 0)
})
})

View file

@ -3,5 +3,10 @@ import {BooleanT} from '#boolean/BooleanT.js'
import {Returns} from '#core/Type.js'
import {NumberT} from '#number/NumberT.js'
const num = f => Returns(NumberT, f)
export const number = plain(a => a)
number.also(BooleanT, Returns(NumberT, a => a ? 1 : 0))
number.also(
BooleanT, num(a => a ? 1 : 0),
[], num(() => 0)
)