CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pydash

A comprehensive Python utility library for functional programming inspired by JavaScript's Lo-Dash

Pending
Overview
Eval results
Files

strings.mddocs/

Strings Module

The Strings module provides 69 functions for comprehensive string manipulation and formatting. These functions cover case conversion, padding, trimming, searching, transformation, and various string utilities.

Case Conversion Functions

camel_case

def camel_case(text: Any) -> str

Converts text to camelCase.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in camelCase.

Example:

from pydash import camel_case

camel_case('Foo Bar')
# 'fooBar'

camel_case('--foo-bar--')
# 'fooBar'

camel_case('__FOO_BAR__')
# 'fooBar'

kebab_case

def kebab_case(text: Any) -> str

Converts text to kebab-case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in kebab-case.

Example:

from pydash import kebab_case

kebab_case('Foo Bar')
# 'foo-bar'

kebab_case('fooBar')
# 'foo-bar'

kebab_case('__FOO_BAR__')
# 'foo-bar'

snake_case

def snake_case(text: Any) -> str

Converts text to snake_case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in snake_case.

Example:

from pydash import snake_case

snake_case('Foo Bar')
# 'foo_bar'

snake_case('fooBar')
# 'foo_bar'

snake_case('--FOO-BAR--')
# 'foo_bar'

pascal_case

def pascal_case(text: Any, strict: bool = True) -> str

Converts text to PascalCase.

Parameters:

  • text (Any): String to convert.
  • strict (bool): Whether to force strict camel case. Defaults to True.

Returns:

  • str: String in PascalCase.

Example:

from pydash import pascal_case

pascal_case('foo bar')
# 'FooBar'

pascal_case('--foo-bar--')
# 'FooBar'

pascal_case('fooBar')
# 'FooBar'

start_case

def start_case(text: Any) -> str

Converts text to Start Case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in Start Case.

Example:

from pydash import start_case

start_case('--foo-bar--')
# 'Foo Bar'

start_case('fooBar')
# 'Foo Bar'

start_case('__FOO_BAR__')
# 'FOO BAR'

lower_case

def lower_case(text: Any) -> str

Converts text, as space separated words, to lower case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in lower case with spaces.

Example:

from pydash import lower_case

lower_case('--Foo-Bar--')
# 'foo bar'

lower_case('fooBar')
# 'foo bar'

lower_case('__FOO_BAR__')
# 'foo bar'

upper_case

def upper_case(text: Any) -> str

Converts text, as space separated words, to upper case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in upper case with spaces.

Example:

from pydash import upper_case

upper_case('--foo-bar--')
# 'FOO BAR'

upper_case('fooBar')
# 'FOO BAR'

upper_case('__foo_bar__')
# 'FOO BAR'

title_case

def title_case(text: Any) -> str

Converts text to Title Case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in Title Case.

Example:

from pydash import title_case

title_case('--foo-bar--')
# 'Foo Bar'

title_case('fooBar')
# 'Foo Bar'

human_case

def human_case(text: Any) -> str

Converts text to human readable form by replacing dashes, underscores, and camel case with spaces.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: String in human readable form.

Example:

from pydash import human_case

human_case('--foo-bar--')
# 'Foo bar'

human_case('fooBar')
# 'Foo bar'

capitalize

def capitalize(text: Any, strict: bool = True) -> str

Converts the first character of text to upper case and the remaining to lower case.

Parameters:

  • text (Any): String to capitalize.
  • strict (bool): Whether to cast rest of string to lower case. Defaults to True.

Returns:

  • str: Capitalized string.

Example:

from pydash import capitalize

capitalize('FRED')
# 'Fred'

capitalize('fRED', False)
# 'FRED'

decapitalize

def decapitalize(text: Any) -> str

Converts the first character of text to lower case.

Parameters:

  • text (Any): String to decapitalize.

Returns:

  • str: Decapitalized string.

Example:

from pydash import decapitalize

decapitalize('Fred')
# 'fred'

decapitalize('FRED')
# 'fRED'

lower_first

def lower_first(text: str) -> str

Converts the first character of text to lower case.

Parameters:

  • text (str): String to convert.

Returns:

  • str: Converted string.

Example:

from pydash import lower_first

lower_first('Fred')
# 'fred'

lower_first('FRED')
# 'fRED'

upper_first

def upper_first(text: str) -> str

Converts the first character of text to upper case.

Parameters:

  • text (str): String to convert.

Returns:

  • str: Converted string.

