UNPKG

@parischap/conversions

Version:

A functional library to replace partially the native Intl API

120 lines 3.81 kB
/** * This module implements a CVReal brand, i.e. a number that disallows Infinity and NaN. Can be used * to represent a temperature, a height from sea-level,... See the `Effect` documentation about * Branding (https://effect.website/docs/code-style/branded-types/) if you are not familiar with * this concept. */ import * as MNumber from '@parischap/effect-lib/MNumber'; import * as MString from '@parischap/effect-lib/MString'; import * as Brand from 'effect/Brand'; import {flow} from 'effect/Function'; import * as Schema from 'effect/Schema'; /** * Module tag * * @category Module markers */ export const moduleTag = '@parischap/conversions/Real/'; /** * Module TypeId * * @category Module markers */ export const TypeId = /*#__PURE__*/Symbol.for(moduleTag); /** * Brand constructor. Should not be used directly * * @ignore */ export const constructor = /*#__PURE__*/Brand.refined(MNumber.isFinite, /*#__PURE__*/flow(/*#__PURE__*/MString.fromNumber(10), /*#__PURE__*/MString.prepend("'"), /*#__PURE__*/MString.append("' does not represent a finite number"), Brand.error)); /** * Constructs a `CVReal` from a number without any verifications * * @category Constructors */ export const unsafeFromNumber = /*#__PURE__*/Brand.nominal(); /** * Tries to construct a `CVReal` from a number. Returns a `Some` if the conversion can be performed, * a `None` otherwise * * @category Constructors */ export const fromNumberOption = /*#__PURE__*/constructor.option.bind(constructor); /** * Tries to construct a `CVReal` from a number. Returns a `Right` if the conversion can be * performed, a `Left` otherwise * * @category Constructors */ export const fromNumber = /*#__PURE__*/constructor.either.bind(constructor); /** * Constructs a `CVReal` from a number if possible. Throws otherwise * * @category Constructors */ export const fromNumberOrThrow = constructor; /** * Constructs a `CVReal` from a `BigDecimal` without any checks * * @category Constructors */ export const unsafeFromBigDecimal = MNumber.unsafeFromBigDecimal; /** * Tries to construct a `CVReal` from a `BigDecimal`. Returns a `Some` if the conversion can be * performed, a `None` otherwise * * @category Constructors */ export const fromBigDecimalOption = MNumber.fromBigDecimalOption; /** * Tries to construct a `CVReal` from a `BigDecimal`. Returns a `Right` if the conversion can be * performed, a `Left` otherwise * * @category Constructors */ export const fromBigDecimal = MNumber.fromBigDecimal; /** * Constructs a `CVReal` from a `BigDecimal` if possible. Throws otherwise * * @category Constructors */ export const fromBigDecimalOrThrow = MNumber.fromBigDecimalOrThrow; /** * Constructs a `CVReal` from a `BigInt` without any checks * * @category Constructors */ export const unsafeFromBigInt = MNumber.unsafeFromBigInt; /** * Tries to construct a `CVReal` from a `BigInt`. Returns a `Some` if the conversion can be * performed, a `None` otherwise * * @category Constructors */ export const fromBigIntOption = MNumber.fromBigIntOption; /** * Tries to construct a `CVReal` from a `BigInt`. Returns a `Right` if the conversion can be * performed, a `Left` otherwise * * @category Constructors */ export const fromBigInt = MNumber.fromBigInt; /** * Constructs a `CVReal` from a `BigInt` if possible. Throws otherwise * * @category Constructors */ export const fromBigIntOrThrow = MNumber.fromBigIntOrThrow; /** * A `Schema` that transforms a number into a `CVReal` * * @ignore */ export const SchemaFromNumber = /*#__PURE__*/Schema.Number.pipe(/*#__PURE__*/Schema.fromBrand(constructor)); /** * A `Schema` that represents a `CVReal` * * @ignore */ export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromNumber); //# sourceMappingURL=Real.js.map