Skip to content

brainrake/purescript-strings

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

61 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Module Documentation

Module Data.Char

A type and functions for single characters.

Char

newtype Char

A unicode character.

charString

charString :: Char -> String

Returns the string of length 1 containing only the given character.

toCharCode

toCharCode :: Char -> Number

Returns the numeric Unicode value of the character.

fromCharCode

fromCharCode :: Number -> Char

Constructs a character from the given Unicode numeric value.

eqChar

instance eqChar :: Eq Char

Characters can be compared for equality with == and /=.

ordChar

instance ordChar :: Ord Char

Characters can be compared with compare, >, >=, < and <=.

showChar

instance showChar :: Show Char

Characters can be rendered as a string with show.

Module Data.String

Wraps the functions of Javascript's String object. A String represents a sequence of characters. For details of the underlying implementation, see String Reference at MDN.

charAt

charAt :: Number -> String -> Maybe Char

Returns the character at the given index, if the index is within bounds.

fromChar

fromChar :: Char -> String

Returns a string of length 1 containing the given character.

singleton

singleton :: Char -> String

Returns a string of length 1 containing the given character. Same as fromChar.

charCodeAt

charCodeAt :: Number -> String -> Maybe Number

Returns the numeric Unicode value of the character at the given index, if the index is within bounds.

null

null :: String -> Boolean

Returns true if the given string is empty.

uncons

uncons :: String -> Maybe { tail :: String, head :: Char }

Returns the first character and the rest of the string, if the string is not empty.

takeWhile

takeWhile :: (Char -> Boolean) -> String -> String

Returns the longest prefix (possibly empty) of characters that satisfy the predicate:

dropWhile

dropWhile :: (Char -> Boolean) -> String -> String

Returns the suffix remaining after takeWhile.

fromCharArray

fromCharArray :: [Char] -> String

Converts an array of characters into a string.

indexOf

indexOf :: String -> String -> Number

Returns the index of the first occurrence of the first string in the second string. Returns -1 if there is no match.

indexOf'

indexOf' :: String -> Number -> String -> Number

Returns the index of the first occurrence of the first string in the second string, starting at the given index. Returns -1 if there is no match.

lastIndexOf

lastIndexOf :: String -> String -> Number

Returns the index of the last occurrence of the first string in the second string. Returns -1 if there is no match.

lastIndexOf'

lastIndexOf' :: String -> Number -> String -> Number

Returns the index of the first occurrence of the last string in the second string, starting at the given index. Returns -1 if there is no match.

length

length :: String -> Number

Returns the number of characters the string is composed of.

localeCompare

localeCompare :: String -> String -> Number

Locale-aware sort order comparison. Returns a negative number if the first string occurs before the second in a sort, a positive number if the first string occurs after the second, and 0 if their sort order is equal.

replace

replace :: String -> String -> String -> String

Replaces the first occurence of the first argument with the second argument.

take

take :: Number -> String -> String

Returns the first n characters of the string.

drop

drop :: Number -> String -> String

Returns the string without the first n characters.

count

count :: (Char -> Boolean) -> String -> Number

Returns the number of characters in the string for which the predicate holds.

split

split :: String -> String -> [String]

Returns the substrings of the first string separated along occurences of the second string.

toCharArray

toCharArray :: String -> [Char]

Converts the string into an array of characters.

toLower

toLower :: String -> String

Returns the argument converted to lowercase.

toUpper

toUpper :: String -> String

Returns the argument converted to uppercase.

trim

trim :: String -> String

Removes whitespace from the beginning and end of a string, including whitespace characters and line terminators.

joinWith

joinWith :: String -> [String] -> String

Joins the strings in the array together, inserting the first argument as separator between them.

Module Data.String.Regex

Wraps Javascript's RegExp object that enables matching strings with patternes defined by regular expressions. For details of the underlying implementation, see RegExp Reference at MDN.

Regex

data Regex :: *

Wraps Javascript RegExp objects.

showRegex

instance showRegex :: Show Regex

RegexFlags

type RegexFlags = { unicode :: Boolean, sticky :: Boolean, multiline :: Boolean, ignoreCase :: Boolean, global :: Boolean }

Flags that control matching.

noFlags

noFlags :: RegexFlags

All flags set to false.

regex

regex :: String -> RegexFlags -> Regex

Constructs a Regex from a pattern string and flags.

source

source :: Regex -> String

Returns the pattern string used to construct the given Regex.

flags

flags :: Regex -> RegexFlags

Returns the RegexFlags used to construct the given Regex.

renderFlags

renderFlags :: RegexFlags -> String

Returns the string representation of the given RegexFlags.

parseFlags

parseFlags :: String -> RegexFlags

Parses the string representation of RegexFlags.

test

test :: Regex -> String -> Boolean

Returns true if the Regex matches the string.

match

match :: Regex -> String -> Maybe [String]

Matches the string against the Regex and returns an array of matches if there were any. See reference.

replace

replace :: Regex -> String -> String -> String

Replaces occurences of the Regex with the first string. The replacement string can include special replacement patterns escaped with "$". See reference.

replace'

replace' :: Regex -> (String -> [String] -> String) -> String -> String

Transforms occurences of the Regex using a function of the matched substring and a list of submatch strings. See the reference.

search

search :: Regex -> String -> Number

Returns the index of the first match of the Regex in the string, or -1 if there is no match.

split

split :: Regex -> String -> [String]

Split the string into an array of substrings along occurences of the Regex.

Module Data.String.Unsafe

Unsafe string and character functions.

charCodeAt

charCodeAt :: Number -> String -> Number

Returns the numeric Unicode value of the character at the given index.

Unsafe: returns NaN if the index is out of bounds.

charAt

charAt :: Number -> String -> Char

Returns the character at the given index.

Unsafe: returns an illegal value if the index is out of bounds.

About

String utility functions and regular expressions

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • PureScript 94.3%
  • JavaScript 5.7%