Example:

from pydash import upper_first

upper_first('fred')
# 'Fred'

upper_first('FRED')
# 'FRED'

swap_case

def swap_case(text: Any) -> str

Swaps the case of each character in text.

Parameters:

  • text (Any): String to swap case.

Returns:

  • str: String with swapped case.

Example:

from pydash import swap_case

swap_case('Hello World')
# 'hELLO wORLD'

to_lower

def to_lower(text: Any) -> str

Converts text to lower case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: Lower case string.

Example:

from pydash import to_lower

to_lower('--Foo-Bar--')
# '--foo-bar--'

to_lower('fooBar')
# 'foobar'

to_upper

def to_upper(text: Any) -> str

Converts text to upper case.

Parameters:

  • text (Any): String to convert.

Returns:

  • str: Upper case string.

Example:

from pydash import to_upper

to_upper('--foo-bar--')
# '--FOO-BAR--'

to_upper('fooBar')
# 'FOOBAR'

String Padding and Alignment

pad

def pad(text: Any, length: int, chars: Any = ' ') -> str

Pads text on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.

Parameters:

  • text (Any): String to pad.
  • length (int): Padding length.
  • chars (Any): String used as padding. Defaults to ' '.

Returns:

  • str: Padded string.

Example:

from pydash import pad

pad('abc', 8)
# '  abc   '

pad('abc', 8, '_-')
# '_-abc_-_'

pad('abc', 3)
# 'abc'

pad_end

def pad_end(text: Any, length: int, chars: Any = ' ') -> str

Pads text on the right side if it's shorter than length.

Parameters:

  • text (Any): String to pad.
  • length (int): Padding length.
  • chars (Any): String used as padding. Defaults to ' '.

Returns:

  • str: Right padded string.

Example:

from pydash import pad_end

pad_end('abc', 6)
# 'abc   '

pad_end('abc', 6, '_-')
# 'abc_-_'

pad_start

def pad_start(text: Any, length: int, chars: Any = ' ') -> str

Pads text on the left side if it's shorter than length.

Parameters:

  • text (Any): String to pad.
  • length (int): Padding length.
  • chars (Any): String used as padding. Defaults to ' '.

Returns:

  • str: Left padded string.

Example:

from pydash import pad_start

pad_start('abc', 6)
# '   abc'

pad_start('abc', 6, '_-')
# '_-_abc'

String Trimming Functions

trim

def trim(text: Any, chars: Any = None) -> str

Removes leading and trailing whitespace or specified characters from text.

Parameters:

  • text (Any): String to trim.
  • chars (Any, optional): Characters to trim.

Returns:

  • str: Trimmed string.

Example:

from pydash import trim

trim('  abc  ')
# 'abc'

trim('-_-abc-_-', '_-')
# 'abc'

trim_end

def trim_end(text: Any, chars: Any = None) -> str

Removes trailing whitespace or specified characters from text.

Parameters:

  • text (Any): String to trim.
  • chars (Any, optional): Characters to trim.

Returns:

  • str: Trimmed string.

Example:

from pydash import trim_end

trim_end('  abc  ')
# '  abc'

trim_end('-_-abc-_-', '_-')
# '-_-abc'

trim_start

def trim_start(text: Any, chars: Any = None) -> str

Removes leading whitespace or specified characters from text.

Parameters:

  • text (Any): String to trim.
  • chars (Any, optional): Characters to trim.

Returns:

  • str: Trimmed string.

Example:

from pydash import trim_start

trim_start('  abc  ')
# 'abc  '

trim_start('-_-abc-_-', '_-')
# 'abc-_-'

String Search and Test Functions

starts_with

def starts_with(text: Any, target: Any, position: int = 0) -> bool

Checks if text starts with the given target string.

Parameters:

  • text (Any): String to inspect.
  • target (Any): String to search for.
  • position (int): Position to search from. Defaults to 0.

Returns:

  • bool: Whether text starts with target.

Example:

from pydash import starts_with

starts_with('abc', 'a')
# True

starts_with('abc', 'b')
# False

starts_with('abc', 'b', 1)
# True

ends_with

def ends_with(text: Any, target: Any, position: Union[int, None] = None) -> bool

Checks if text ends with the given target string.

Parameters:

  • text (Any): String to inspect.
  • target (Any): String to search for.
  • position (Union[int, None]): Position to search up to.

Returns:

  • bool: Whether text ends with target.

Example:

from pydash import ends_with

