(ascii? s)
Return s if s only contains ASCII characters.
Return s if s only contains ASCII characters.
(blank? s)
True if s is nil, empty, or contains only whitespace.
True if s is nil, empty, or contains only whitespace.
(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
(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.
(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.
(char-at s i)
Get the character in s at index i.
Get the character in s at index i.
(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.
(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.
(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.
(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.
(collapse-whitespace s)
Convert all adjacent whitespace in s to a single space.
Convert all adjacent whitespace in s to a single space.
(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") => ""
(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") => ""
(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.
(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.
(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.
(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
(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
(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
(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.
(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.
(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.
(length s)
Return the length of s.
Return the length of 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.
(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).
(lower-case s)
Converts string to all lower-case.
Converts string to all lower-case.
(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.
(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"
(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.
(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.
(pascal-case s)
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
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
(re-quote s)
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.
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.
(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.
(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"
(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"
(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.
(reverse s)
Returns s with its characters reversed.
Returns s with its characters reversed.
(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
(slice s index)
(slice s index length)
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.
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.
(slug s)
Transform s so it's suitable for use in URLs.
The following transformations are applied:
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.
(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
(some? s)
Complement of blank?
Complement of `blank?`
(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.
(split-lines s)
Splits s on \n or \r\n.
Splits s on \n or \r\n.
(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.
(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
(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.
(swap-case s)
Change lower case characters to upper case and vice versa.
Change lower case characters to upper case and vice versa.
(translate s tmap)
(translate s tmap delete-chars)
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
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
(trim s)
Removes whitespace from both ends of string.
Removes whitespace from both ends of string.
(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.
(triml s)
Removes whitespace from the left side of string.
Removes whitespace from the left side of string.
(trimr s)
Removes whitespace from the right side of string.
Removes whitespace from the right side of string.
(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 '...'.
(upper-case s)
Converts string to all upper-case.
Converts string to all upper-case.
(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.
(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.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close