UNPKG

fp-ts-std

Version:

The missing pseudo-standard library for fp-ts.

36 lines (35 loc) 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.includes = exports.split = exports.size = exports.reverse = exports.surround = exports.append = exports.prepend = exports.toLowerCase = exports.toUpperCase = exports.last = exports.head = exports.Show = exports.Semigroup = exports.Ord = exports.Eq = exports.toString = exports.unNonEmptyString = exports.fromNumber = exports.unsafeFromString = exports.fromString = void 0; const O = require("fp-ts/Option"); const Predicate_1 = require("fp-ts/Predicate"); const function_1 = require("fp-ts/function"); const string_1 = require("fp-ts/string"); const newtype_ts_1 = require("newtype-ts"); const Newtype_1 = require("./Newtype"); const Option_1 = require("./Option"); const Str = require("./String"); exports.fromString = (0, function_1.flow)(O.fromPredicate((0, Predicate_1.not)(string_1.isEmpty)), O.map((Newtype_1.pack))); exports.unsafeFromString = (0, function_1.flow)(exports.fromString, (0, Option_1.unsafeExpect)("Failed to lift an empty string to NonEmptyString")); exports.fromNumber = (0, function_1.flow)(Str.fromNumber, exports.unsafeFromString); exports.unNonEmptyString = Newtype_1.unpack; exports.toString = exports.unNonEmptyString; exports.Eq = (0, newtype_ts_1.getEq)(string_1.Eq); exports.Ord = (0, newtype_ts_1.getOrd)(string_1.Ord); exports.Semigroup = (0, newtype_ts_1.getSemigroup)(string_1.Semigroup); exports.Show = { show: (0, function_1.flow)(exports.unNonEmptyString, string_1.Show.show), }; exports.head = (0, Newtype_1.over)((0, function_1.flow)(Str.head, Option_1.unsafeUnwrap)); exports.last = (0, Newtype_1.over)((0, function_1.flow)(Str.last, Option_1.unsafeUnwrap)); exports.toUpperCase = (0, Newtype_1.over)(string_1.toUpperCase); exports.toLowerCase = (0, Newtype_1.over)(string_1.toLowerCase); exports.prepend = (0, function_1.flow)(Str.prepend, Newtype_1.over); exports.append = (0, function_1.flow)(Str.append, Newtype_1.over); exports.surround = (0, function_1.flow)(Str.surround, Newtype_1.over); exports.reverse = (0, Newtype_1.over)(Str.reverse); exports.size = (0, function_1.flow)(exports.toString, string_1.size); const split = (separator) => (0, function_1.flow)(exports.toString, (0, string_1.split)(separator)); exports.split = split; const includes = (search) => (0, function_1.flow)(exports.toString, (0, string_1.includes)(search)); exports.includes = includes;