ends_with('abc', 'c')
# True

ends_with('abc', 'b')
# False

ends_with('abc', 'b', 2)
# True

has_substr

def has_substr(text: Any, subtext: Any) -> bool

Checks if text contains subtext.

Parameters:

  • text (Any): String to inspect.
  • subtext (Any): String to search for.

Returns:

  • bool: Whether text contains subtext.

Example:

from pydash import has_substr

has_substr('hello world', 'world')
# True

has_substr('hello world', 'foo')
# False

count_substr

def count_substr(text: Any, subtext: Any) -> int

Counts the number of non-overlapping occurrences of subtext in text.

Parameters:

  • text (Any): String to inspect.
  • subtext (Any): String to search for.

Returns:

  • int: Number of occurrences.

Example:

from pydash import count_substr

count_substr('hello world world', 'world')
# 2

count_substr('aaa', 'aa')
# 1

String Manipulation Functions

chop

def chop(text: Any, step: int) -> List[str]

Break up text into a list of strings of length step.

Parameters:

  • text (Any): String to chop.
  • step (int): Length of each chunk.

Returns:

  • List[str]: List of chopped strings.

Example:

from pydash import chop

chop('abcdefg', 3)
# ['abc', 'def', 'g']

chop_right

def chop_right(text: Any, step: int) -> List[str]

Like chop except that it starts from the right.

Parameters:

  • text (Any): String to chop.
  • step (int): Length of each chunk.

Returns:

  • List[str]: List of chopped strings.

Example:

from pydash import chop_right

chop_right('abcdefg', 3)
# ['a', 'bcd', 'efg']

chars

def chars(text: Any) -> List[str]

Split text into a list of single characters.

Parameters:

  • text (Any): String to split into characters.

Returns:

  • List[str]: List of single characters.

Example:

from pydash import chars

chars('abc')
# ['a', 'b', 'c']

clean

def clean(text: Any) -> str

Trim text and replace multiple consecutive whitespace with a single space.

Parameters:

  • text (Any): String to clean.

Returns:

  • str: Cleaned string.

Example:

from pydash import clean

clean('  hello    world  ')
# 'hello world'

lines

def lines(text: Any) -> List[str]

Split text by line breaks and return list of lines.

Parameters:

  • text (Any): String to split.

Returns:

  • List[str]: List of lines.

Example:

from pydash import lines

lines('a\nb\r\nc')
# ['a', 'b', 'c']

words

def words(text: Any, pattern: Any = None) -> List[str]

Split text into a list of words.

Parameters:

  • text (Any): String to split into words.
  • pattern (Any, optional): Pattern to use for splitting.

Returns:

  • List[str]: List of words.

Example:

from pydash import words

words('fred, barney, & pebbles')
# ['fred', 'barney', 'pebbles']

words('fred, barney, & pebbles', r'[^, ]+')
# ['fred', 'barney', '&', 'pebbles']

split

def split(text: Any, separator: Any = None, limit: Union[int, None] = None) -> List[str]

Split text by separator. If limit is specified, the resulting list will have at most limit elements.

Parameters:

  • text (Any): String to split.
  • separator (Any, optional): Separator to split by.
  • limit (Union[int, None]): Maximum number of splits.

Returns:

  • List[str]: List of split strings.

Example:

from pydash import split

split('a-b-c', '-')
# ['a', 'b', 'c']

split('a-b-c', '-', 2)
# ['a', 'b-c']

String Prefix/Suffix Operations

ensure_starts_with

def ensure_starts_with(text: Any, prefix: Any) -> str

If text does not start with prefix, append prefix to the beginning of text.

Parameters:

  • text (Any): String to check.
  • prefix (Any): Prefix to ensure.

Returns:

  • str: String that starts with prefix.

Example:

from pydash import ensure_starts_with

ensure_starts_with('foobar', 'foo')
# 'foobar'

ensure_starts_with('bar', 'foo')
# 'foobar'

ensure_ends_with

def ensure_ends_with(text: Any, suffix: Any) -> str

If text does not end with suffix, append suffix to text.

Parameters:

  • text (Any): String to check.
  • suffix (Any): Suffix to ensure.

Returns:

  • str: String that ends with suffix.

Example:

from pydash import ensure_ends_with

ensure_ends_with('foobar', 'bar')
# 'foobar'

ensure_ends_with('foo', 'bar')
# 'foobar'

replace_start

def replace_start(text: Any, target: Any, replacement: Any) -> str

