Liking cljdoc? Tell your friends :D

superstring.core


ascii?clj/s

(ascii? s)

Return s if s only contains ASCII characters.

Return s if s only contains ASCII characters.
source (clj)source (cljs)raw docstring

blank?clj/s≠

clj
(blank? s)

True if s is nil, empty, or contains only whitespace.

True if s is nil, empty, or contains only whitespace.
cljs
source (clj)source (cljs)raw docstring

camel-caseclj/s

(camel-case s)

Lower case the first char in s and use capitalization to separate words.

foo bar => fooBar camelCase => camelCase PascalCase => pascalCase

Lower case the first char in s and use capitalization to separate words.

foo bar => fooBar
camelCase => camelCase
PascalCase => pascalCase
source (clj)source (cljs)raw docstring

capitalizeclj/s≠

clj
(capitalize s)

Converts first character of the string to upper-case, all other characters to lower-case.

Converts first character of the string to upper-case, all other
characters to lower-case.
cljs
source (clj)source (cljs)raw docstring

centerclj/s

(center s width)
(center s width padding)

Pad both ends of s with padding, or spaces, until the length of s matches width.

Pad both ends of s with padding, or spaces, until the length of s
matches width.
source (clj)source (cljs)raw docstring

char-atclj/s

(char-at s i)

Get the character in s at index i.

Get the character in s at index i.
source (clj)source (cljs)raw docstring

chompclj/s

(chomp s)
(chomp s separator)

Return a new string with the given record separator removed from the end (if present).

If separator is not provided, chomp will remove \n, \r or \r\n from the end of s.

Return a new string with the given record separator removed from
the end (if present).

If separator is not provided, chomp will remove \n, \r or \r\n from
the end of s.
source (clj)source (cljs)raw docstring

chopclj/s

(chop s)

Return a new string with the last character removed.

If the string ends with \r\n, both characters are removed.

Applying chop to an empty string is a no-op.

chomp is often a safer alternative, as it leaves the string unchanged if it doesn’t end in a record separator.

Return a new string with the last character removed.

If the string ends with \r\n, both characters are removed.

Applying chop to an empty string is a no-op.

chomp is often a safer alternative, as it leaves the string
unchanged if it doesn’t end in a record separator.
source (clj)source (cljs)raw docstring

chop-prefixclj/s

(chop-prefix s prefix)
(chop-prefix s prefix ignore-case)

If found, remove prefix from the start of s.

Otherwise return s.

If found, remove prefix from the start of s.

Otherwise return s.
source (clj)source (cljs)raw docstring

chop-suffixclj/s

(chop-suffix s suffix)
(chop-suffix s suffix ignore-case)

If found, remove suffix from the end of s.

Otherwise return s.

If found, remove suffix from the end of s.

Otherwise return s.
source (clj)source (cljs)raw docstring

collapse-whitespaceclj/s

(collapse-whitespace s)

Convert all adjacent whitespace in s to a single space.

Convert all adjacent whitespace in s to a single space.
source (clj)source (cljs)raw docstring

common-prefixclj/s

(common-prefix s1 s2)
(common-prefix s1 s2 ignore-case)

Return the longest common prefix of s1 and s2.

(common-prefix "abadon" "aberdeen") => "ab" (common-prefix "foo" "bar") => ""

Return the longest common prefix of s1 and s2.

(common-prefix "abadon" "aberdeen") => "ab"
(common-prefix "foo" "bar") => ""
source (clj)source (cljs)raw docstring

common-suffixclj/s

(common-suffix s1 s2)
(common-suffix s1 s2 ignore-case)

Return the longest common suffix of s1 and s2.

(common-suffix "bba" "aba") => "ba" (common-suffix "foo" "bar") => ""

Return the longest common suffix of s1 and s2.

(common-suffix "bba" "aba") => "ba"
(common-suffix "foo" "bar") => ""
source (clj)source (cljs)raw docstring

distanceclj/s

(distance s1 s2)
(distance s1 s2 algorithm)

Get the edit distance between s1 and s2.

The default distance metric is the Levenshtein distance.

The optional algorithm argument can be either :levenshtein to get the default, or :hamming to get the Hamming distance between s1 and s2.

Get the edit distance between s1 and s2.

The default distance metric is the Levenshtein distance.

The optional algorithm argument can be either :levenshtein to get
the default, or :hamming to get the Hamming distance between s1 and
s2.
source (clj)source (cljs)raw docstring

