UNPKG

@parischap/conversions

Version:

A functional library to replace partially the native Intl API

66 lines 1.98 kB
/** * A module that implements a `CVSemVer` brand, i.e. a string that represents a valid semantic * version. See the `Effect` documentation about Branding * (https://effect.website/docs/code-style/branded-types/) if you are not familiar with this * concept. */ import * as MString from '@parischap/effect-lib/MString'; import * as Brand from 'effect/Brand'; import * as Schema from 'effect/Schema'; /** * Module tag * * @category Module markers */ export const moduleTag = '@parischap/conversions/SemVer/'; /** * Module TypeId * * @category Module markers */ export const TypeId = /*#__PURE__*/Symbol.for(moduleTag); /** * Constructs a `CVSemVer` without any verifications * * @category Constructors */ export const unsafeFromString = /*#__PURE__*/Brand.nominal(); /** * Brand constructor. Should not be used directly * * @ignore */ export const constructor = /*#__PURE__*/Brand.refined(MString.isSemVer, s => Brand.error(`'${s}' does not represent a semver`)); /** * Tries to construct a `CVSemVer` from a string. Returns a `Some` if the conversion can be * performed, a `None` otherwise * * @category Constructors */ export const fromStringOption = /*#__PURE__*/constructor.option.bind(constructor); /** * Tries to construct a `CVSemVer` from a string. Returns a `Right` if the conversion can be * performed, a `Left` otherwise * * @category Constructors */ export const fromString = /*#__PURE__*/constructor.either.bind(constructor); /** * Constructs a `CVSemVer` if possible. Throws otherwise. * * @category Constructors */ export const fromStringOrThrow = constructor; /** * A `Schema` that transforms a string into a `CVSemVer` * * @ignore */ export const SchemaFromString = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.fromBrand(constructor)); /** * A `Schema` that represents a `CVSemVer` * * @ignore */ export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromString); //# sourceMappingURL=SemVer.js.map