Replace target with replacement if text starts with target.

Parameters:

  • text (Any): String to modify.
  • target (Any): String to replace.
  • replacement (Any): Replacement string.

Returns:

  • str: Modified string.

Example:

from pydash import replace_start

replace_start('foobar', 'foo', 'baz')
# 'bazbar'

replace_start('foobar', 'qux', 'baz')
# 'foobar'

replace_end

def replace_end(text: Any, target: Any, replacement: Any) -> str

Replace target with replacement if text ends with target.

Parameters:

  • text (Any): String to modify.
  • target (Any): String to replace.
  • replacement (Any): Replacement string.

Returns:

  • str: Modified string.

Example:

from pydash import replace_end

replace_end('foobar', 'bar', 'baz')
# 'foobaz'

replace_end('foobar', 'qux', 'baz')
# 'foobar'

String Extraction Functions

substr_left

def substr_left(text: Any, subtext: Any) -> str

Return substring of text before the first occurrence of subtext.

Parameters:

  • text (Any): String to extract from.
  • subtext (Any): String to search for.

Returns:

  • str: Substring before first occurrence of subtext.

Example:

from pydash import substr_left

substr_left('foobar', 'b')
# 'foo'

substr_left('foobar', 'z')
# 'foobar'

substr_left_end

def substr_left_end(text: Any, subtext: Any) -> str

Return substring of text before the last occurrence of subtext.

Parameters:

  • text (Any): String to extract from.
  • subtext (Any): String to search for.

Returns:

  • str: Substring before last occurrence of subtext.

Example:

from pydash import substr_left_end

substr_left_end('foobarbar', 'bar')
# 'foobar'

substr_right

def substr_right(text: Any, subtext: Any) -> str

Return substring of text after the first occurrence of subtext.

Parameters:

  • text (Any): String to extract from.
  • subtext (Any): String to search for.

Returns:

  • str: Substring after first occurrence of subtext.

Example:

from pydash import substr_right

substr_right('foobar', 'o')
# 'obar'

substr_right('foobar', 'z')
# ''

substr_right_end

def substr_right_end(text: Any, subtext: Any) -> str

Return substring of text after the last occurrence of subtext.

Parameters:

  • text (Any): String to extract from.
  • subtext (Any): String to search for.

Returns:

  • str: Substring after last occurrence of subtext.

Example:

from pydash import substr_right_end

substr_right_end('foobarbar', 'bar')
# 'bar'

String Transformation Functions

deburr

def deburr(text: Any) -> str

Converts Latin-1 Supplement and Latin Extended-A letters to basic Latin letters and removes combining diacritical marks.

Parameters:

  • text (Any): String to deburr.

Returns:

  • str: Deburred string.

Example:

from pydash import deburr

deburr('déjà vu')
# 'deja vu'

escape

def escape(text: Any) -> str

Converts the characters "&", "<", ">", '"', and "'" in text to their corresponding HTML entities.

Parameters:

  • text (Any): String to escape.

Returns:

  • str: HTML escaped string.

Example:

from pydash import escape

escape('fred, barney, & pebbles')
# 'fred, barney, &amp; pebbles'

unescape

def unescape(text: Any) -> str