ends-with?clj/s

(ends-with? s suffix)
(ends-with? s suffix ignore-case)

Return s if s ends with suffix.

If a third argument is provided the string comparison is insensitive to case.

Return s if s ends with suffix.

If a third argument is provided the string comparison is insensitive to case.
source (clj)source (cljs)raw docstring

escapeclj/s≠

clj
(escape s cmap)

Return a new string, using cmap to escape each character ch from s as follows:

If (cmap ch) is nil, append ch to the new string. If (cmap ch) is non-nil, append (str (cmap ch)) instead.

Return a new string, using cmap to escape each character ch
from s as follows:

If (cmap ch) is nil, append ch to the new string.
If (cmap ch) is non-nil, append (str (cmap ch)) instead.
cljs
source (clj)source (cljs)raw docstring

includes-all?clj/s

(includes-all? s needles)
(includes-all? s needles ignore-case)

Return s if s includes all needles.

(includes-all? "foo bar baz" ["foo" "bar"]) => "foo bar baz" (includes-all? "foo bar" ["qux" "bar"]) => nil

Return s if s includes all needles.

(includes-all? "foo bar baz" ["foo" "bar"]) => "foo bar baz"
(includes-all? "foo bar" ["qux" "bar"]) => nil
source (clj)source (cljs)raw docstring

includes-any?clj/s

(includes-any? s needles)
(includes-any? s needles ignore-case)

Return s if s includes any of the needles.

(includes-any? "foo bar baz" ["foo" "qux"]) => "foo bar baz" (includes-any? "foo bar" ["qux" "quux"]) => nil

Return s if s includes any of the needles.

(includes-any? "foo bar baz" ["foo" "qux"]) => "foo bar baz"
(includes-any? "foo bar" ["qux" "quux"]) => nil
source (clj)source (cljs)raw docstring

includes?clj/s

(includes? s needle)
(includes? s needle ignore-case)

Return s if s includes needle.

(includes? "foobar" "foo") => "foobar" (includes? "foobar" "qux") => nil

Return s if s includes needle.

(includes? "foobar" "foo") => "foobar"
(includes? "foobar" "qux") => nil
source (clj)source (cljs)raw docstring

index-ofclj/s≠

clj
(index-of s value)
(index-of s value from-index)

Return index of value (string or char) in s, optionally searching forward from from-index. Return nil if value not found.

Return index of value (string or char) in s, optionally searching
forward from from-index. Return nil if value not found.
cljs
source (clj)source (cljs)raw docstring

joinclj/s≠

clj
(join coll)
(join separator coll)

Returns a string of all elements in coll, as returned by (seq coll), separated by an optional separator.

Returns a string of all elements in coll, as returned by (seq coll),
separated by an optional separator.
cljs
source (clj)source (cljs)raw docstring

last-index-ofclj/s≠

clj
(last-index-of s value)
(last-index-of s value from-index)

Return last index of value (string or char) in s, optionally searching backward from from-index. Return nil if value not found.

Return last index of value (string or char) in s, optionally
searching backward from from-index. Return nil if value not found.
cljs
source (clj)source (cljs)raw docstring

lengthclj/s

(length s)

Return the length of s.

Return the length of s.
source (clj)source (cljs)raw docstring

lisp-caseclj/s

(lisp-case s)

Lower case s and separate words with dashes.

foo bar => foo-bar camelCase => camel-case

This is also referred to as kebab-case in some circles.

Lower case s and separate words with dashes.

foo bar => foo-bar
camelCase => camel-case

This is also referred to as kebab-case in some circles.
source (clj)source (cljs)raw docstring

longest-common-substringclj/s

(longest-common-substring s1 s2)

Returns the set of the longest common substrings in s1 and s2.

This implementation uses dynamic programming, and not a generalized suffix tree, so the runtime is O(nm).

Returns the set of the longest common substrings in s1 and s2.

This implementation uses dynamic programming, and not a generalized
suffix tree, so the runtime is O(nm).
source (clj)source (cljs)raw docstring

lower-caseclj/s≠

clj
(lower-case s)

Converts string to all lower-case.

Converts string to all lower-case.
cljs
source (clj)source (cljs)raw docstring

lower-case?clj/s

(lower-case? s)

Return s if s is all lower case.

Characters without case, e.g. numbers, are considered to be trivially lower case.

Return s if s is all lower case.

