How to use the pydash.is_string function in pydash

To help you get started, we’ve selected a few pydash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kengz / SLM-Lab / test / lib / test_util.py View on Github external
def test_get_ts():
    ts = util.get_ts()
    assert ps.is_string(ts)
    assert util.RE_FILE_TS.match(ts)
github dgilland / pydash / tests / test_functions.py View on Github external
    ((_.is_string, _.is_number), ['one', 1, 'two', 2], True),
    ((_.is_string, _.is_number), [True, False, None, []], False),
])
def test_disjoin(case, arg, expected):
    assert _.disjoin(*case)(arg) == expected
github dgilland / pydash / src / pydash / utilities.py View on Github external
def to_path_tokens(value):
    """Parse `value` into :class:`PathToken` objects."""
    if pyd.is_string(value) and ('.' in value or '[' in value):
        # Since we can't tell whether a bare number is supposed to be dict key
        # or a list index, we support a special syntax where any string-integer
        # surrounded by brackets is treated as a list index and converted to an
        # integer.
        keys = [PathToken(int(key[1:-1]), default_factory=list)
                if RE_PATH_LIST_INDEX.match(key)
                else PathToken(unescape_path_key(key), default_factory=dict)
                for key in filter(None, RE_PATH_KEY_DELIM.split(value))]
    elif pyd.is_string(value) or pyd.is_number(value):
        keys = [PathToken(value, default_factory=dict)]
    elif value is NoValue:
        keys = []
    else:
        keys = value

    return keys
github dgilland / pydash / src / pydash / arrays.py View on Github external
[1, 4]
        >>> array = [1, 2, 3, 4]
        >>> splice(array, 1, 2, 0, 0)
        [2, 3]
        >>> array
        [1, 0, 0, 4]

    .. versionadded:: 2.2.0

    .. versionchanged:: 3.0.0
        Support string splicing.
    """
    if count is None:
        count = len(array) - start

    is_string = pyd.is_string(array)

    if is_string:
        array = list(array)

    removed = array[start:start + count]
    del array[start:start + count]

    for item in reverse(items):
        array.insert(start, item)

    if is_string:
        return ''.join(array)
    else:
        return removed
github dgilland / pydash / src / pydash / objects.py View on Github external
cbk = customizer
    else:
        cbk = None

    if cbk:
        result = cbk(value, key, value)

    if result is not None:
        return result

    if not _cloned:
        result = clone_by(value)
    else:
        result = value

    if cbk and not pyd.is_string(value) and not isinstance(value, bytes):
        for key, subvalue in iterator(value):
            if is_deep:
                val = base_clone(subvalue, is_deep, cbk, key, value,
                                 _cloned=True)
            else:
                val = cbk(subvalue, key, value)

            if val is not None:
                result[key] = val

    return result
github dgilland / pydash / src / pydash / strings.py View on Github external
.. versionchanged:: 4.0.0
        Removed alias ``trunc``.
    """
    text = pyd.to_string(text)

    if len(text) <= length:
        return text

    omission_len = len(omission)
    text_len = length - omission_len
    text = text[:text_len]

    trunc_len = len(text)

    if pyd.is_string(separator):
        trunc_len = text.rfind(separator)
    elif pyd.is_reg_exp(separator):
        last = None
        for match in separator.finditer(text):
            last = match

        if last is not None:
            trunc_len = last.start()

    return text[:trunc_len] + omission
github dgilland / pydash / src / pydash / objects.py View on Github external
>>> to_string(1) == '1'
        True
        >>> to_string(None) == ''
        True
        >>> to_string([1, 2, 3]) == '[1, 2, 3]'
        True
        >>> to_string('a') == 'a'
        True

    .. versionadded:: 2.0.0

    .. versionchanged:: 3.0.0
        Convert ``None`` to empty string.
    """
    if pyd.is_string(obj):
        res = obj
    elif obj is None:
        res = ''
    else:
        res = text_type(obj)
    return res
github dgilland / pydash / src / pydash / objects.py View on Github external
Example:

        >>> to_boolean('true')
        True
        >>> to_boolean('1')
        True
        >>> to_boolean('false')
        False
        >>> to_boolean('0')
        False
        >>> assert to_boolean('a') is None

    .. versionadded:: 3.0.0
    """
    if pyd.is_string(obj):
        obj = obj.strip()

        def boolean_match(text, vals):
            if text.lower() in [val.lower() for val in vals]:
                return True
            else:
                return re.match('|'.join(vals), text)

        if true_values and boolean_match(obj, true_values):
            value = True
        elif false_values and boolean_match(obj, false_values):
            value = False
        else:
            value = None
    else:
        value = bool(obj)

pydash

The kitchen sink of Python utility libraries for doing "stuff" in a functional way. Based on the Lo-Dash Javascript library.

MIT
Latest version published 1 month ago

Package Health Score

91 / 100
Full package analysis