Skip to content

Commit 9d54395

Browse files
committed
Initial commit
Add starting project files and initial set of functions.
0 parents  commit 9d54395

5 files changed

Lines changed: 114 additions & 0 deletions

File tree

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Editor code style configuration
2+
# http://editorconfig.org/
3+
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 4
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true
12+
13+
[*.md]
14+
trim_trailing_whitespace = false

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Alex Hunt
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# stringutils
2+
3+
A functional string utility library for Python.

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from setuptools import setup
2+
3+
setup(
4+
name='stringutils',
5+
description='A functional string utility library for Python',
6+
version='0.1.0',
7+
url='https://github.com/huntie/stringutils',
8+
author='Alex Hunt',
9+
author_email='hello@alexhunt.io',
10+
license='MIT',
11+
12+
classifiers=[
13+
'Development Status :: 4 - Beta',
14+
'Intended Audience :: Developers',
15+
'License :: OSI Approved :: MIT License',
16+
'Programming Language :: Python :: 3',
17+
'Topic :: Text Processing',
18+
'Topic :: Utilities',
19+
],
20+
21+
packages=['stringutils'],
22+
)

stringutils/__init__.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
stringutils
3+
~~~~~~~~~~~
4+
5+
A functional string utility library for Python.
6+
7+
:copyright: (c) 2018 Alex Hunt.
8+
:license: MIT, see LICENSE.txt for more details.
9+
"""
10+
11+
import re
12+
13+
def join(strings, sep=', ', insertend=False):
14+
"""
15+
Concatenate a list of strings into a single string by a separating
16+
delimiter. If *insertend* is given and true, the delimiter is also included
17+
at the end of the string.
18+
"""
19+
return sep.join(strings)
20+
21+
def lines(string, keepends=False):
22+
"""
23+
Split a string into a list of strings at newline characters. Unless
24+
*keepends* is given and true, the resulting strings do not have newlines
25+
included.
26+
"""
27+
return string.splitlines(keepends)
28+
29+
def words(string):
30+
"""
31+
Split a string into a list of words, which were delimited by one or more
32+
whitespace characters.
33+
"""
34+
return re.split('\s+', string)
35+
36+
def unlines(lines):
37+
"""
38+
Join a list of lines into a single string after appending a terminating
39+
newline character to each.
40+
"""
41+
return join(lines, '\n', True)
42+
43+
def unlines_universal(lines):
44+
"""
45+
Join a list of lines into a single string after appending a terminating
46+
CRLF newline sequence to each.
47+
"""
48+
return join(lines, '\r\n', True)
49+
50+
def unwords(words):
51+
"""
52+
Join a list of words into a single string with separating spaces.
53+
"""
54+
return join(words, ' ')

0 commit comments

Comments
 (0)