Characters without case, e.g. numbers, are considered to be trivially
lower case.
source (clj)source (cljs)raw docstring

mixed-case?clj/s

(mixed-case? s)

Return s if s contains both upper and lower case letters.

(mixed-case? "foo1") => nil (mixed-case? "Foo Bar") => "Foo Bar"

Return s if s contains both upper and lower case letters.

(mixed-case? "foo1") => nil
(mixed-case? "Foo Bar") => "Foo Bar"
source (clj)source (cljs)raw docstring

pad-leftclj/s

(pad-left s width)
(pad-left s width padding)

Pad the beginning of s with padding, or spaces, until the length of s matches width.

Pad the beginning of s with padding, or spaces, until the length of
s matches width.
source (clj)source (cljs)raw docstring

pad-rightclj/s

(pad-right s width)
(pad-right s width padding)

Pad the end of s with padding, or spaces, until the length of s matches width.

Pad the end of s with padding, or spaces, until the length of s matches
width.
source (clj)source (cljs)raw docstring

pascal-caseclj/s≠

(pascal-case s)
clj

Upper the case first char in s and use capitalization to separate words.

foo bar => FooBar camelCase => CamelCase PascalCase => PascalCase

Upper the case first char in s and use capitalization to separate words.

foo bar => FooBar
camelCase => CamelCase
PascalCase => PascalCase
cljs

Upper case the first char in s and use capitalization to separate words.

foo bar => FooBar camelCase => CamelCase PascalCase => PascalCase

Upper case the first char in s and use capitalization to separate words.

foo bar => FooBar
camelCase => CamelCase
PascalCase => PascalCase
source (clj)source (cljs)raw docstring

re-quoteclj/s≠

(re-quote s)
clj

Create a string matching s exactly, and nothing else, for use in regular expressions.

Create a string matching s exactly, and nothing else, for use in
regular expressions.
cljs

Return a string matching s exactly, and nothing else, for use in regular expressions.

Return a string matching s exactly, and nothing else, for use in
regular expressions.
source (clj)source (cljs)raw docstring

re-quote-replacementclj

(re-quote-replacement replacement)

Given a replacement string that you wish to be a literal replacement for a pattern match in replace or replace-first, do the necessary escaping of special characters in the replacement.

Given a replacement string that you wish to be a literal
replacement for a pattern match in replace or replace-first, do the
necessary escaping of special characters in the replacement.
sourceraw docstring

replaceclj/s≠

clj
(replace s match replacement)

Replaces all instance of match with replacement in s.

match/replacement can be:

string / string char / char pattern / (string or function of match).

See also replace-first.

