Metadata-Version: 2.1
Name: string-kit
Version: 0.1.0a7
Summary: Library of string functions and formatters
Keywords: string formatter
Author-Email: "Aalap Shah (aka fishfin)" <shah.aalap@gmail.com>
License: MIT License
         
         Copyright (c) 2025 Aalap Shah
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development
Classifier: Topic :: Utilities
Project-URL: Homepage, https://gitlab.com/shah-aalap/python-string-kit
Requires-Python: >=3.13
Description-Content-Type: text/x-rst

.. |pypi-version| image:: https://img.shields.io/pypi/v/string-kit?label=PyPI%20Version&color=4BC51D
   :alt: PyPI Version
   :target: https://pypi.org/projects/string-kit/

.. |pypi-downloads| image:: https://img.shields.io/pypi/dm/string-kit?label=PyPI%20Downloads&color=037585
   :alt: PyPI Downloads
   :target: https://pypi.org/projects/string-kit/

string-kit
##########

|pypi-version| |pypi-downloads|

Description
***********

Provides advanced string utilities and a powerful Formatter.

This is a development version, and while it has been thoroughly tested, it will be battle-tested in a live project and updated as needed.

Formatter
==============

``string_kit.Formatter`` is a drop-in replacement of ``string.Formatter`` and supports the same syntax and more.

``string_kit.Formatter`` adds the following features:
 - virtual fields ``now``, ``uuid1``, ``uuid4``, ``uuid5`` (no key is required in the format parameters, however if present, they take precedence); many more coming up.
 - user-defined virtual fields can be added through ``field_default`` init parm.
 - can send namespaces where format field values are searched through ``namespaces`` init parm.
 - ``!capitalize``, ``!lower``, ``!lstrip``, ``!rstrip``, ``!slug``, ``!strip``, ``!title``, ``!upper``; many more coming up.
 - user-defined convertors can be added through ``convertors`` init parm.
 - chained conversions and format specifications in any order: ``{field!slug:.10s!upper}``.
 - user-configurable ``silence_missing_fields``, if set ``True``, will suppress ``IndexError`` and ``KeyError`` and will quietly replace with empty string.
 - user-configurable characters to identify fields (default ``{}``), convertors (default ``!``) and format specifiers (default ``:``).

A simple example:

.. code-block:: python

   import random
   from string_kit import Formatter

   the_weather = "Sunny but Humid"

   custom_field_defaults = {
       "password": lambda: random.choice(["lI0n", "rAbb1t", "tig3R"]) \
                           + str(random.randint(1000, 9999)),
   }

   custom_convertors = {
       "greeting": lambda str_, greeting: f"{greeting} {str_}",
   }


   class CustomFormatter(Formatter):
       field_defaults = {
           "bye": "Good bye!",
       }
       convertors = {
           "space2dash": lambda str_: str_.replace(" ", "-")
       }


   skf = CustomFormatter(
       silence_missing_fields=True,
       field_defaults=custom_field_defaults,  # optional, dict with str or callable values
       convertors=custom_convertors,          # optional, dict with callable values
       field_namespaces=[locals()],           # optional, namespaces to search for field names
   )

   print(skf.format("{name!space2dash!greeting(Hello)},"
                    " your random password is: '{password}'. {bye}",
                    name="Charlie Brown"))
   # "Hello Charlie-Brown, your random password is: 'rAbb1t1258'. Good bye!"

   print(skf.format("Today is {now!strftime(%A)!upper}, also a"
                    " {the_weather!lower:.5!replace(sunny,sunny \\(☀️\\))} day."
                    " {missing!lstrip}"))
   # "Today is FRIDAY, also a sunny (☀️) day. "

Some TODO Ideas
===============

 - add ``snake_case``, ``kebab-case``, ``PascalCase``, ``camelCase`` as built-in convertors
 - add ``sqids`` convertor with parameters (strings allowed, length) passed as static values
