NonEmptyString overview

A newtype around strings signifying non-emptiness therein.

Many further utilities can be defined in terms of the String module via contramap, for example any predicates.

Added in v0.15.0


Table of contents


0 Types

NonEmptyString (type alias)

Newtype representing a non-empty string. Non-emptiness is only guaranteed so long as interaction with the newtype is confined to exports from this module, as unlike NonEmptyArray it’s only protected by a smart constructor.

Signature

export type NonEmptyString = Newtype<NonEmptyStringSymbol, string>
type NonEmptyString = Newtype NonEmptyStringSymbol string

Example

import { NonEmptyString, unsafeFromString } from 'fp-ts-std/NonEmptyString'
import * as O from 'fp-ts/Option'

const signature: NonEmptyString = unsafeFromString('- @samhh.com')

Added in v0.15.0

1 Typeclass Instances

Eq

Eq instance for NonEmptyString for testing equivalence.

Signature

export declare const Eq: Eq<NonEmptyString>
Eq :: Eq NonEmptyString

Added in v0.15.0

Ord

Ord instance for NonEmptyString for comparison.

Signature

export declare const Ord: Ord<NonEmptyString>
Ord :: Ord NonEmptyString

Added in v0.15.0

Semigroup

Semigroup instance for NonEmptyString, enabling concatenation.

Signature

export declare const Semigroup: Semigroup<NonEmptyString>
Semigroup :: Semigroup NonEmptyString

Added in v0.15.0

Show

Show instance for NonEmptyString.

Signature

export declare const Show: Show<NonEmptyString>
Show :: Show NonEmptyString

Added in v0.15.0

3 Functions

append

Append a string to a NonEmptyString.

Signature

export declare const append: (x: string) => Endomorphism<NonEmptyString>
append :: string -> Endomorphism NonEmptyString

Added in v0.15.0

fromNumber

Safely derive a NonEmptyString from any number.

Signature

export declare const fromNumber: (x: number) => NonEmptyString
fromNumber :: number -> NonEmptyString

Added in v0.15.0

fromString

Smart constructor from strings.

Signature

export declare const fromString: (x: string) => O.Option<NonEmptyString>

Added in v0.15.0

Get the first character in a NonEmptyString.

Signature

export declare const head: Endomorphism<NonEmptyString>
head :: Endomorphism NonEmptyString

Added in v0.15.0

includes

Predicate upon the presence of a search string anywhere in a NonEmptyString.

Signature

export declare const includes: (search: string) => Predicate<NonEmptyString>
includes :: string -> Predicate NonEmptyString

Added in v0.17.0

last

Get the last character in a NonEmptyString.

Signature

export declare const last: Endomorphism<NonEmptyString>
last :: Endomorphism NonEmptyString

Added in v0.15.0

prepend

Prepend a string to a NonEmptyString.

Signature

export declare const prepend: (x: string) => Endomorphism<NonEmptyString>
prepend :: string -> Endomorphism NonEmptyString

Added in v0.15.0

reverse

Reverse a NonEmptyString.

Signature

export declare const reverse: Endomorphism<NonEmptyString>
reverse :: Endomorphism NonEmptyString

Added in v0.15.0

size

Calculate the number of characters in a NonEmptyString.

Signature

export declare const size: (x: NonEmptyString) => number
size :: NonEmptyString -> number

Added in v0.17.0

split

Split a NonEmptyString into an array of strings using separator.

Signature

export declare const split: (separator: string | RegExp) => (x: NonEmptyString) => ReadonlyNonEmptyArray<string>
split :: string | RegExp -> NonEmptyString -> ReadonlyNonEmptyArray string

Added in v0.17.0

surround

Surround a NonEmptyString. Equivalent to calling prepend and append with the same outer value.

Signature

export declare const surround: (x: string) => Endomorphism<NonEmptyString>
surround :: string -> Endomorphism NonEmptyString

Added in v0.15.0

toLowerCase

Convert a NonEmptyString to lowercase.

Signature

export declare const toLowerCase: Endomorphism<NonEmptyString>
toLowerCase :: Endomorphism NonEmptyString

Added in v0.15.0

toString

An alias of unNonEmptyString.

Signature

export declare const toString: (x: NonEmptyString) => string
toString :: NonEmptyString -> string

Added in v0.15.0

toUpperCase

Convert a NonEmptyString to uppercase.

Signature

export declare const toUpperCase: Endomorphism<NonEmptyString>
toUpperCase :: Endomorphism NonEmptyString

Added in v0.15.0

unNonEmptyString

Unwrap a NonEmptyString newtype back to its underlying string representation.

Signature

export declare const unNonEmptyString: (x: NonEmptyString) => string
unNonEmptyString :: NonEmptyString -> string

Added in v0.15.0

unsafeFromString

Unsafely lift a string to NonEmptyString, throwing upon failure. Can be useful for static values. Try to use fromString instead.

Signature

export declare const unsafeFromString: (x: string) => NonEmptyString
unsafeFromString :: string -> NonEmptyString

Added in v0.15.0