The replacement is literal (i.e. none of its characters are treated specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are substituted with the string that matched the corresponding parenthesized group in the pattern. If you wish your replacement string r to be used literally, use (re-quote-replacement r) as the replacement argument. See also documentation for java.util.regex.Matcher's appendReplacement method.

Example: (clojure.string/replace "Almost Pig Latin" #"\b(\w)(\w+)\b" "$2$1ay") -> "lmostAay igPay atinLay"

Replaces all instance of match with replacement in s.

match/replacement can be:

string / string
char / char
pattern / (string or function of match).

See also replace-first.

The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.  If you wish your replacement
string r to be used literally, use (re-quote-replacement r) as the
replacement argument.  See also documentation for
java.util.regex.Matcher's appendReplacement method.

Example:
(clojure.string/replace "Almost Pig Latin" #"\b(\w)(\w+)\b" "$2$1ay")
-> "lmostAay igPay atinLay"
cljs
source (clj)source (cljs)raw docstring

replace-firstclj/s≠

clj
(replace-first s match replacement)

Replaces the first instance of match with replacement in s.

match/replacement can be:

char / char string / string pattern / (string or function of match).

See also replace.

The replacement is literal (i.e. none of its characters are treated specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are substituted with the string that matched the corresponding parenthesized group in the pattern. If you wish your replacement string r to be used literally, use (re-quote-replacement r) as the replacement argument. See also documentation for java.util.regex.Matcher's appendReplacement method.

Example: (clojure.string/replace-first "swap first two words" #"(\w+)(\s+)(\w+)" "$3$2$1") -> "first swap two words"

Replaces the first instance of match with replacement in s.

match/replacement can be:

char / char
string / string
pattern / (string or function of match).

See also replace.

The replacement is literal (i.e. none of its characters are treated
specially) for all cases above except pattern / string.

For pattern / string, $1, $2, etc. in the replacement string are
substituted with the string that matched the corresponding
parenthesized group in the pattern.  If you wish your replacement
string r to be used literally, use (re-quote-replacement r) as the
replacement argument.  See also documentation for
java.util.regex.Matcher's appendReplacement method.

Example:
(clojure.string/replace-first "swap first two words"
                              #"(\w+)(\s+)(\w+)" "$3$2$1")
-> "first swap two words"
cljs
source (clj)source (cljs)raw docstring

replace-lastclj/s

(replace-last s match replacement)

Like replace-first, but replaces the last occurrence instead of the first.

Like `replace-first`, but replaces the last occurrence instead of the first.
source (clj)source (cljs)raw docstring

reverseclj/s≠

clj
(reverse s)

Returns s with its characters reversed.

Returns s with its characters reversed.
cljs
source (clj)source (cljs)raw docstring

screaming-snake-caseclj/s

(screaming-snake-case s)

Upper case s and use underscores to separate words.

foo bar => FOO_BAR camelCase => CAMEL_CASE PascalCase => PASCAL_CASE

Upper case s and use underscores to separate words.

foo bar => FOO_BAR
camelCase => CAMEL_CASE
PascalCase => PASCAL_CASE
source (clj)source (cljs)raw docstring

sliceclj/s≠

(slice s index)
(slice s index length)
clj

Return a slice of s beginning at index and of the given length, or 1.

If index is negative, the starting index is relative to the end of the string.

If the requested slice ends outside the string boundaries, we return the substring of s starting at index.

Returns nil if index falls outside the string boundaries or if length is negative.

Return a slice of s beginning at index and of the given length, or 1.

If index is negative, the starting index is relative to the end of the string.

If the requested slice ends outside the string boundaries, we return
the substring of s starting at index.

Returns nil if index falls outside the string boundaries or if
length is negative.
cljs

Return a slice of s beginning at index and of the given length, or 1.

If index is negative the starting index is relative to the end of the string.

If the requested slice ends outside the string boundaries, we return the substring of s starting at index.

Returns nil if index falls outside the string boundaries or if length is negative.

Return a slice of s beginning at index and of the given length, or 1.

If index is negative the starting index is relative to the end of the string.

If the requested slice ends outside the string boundaries, we return
the substring of s starting at index.

Returns nil if index falls outside the string boundaries or if
length is negative.
source (clj)source (cljs)raw docstring

slugclj/s

(slug s)

Transform s so it's suitable for use in URLs.

The following transformations are applied:

  • Diacritical marks are removed from all characters.
  • Any character which isn't alphanumeric or in #{_-.~} is removed.
  • Lower case
  • Whitespace is collapsed and replaced by a single dash.
Transform s so it's suitable for use in URLs.

The following transformations are applied:

* Diacritical marks are removed from all characters.
* Any character which isn't alphanumeric or in #{_-.~} is removed.
* Lower case
* Whitespace is collapsed and replaced by a single dash.
source (clj)source (cljs)raw docstring

snake-caseclj/s

(snake-case s)

Lower case s and use underscores to separate words.

foo bar => foo_bar camelCase => camel_case PascalCase => pascal_case

Lower case s and use underscores to separate words.

foo bar => foo_bar
camelCase => camel_case
PascalCase => pascal_case
source (clj)source (cljs)raw docstring

some?clj/s

(some? s)

Complement of blank?

Complement of `blank?`
source (clj)source (cljs)raw docstring

splitclj/s≠

clj
(split s re)
(split s re limit)

Splits string on a regular expression. Optional argument limit is the maximum number of splits. Not lazy. Returns vector of the splits.

Splits string on a regular expression.  Optional argument limit is
the maximum number of splits. Not lazy. Returns vector of the splits.
cljs
source (clj)source (cljs)raw docstring

split-linesclj/s≠

clj
(split-lines s)

Splits s on \n or \r\n.

Splits s on \n or \r\n.
cljs
source (clj)source (cljs)raw docstring

starts-with?clj/s

(starts-with? s prefix)
(starts-with? s prefix ignore-case)

Return s if s starts with prefix.

If a third argument is provided the string comparison is insensitive to case.

Return s if s starts with prefix.

If a third argument is provided the string comparison is insensitive to case.
source (clj)source (cljs)raw docstring

strip-accentsclj/s

(strip-accents s)

Strip all accents (diacritical marks) from s.

Et ça sera sa moitié => Et ca sera sa moitie

Strip all accents (diacritical marks) from s.

Et ça sera sa moitié => Et ca sera sa moitie
source (clj)source (cljs)raw docstring

substringclj/s≠

clj
(substring s start)
(substring s start end)

Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), exclusive.

Returns the substring of s beginning at start inclusive, and ending
at end (defaults to length of string), exclusive.
cljs
source (clj)source (cljs)raw docstring

swap-caseclj/s

(swap-case s)

Change lower case characters to upper case and vice versa.

Change lower case characters to upper case and vice versa.
source (clj)source (cljs)raw docstring

translateclj/s≠

(translate s tmap)
(translate s tmap delete-chars)
clj

Translate all characters in s according to the mappings found in tmap.

Any characters found in the set delete-chars will be pruned prior to consulting tmap.

Any characters mapping to nil in tmap will also be deleted.

(translate "abba" {\a \b}) => bbbb (translate "abba" {\a \b, \b \a}) => baab (translate "foo" {\a }) => foo (translate "gabba" {\a \b} #{\b}) => gbb (translate "gabba" {\a nil} #{\b}) => g

Translate all characters in s according to the mappings found in tmap.

Any characters found in the set delete-chars will be pruned prior to
consulting tmap.

Any characters mapping to nil in tmap will also be deleted.

(translate "abba" {\a \b}) => bbbb
(translate "abba" {\a \b, \b \a}) => baab
(translate "foo" {\a }) =>  foo
(translate "gabba" {\a \b} #{\b}) => gbb
(translate "gabba" {\a nil} #{\b}) => g
cljs

Translate all characters in s according to the mappings found in tmap.

Any characters found in the set delete-chars will be pruned prior to consulting tmap.

Any characters mapping to nil in tmap will also be deleted.

(translate "abba" {"a" "b"}) => bbbb (translate "abba" {"a" "b", "b" "a"}) => baab (translate "foo" {"a" "b"}) => foo (translate "gabba" {"a" "b"} #{"b"}) => gbb (translate "gabba" {\a nil} #{\b}) => g

Translate all characters in s according to the mappings found in tmap.

Any characters found in the set delete-chars will be pruned prior to
consulting tmap.

Any characters mapping to nil in tmap will also be deleted.

(translate "abba" {"a" "b"}) => bbbb
(translate "abba" {"a" "b", "b" "a"}) => baab
(translate "foo" {"a" "b"}) =>  foo
(translate "gabba" {"a" "b"} #{"b"}) => gbb
(translate "gabba" {\a nil} #{\b}) => g
source (clj)source (cljs)raw docstring

trimclj/s≠

clj
(trim s)

Removes whitespace from both ends of string.

Removes whitespace from both ends of string.
cljs
source (clj)source (cljs)raw docstring

trim-newlineclj/s≠

clj
(trim-newline s)

Removes all trailing newline \n or return \r characters from string. Similar to Perl's chomp.

Removes all trailing newline \n or return \r characters from
string.  Similar to Perl's chomp.
cljs
source (clj)source (cljs)raw docstring

trimlclj/s≠

clj
(triml s)

Removes whitespace from the left side of string.

Removes whitespace from the left side of string.
cljs
source (clj)source (cljs)raw docstring

trimrclj/s≠

clj
(trimr s)

Removes whitespace from the right side of string.

Removes whitespace from the right side of string.
cljs
source (clj)source (cljs)raw docstring

truncateclj/s

(truncate s len)

If s is longer than len-3, cut it down to len-3 and append '...'.

If s is longer than len-3, cut it down to len-3 and append '...'.
source (clj)source (cljs)raw docstring

upper-caseclj/s≠

clj
(upper-case s)

Converts string to all upper-case.

Converts string to all upper-case.
cljs
source (clj)source (cljs)raw docstring

upper-case?clj/s

(upper-case? s)

Return s if s is all upper case.

Characters without case, e.g. numbers, are considered to be trivially upper case.

Return s if s is all upper case.

Characters without case, e.g. numbers, are considered to be trivially
upper case.
source (clj)source (cljs)raw docstring

wrap-wordsclj/s

(wrap-words s width)

Insert newlines in s so the length of each line doesn't exceed width.

Insert newlines in s so the length of each line doesn't exceed width.
source (clj)source (cljs)raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close