The inverse of escape. Converts the HTML entities "&", "<", ">", """, and "'" in text to their corresponding characters.

Parameters:

  • text (Any): String to unescape.

Returns:

  • str: HTML unescaped string.

Example:

from pydash import unescape

unescape('fred, barney, &amp; pebbles')
# 'fred, barney, & pebbles'

escape_reg_exp

def escape_reg_exp(text: Any) -> str

Escapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in text.

Parameters:

  • text (Any): String to escape.

Returns:

  • str: Escaped string.

Example:

from pydash import escape_reg_exp

escape_reg_exp('[pydash](https://python.org/)')
# '\\[pydash\\]\\(https://python\\.org/\\)'

quote

def quote(text: Any, quote_char: Any = '"') -> str

Quote text with quote_char.

Parameters:

  • text (Any): String to quote.
  • quote_char (Any): Character to quote with. Defaults to '"'.

Returns:

  • str: Quoted string.

Example:

from pydash import quote

quote('hello')
# '"hello"'

quote('hello', "'")
# "'hello'"

unquote

def unquote(text: Any, quote_char: Any = '"') -> str

Unquote text by removing quote_char from beginning and end.

Parameters:

  • text (Any): String to unquote.
  • quote_char (Any): Quote character to remove. Defaults to '"'.

Returns:

  • str: Unquoted string.

Example:

from pydash import unquote

unquote('"hello"')
# 'hello'

unquote("'hello'", "'")
# 'hello'

surround

def surround(text: Any, wrapper: Any) -> str

Surround text with wrapper.

Parameters:

  • text (Any): String to surround.
  • wrapper (Any): String to wrap with.

Returns:

  • str: Surrounded string.

Example:

from pydash import surround

surround('abc', '"')
# '"abc"'

surround('abc', '!')
# '!abc!'

String Repetition and Generation

repeat

def repeat(text: Any, n: int = 0) -> str

Repeats the given string n times.

Parameters:

  • text (Any): String to repeat.
  • n (int): Number of times to repeat. Defaults to 0.

Returns:

  • str: Repeated string.

Example:

from pydash import repeat

repeat('*', 3)
# '***'

repeat('abc', 2)
# 'abcabc'

repeat('abc', 0)
# ''

predecessor

def predecessor(char: Any) -> str

Return the predecessor character of char.

Parameters:

  • char (Any): Character to get predecessor of.

Returns:

  • str: Predecessor character.

Example:

from pydash import predecessor

predecessor('c')
# 'b'

predecessor('C')
# 'B'

predecessor('3')
# '2'

successor

def successor(char: Any) -> str

Return the successor character of char.

Parameters:

  • char (Any): Character to get successor of.

Returns:

  • str: Successor character.

Example:

from pydash import successor

successor('a')
# 'b'

successor('A')
# 'B'

successor('1')
# '2'

String Formatting Functions

insert_substr

def insert_substr(text: Any, index: int, subtext: Any) -> str

Insert subtext into text starting at index.

Parameters:

  • text (Any): String to modify.
  • index (int): Index to insert at.
  • subtext (Any): String to insert.

Returns:

  • str: Modified string.

Example:

from pydash import insert_substr

insert_substr('abcdef', 3, 'XYZ')
# 'abcXYZdef'

join

def join(array: Iterable[Any], separator: Any = '') -> str

Joins the elements in array into a string separated by separator.

Parameters:

  • array (Iterable[Any]): Array to join.
  • separator (Any): Separator string. Defaults to ''.

Returns:

  • str: Joined string.

Example:

from pydash import join

join(['a', 'b', 'c'], '~')
# 'a~b~c'

join([1, 2, 3], ', ')
# '1, 2, 3'

number_format

def number_format(number: Union[int, float], scale: int = 0, decimal_sep: str = '.', thousands_sep: str = ',') -> str

Format a number to a readable string representation.

Parameters:

  • number (Union[int, float]): Number to format.
  • scale (int): Number of decimal places. Defaults to 0.
  • decimal_sep (str): Decimal separator. Defaults to '.'.
  • thousands_sep (str): Thousands separator. Defaults to ','.

Returns:

  • str: Formatted number string.

Example:

from pydash import number_format

number_format(1234.5678)
# '1,235'

number_format(1234.5678, 2)
# '1,234.57'

number_format(1234.5678, 3, ',', ' ')
# '1 234,568'

prune

def prune(text: Any, length: int = 0, omission: str = '...') -> str

Like truncate except that it ensures that the pruned string doesn't exceed the original length and that words are not cut off unless necessary.

Parameters:

  • text (Any): String to prune.
  • length (int): Maximum length. Defaults to 0.
  • omission (str): Omission string. Defaults to '...'.

Returns:

  • str: Pruned string.

Example:

from pydash import prune

prune('hi-diddly-ho there, neighborino', 24)
# 'hi-diddly-ho there...'

truncate

def truncate(text: Any, length: int = 30, omission: str = '...', separator: Any = None) -> str

Truncates text if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to "...".

Parameters:

  • text (Any): String to truncate.
  • length (int): Maximum string length. Defaults to 30.
  • omission (str): Omission string. Defaults to '...'.
  • separator (Any, optional): Separator pattern to truncate to.

Returns:

  • str: Truncated string.

Example:

from pydash import truncate

truncate('hi-diddly-ho there, neighborino')
# 'hi-diddly-ho there, neighbo...'

truncate('hi-diddly-ho there, neighborino', 24)
# 'hi-diddly-ho there, n...'

strip_tags

def strip_tags(text: Any) -> str

Remove HTML/XML tags from text.

Parameters:

  • text (Any): String to strip tags from.

Returns:

  • str: String with tags removed.

Example:

from pydash import strip_tags

strip_tags('<p>Hello <strong>world</strong>!</p>')
# 'Hello world!'

slugify

def slugify(text: Any) -> str

Convert text into an ASCII slug by replacing whitespace, dashes, and underscores with dashes, removing non-word characters, and converting to lower case.

Parameters:

  • text (Any): String to slugify.

Returns:

  • str: Slugified string.

Example:

from pydash import slugify

slugify('Hello World!')
# 'hello-world'

slugify('  Hello    World  ')
# 'hello-world'

url

def url(text: Any, **params: Any) -> str

Create a URL by appending query string parameters to text.

Parameters:

  • text (Any): Base URL string.
  • params (**Any): Query parameters to append.

Returns:

  • str: URL with query string.

Example:

from pydash import url

url('http://example.com', foo='bar', hello='world')
# 'http://example.com?foo=bar&hello=world'

String Replacement Functions

replace

def replace(text: Any, pattern: Any, repl: Any, count: int = -1) -> str

Replace occurrences of pattern with repl in text. Optionally, limit number of replacements to count.

Parameters:

  • text (Any): String to search and replace in.
  • pattern (Any): String pattern to find.
  • repl (Any): String to replace matches with.
  • count (int): Maximum number of replacements. Defaults to -1 (all).

Returns:

  • str: String with replacements made.

Example:

from pydash import replace

replace('aabbcc', 'b', 'X')
# 'aaXXcc'

replace('aabbcc', 'b', 'X', 1)
# 'aaXbcc'

reg_exp_replace

def reg_exp_replace(text: Any, pattern: Any, repl: Any) -> str

Replace occurrences of regular expression pattern with repl in text.

Parameters:

  • text (Any): String to search and replace in.
  • pattern (Any): Regular expression pattern to find.
  • repl (Any): String to replace matches with.

Returns:

  • str: String with replacements made.

Example:

from pydash import reg_exp_replace
import re

reg_exp_replace('hello world', r'l+', 'L')
# 'heLo worLd'

reg_exp_js_match

def reg_exp_js_match(text: Any, reg_exp: Any) -> Union[List[str], None]

Return list of matches using JavaScript style regular expression.

Parameters:

  • text (Any): String to search.
  • reg_exp (Any): JavaScript style regular expression.

Returns:

  • Union[List[str], None]: List of matches or None.

reg_exp_js_replace

def reg_exp_js_replace(text: Any, reg_exp: Any, repl: Any) -> str

Replace text using JavaScript style regular expression.

Parameters:

  • text (Any): String to search and replace in.
  • reg_exp (Any): JavaScript style regular expression.
  • repl (Any): String to replace matches with.

Returns:

  • str: String with replacements made.

String Utility Functions

separator_case

def separator_case(text: Any, separator: Any) -> str

Convert text to a delimited string where words are separated by separator.

Parameters:

  • text (Any): String to convert.
  • separator (Any): Separator to use between words.

Returns:

  • str: Converted string with custom separator.

Example:

from pydash import separator_case

separator_case('fooBar', '.')
# 'foo.Bar'

separator_case('Foo Bar', '_')
# 'Foo_Bar'

series_phrase

def series_phrase(array: List[Any]) -> str

Join array into a grammatically correct series phrase (e.g. "a, b, and c").

Parameters:

  • array (List[Any]): Array to join into series phrase.

Returns:

  • str: Grammatically correct series phrase.

Example:

from pydash import series_phrase

series_phrase(['apple'])
# 'apple'

series_phrase(['apple', 'banana'])
# 'apple and banana'

series_phrase(['apple', 'banana', 'cherry'])
# 'apple, banana, and cherry'

series_phrase_serial

def series_phrase_serial(array: List[Any]) -> str

Like series_phrase but with serial comma (Oxford comma).

Parameters:

  • array (List[Any]): Array to join into series phrase.

Returns:

  • str: Series phrase with serial comma.

Example:

from pydash import series_phrase_serial

series_phrase_serial(['apple', 'banana', 'cherry'])
# 'apple, banana, and cherry'

This Strings module provides comprehensive string manipulation capabilities with 66 functions covering all aspects of string processing from basic transformations to advanced formatting and pattern matching operations.

Install with Tessl CLI

npx tessl i tessl/pypi-pydash

docs

arrays.md

chaining.md

collections.md

functions.md

index.md

numerical.md

objects.md

predicates.md

strings.md

utilities.md

tile.json