Skip to content

Instantly share code, notes, and snippets.

@arnu515-test
Last active January 12, 2021 09:32
PyDash on dev.to
class PyDash:
def __init__(self):
pass
@staticmethod
def lower(string: str):
"""
Converts a string to lowercase
"""
return string.lower()
@staticmethod
def upper(string: str):
"""
Converts a string to uppercase
"""
return string.upper()
@staticmethod
def title(string: str):
"""
Converts a string to titlecase
"""
return string.title()
@staticmethod
def kebab(string: str):
"""
Converts a string to kebabcase
"""
return string.replace(" ", "-").lower()

Pydash

A simple and stupid clone of LoDash in python.

This was made for my blog post on dev.to and is not a serious package, so don't expect updates.

MIT License
Copyright (c) 2021 arnu515
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.
from setuptools import setup, find_packages
from os.path import abspath, dirname, join
# Fetches the content from README.md
# This will be used for the "long_description" field.
README_MD = open(join(dirname(abspath(__file__)), "README.md")).read()
setup(
# The name of your project that we discussed earlier.
# This name will decide what users will type when they install your package.
# In my case it will be:
# pip install pydash-arnu515
# This field is REQUIRED
name="pydash-arnu515",
# The version of your project.
# Usually, it would be in the form of:
# major.minor.patch
# eg: 1.0.0, 1.0.1, 3.0.2, 5.0-beta, etc.
# You CANNOT upload two versions of your package with the same version number
# This field is REQUIRED
version="1.0.0",
# The packages that constitute your project.
# For my project, I have only one - "pydash".
# Either you could write the name of the package, or
# alternatively use setuptools.findpackages()
#
# If you only have one file, instead of a package,
# you can instead use the py_modules field instead.
# EITHER py_modules OR packages should be present.
packages=find_packages(),
# The description that will be shown on PyPI.
# Keep it short and concise
# This field is OPTIONAL
description="A small clone of lodash",
# The content that will be shown on your project page.
# In this case, we're displaying whatever is there in our README.md file
# This field is OPTIONAL
long_description=README_MD,
# Now, we'll tell PyPI what language our README file is in.
# In my case it is in Markdown, so I'll write "text/markdown"
# Some people use reStructuredText instead, so you should write "text/x-rst"
# If your README is just a text file, you have to write "text/plain"
# This field is OPTIONAL
long_description_content_type="text/markdown",
# The url field should contain a link to a git repository, the project's website
# or the project's documentation. I'll leave a link to this project's Github repository.
# This field is OPTIONAL
url="https://github.com/arnu515/pydash",
# The author name and email fields are self explanatory.
# These fields are OPTIONAL
author_name="arnu515",
author_email="arnu5152@gmail.com",
# Classifiers help categorize your project.
# For a complete list of classifiers, visit:
# https://pypi.org/classifiers
# This is OPTIONAL
classifiers=[
"License :: OSI Approved :: MIT License",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3 :: Only"
],
# Keywords are tags that identify your project and help searching for it
# This field is OPTIONAL
keywords="lodash, string, manipulation",
# For additional fields, check:
# https://github.com/pypa/sampleproject/blob/master/setup.py
)
import unittest
from pydash import PyDash
class Test(unittest.TestCase):
def test_lower_method(self):
self.assertEqual(PyDash.lower("TEST"), "test")
self.assertNotEqual(PyDash.lower("test"), "TEST")
def test_upper_method(self):
self.assertEqual(PyDash.upper("test"), "TEST")
self.assertNotEqual(PyDash.upper("TEST"), "test")
def test_title_method(self):
self.assertEqual(PyDash.title("hello world"), "Hello world")
self.assertNotEqual(PyDash.title("hELLO wORLD"), "hello world")
def test_kebab_method(self):
self.assertEqual(PyDash.kebab("Kebab case adds hyphens BetWEEN lowerCASE text"),
"kebab-case-adds-hyphens-between-lowercase-text")
self.assertNotEqual(PyDash.kebab("Kebab case doesn't contain spaces"), "kebab-case-doesn't contain spaces")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment