@parischap/conversions
Version:
A functional library to replace partially the native Intl API
63 lines • 1.81 kB
JavaScript
/**
* A module that implements a `CVEmail` brand, i.e. a string that represents a valid email. 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/Email/';
/**
* Module TypeId
*
* @category Module markers
*/
export const TypeId = /*#__PURE__*/Symbol.for(moduleTag);
/**
* Constructs an Email without any verifications
*
* @category Constructors
*/
export const unsafeFromString = /*#__PURE__*/Brand.nominal();
/**
* Brand constructor. Should not be used directly
*
* @internal
*/
export const constructor = /*#__PURE__*/Brand.refined(MString.isEmail, s => Brand.error(`'${s}' does not represent a email`));
/**
* Constructs an Option of an Email from a string.
*
* @category Constructors
*/
export const fromStringOption = /*#__PURE__*/constructor.option.bind(constructor);
/**
* Constructs an Either of an Email from a string.
*
* @category Constructors
*/
export const fromString = /*#__PURE__*/constructor.either.bind(constructor);
/**
* Constructs an Email if possible. Throws otherwise.
*
* @category Constructors
*/
export const fromStringOrThrow = constructor;
/**
* A Schema that transforms a string into a CVBrand.Email.Type
*
* @ignore
*/
export const SchemaFromString = /*#__PURE__*/Schema.String.pipe(/*#__PURE__*/Schema.fromBrand(constructor));
/**
* A Schema that represents a CVBrand.Email.Type
*
* @ignore
*/
export const SchemaFromSelf = /*#__PURE__*/Schema.typeSchema(SchemaFromString);
//# sourceMappingURL=Email.js.map