Fixed ES modules imports
@perfective/common can now be imported from regular .js/.mjs ESM files.
Added wrappers for most of the Math functions (#20)
Unlike the standard Math functions, the following functions throw an Exception for invalid inputs:
absolute()arccos(),arccosh()arcsin(),arcsinh()arctan(),arctan2(),arctanh()cos(),cosh()sin(),sinh()tan(),tanh()rounded(),roundedUp(),roundedDown(),roundedToFloat32(),truncated()power(),powerOf()squareRoot(),cubeRoot(),l2norm()exp(),expm1()log(),log10(),log1p(),log2()sign()with theSignnominal type
Replacing NaN with null is a redundant idea, because it’s trivial to use library functions with Maybe instead:
maybe(x).to(Math.acos).that(isNumber)Meanwhile, throwing an exception gives library users an option to track invalid inputs.
In this case, the Result monad can be used:
result(x).onto(resultFrom(arccos))Added more nominal types for numbers
- Added the
Infinity,PositiveInfinity, andNegativeInfinitynominal types with theisInfinity()type guard. - Added the
FiniteNumbernominal type with theisFinite()type guard (#18) andassertIsFinite()assertion. - Added the
PositiveNumber,NonPositiveNumber,NegativeNumber,NonNegativeNumbernominal types. - Added the
assertIsNonNegativeNumber()type guard.
Introduced assertion functions
- Added the
assertIsNotNaN()(#53) andassertIsNonNegativeNumber()functions. - Added the
typeException()function.