Skip to main content Link Search Menu Expand Document (external link)

String overview

A simple extension to the Effect String module


Table of contents


Constructors

fromNonNullablePrimitive

Builds a string from a primitive value other than null and undefined.

Signature

export declare const fromNonNullablePrimitive: (u: MTypes.NonNullablePrimitive) => string

fromNumber

Builds a string from a number using the passed radix.

Signature

export declare const fromNumber: (radix?: number) => (u: number) => string

fromPrimitive

Builds a string from a primitive value. null is converted to the string “null” and undefined to the string “undefined”

Signature

export declare const fromPrimitive: MTypes.OneArgFunction<MTypes.Primitive, string>

Destructors

matchAndGroups

Same as match but also returns capturing groups.

Signature

export declare const matchAndGroups: (regExp: RegExp) => (self: string) => Option.Option<RegExpExecArray>

Models

SearchResult (namespace)

This namespace implements a type that represents the result of the search of a string in another string.

Type (interface)

Interface that represents a SearchResult

Signature

export interface Type extends Equal.Equal, Inspectable.Inspectable, Pipeable.Pipeable {
  /** The index where the match was found in the target string */
  readonly startIndex: number
  /** The index of the character following the match in the target string */
  readonly endIndex: number
  /** The match */
  readonly match: string
  /** @internal */
  readonly [_TypeId]: _TypeId
}

moduleTag

Module tag

Signature

export declare const moduleTag: "@parischap/effect-lib/String/"

Predicates

hasLength

Returns true if the length of self is l

Signature

export declare const hasLength: (l: number) => (self: string) => boolean

isEmail

Returns true if self is an email

Signature

export declare const isEmail: (self: string) => boolean

isSemVer

Returns true if self is a SemVer

Signature

export declare const isSemVer: (self: string) => boolean

Utils

append

Appends s to self

Signature

export declare const append: (s: string) => (self: string) => string

count

Returns the number of occurences of regexp in self

Signature

export declare const count: (regexp: RegExp | string) => (self: string) => number

isMultiLine

Returns true if self contains an eol character

Signature

export declare const isMultiLine: (self: string) => boolean

match

A slightly different version of match using RegExp.prototype.exec instead of String.prototype.match. This function will always return only the first match, even if the g flag is set. Good to use in a library when you have no control over the RegExp you receive.

Signature

export declare const match: (regExp: RegExp) => (self: string) => Option.Option<string>

prepend

Prepends s to self

Signature

export declare const prepend: (s: string) => (self: string) => string

replaceBetween

Replaces the part of self between startIndex included and endIndex excluded by replacement. If startIndex equals endIndex, replacement is inserted at startIndex. If startIndex is strictly greater than endIndex, the part between endIndex and startIndex will be present before and after the replacement. If startIndex is strictly less than 0, it is taken equal to 0. Same for endIndex. If startIndex or strisctly superior to the length of self, it is taken equal to the length of self. Same

Signature

export declare const replaceBetween: (
  replacement: string,
  startIndex: number,
  endIndex: number
) => (self: string) => string

Searches for the first occurence of regexp in self and returns a SearchResult. You can optionnally provide the index from which to start searching. ‘g’ flag needs not be set if you pass a regular expression. As opposed to String.search, regexp special characters need not be escaped when passing a string regexp

Signature

export declare const search: (
  regexp: RegExp | string,
  startIndex?: number
) => (self: string) => Option.Option<SearchResult.Type>

searchAll

Searches for all occurences of regexp in self and returns an array of SearchResults. ‘g’ flag needs not be set if you pass a regular expression.

Signature

export declare const searchAll: (regexp: RegExp | string) => (self: string) => Array<SearchResult.Type>

searchRight

Searches for the last occurence of regexp in self and returns a SearchResult. ‘g’ flag needs not be set if you pass a regular expression.

Signature

export declare const searchRight: (regexp: RegExp | string) => (self: string) => Option.Option<SearchResult.Type>

splitAt

Splits self in two parts at position n. The length of the first string is n (characters 0 to n-1). If n is strictly less than 0, it is taken equal to 0. If n is greater than the length of self, it is taken equal to the length of self.

Signature

export declare const splitAt: (n: number) => (self: string) => [left: string, right: string]

splitAtFromRight

Splits self in two parts at position n from the end of self. The length of the second string is n. If n is strictly less than 0, it is taken equal to 0. If n is greater than the length of self, it is taken equal to the length of self.

Signature

export declare const splitAtFromRight: (n: number) => (self: string) => [left: string, right: string]

splitEquallyRestAtEnd

Splits self in substrings of bitSize characters. The length of the last string, if any, is comprised between 1 and bitSize characters. bitSize must be a strictly positive integer.

Signature

export declare const splitEquallyRestAtEnd: (bitSize: number) => MTypes.OneArgFunction<string, MTypes.OverOne<string>>

splitEquallyRestAtStart

Splits self in substrings of bitSize characters. The length of the first string, if any, is comprised between 1 and bitSize characters. bitSize must be a strictly positive integer.

Signature

export declare const splitEquallyRestAtStart: (bitSize: number) => MTypes.OneArgFunction<string, Array<string>>

stripLeft

If self starts with s, returns self stripped of s. Otherwise, returns self

Signature

export declare const stripLeft: (s: string) => (self: string) => string

stripLeftOption

If self starts with s, returns a some of self stripped of s. Otherwise, returns a none

Signature

export declare const stripLeftOption: (s: string) => (self: string) => Option.Option<string>

stripRight

If self ends with s, returns self stripped of s. Otherwise, returns self

Signature

export declare const stripRight: (s: string) => (self: string) => string

stripRightOption

If self ends with s, returns a some of self stripped of s. Otherwise, returns a none

Signature

export declare const stripRightOption: (s: string) => (self: string) => Option.Option<string>

tabify

Adds string tabChar count times at the beginning of each new line of self

Signature

export declare const tabify: (tabChar: string, count?: number) => (self: string) => string

takeLeftBut

Takes all characters from self except the n last characters

Signature

export declare const takeLeftBut: (n: number) => (self: string) => string

takeLeftTo

Looks from the left for the first substring of self that matches regexp and returns all characters before that substring. If no occurence is found, returns self. ‘g’ flag has no incidence if you pass a regular expression.

Signature

export declare const takeLeftTo: (regexp: RegExp | string) => (self: string) => string

takeRightBut

Takes all characters from self except the n first characters

Signature

export declare const takeRightBut: (n: number) => (self: string) => string

takeRightFrom

Looks from the right for the first substring of self that matches regexp and returns all characters after that substring. If no occurence is found, returns self. ‘g’ flag needs not be set if you pass a regular expression.

Signature

export declare const takeRightFrom: (regexp: RegExp | string) => (self: string) => string

trimEnd

Same as String.trimEnd but the character to remove can be specified

Signature

export declare const trimEnd: (charToRemove: string) => (self: string) => string

trimStart

Same as String.trimStart but the character to remove can be specified

Signature

export declare const trimStart: (charToRemove: string) => (self: string) => string