utils
The utils libray attempts to be relevant to dom related things.
It’s currently mostly string utils but there’s some other bits and bobs in there.
If you can think of any missing that would be good then get in touch.
domonic.utils
snippets etc
-
class domonic.utils.Utils[source]
-
static acronym(sentence: str) → str[source]
[pass a sentence, returns the acronym]
- Parameters
sentence ([str]) – [typically 3 words]
- Returns
[a TLA (three letter acronym)]
- Return type
[str]
-
static case_camel(s: str) → str[source]
case_camel(‘camel-case’) > ‘camelCase’
-
static case_kebab(s: str) → str[source]
kebab(‘camelCase’) # ‘camel-case’
-
static case_snake(s: str) → str[source]
snake(‘camelCase’) # ‘camel_case’
-
static chunk(list: list, size: int) → list[source]
chunk a list into batches
-
static chunks(iterable, size: int, format=<built-in function iter>)[source]
Iterate over any iterable (list, set, file, stream, strings, whatever), of ANY size
-
static clean(lst: list) → list[source]
[removes falsy values (False, None, 0 and “”) from a list ]
- Parameters
lst ([list]) – [lst to operate on]
- Returns
[a new list with falsy values removed]
- Return type
[list]
-
static dictify(arr: list) → dict[source]
[turns a list into a dictionary where the list items are the keys]
- Parameters
arr ([list]) – [list to change]
- Returns
[a new dict where the list items are now the keys]
- Return type
[dict]
-
static digits(text: str = '') → str[source]
[takes a string of mix of digits and letters and returns a string of digits]
- Parameters
text (str, optional) – [the text to change]. Defaults to ‘’.
- Returns
[a string of digits]
- Return type
[str]
-
static escape(s: str) → str[source]
[escape a string]
- Parameters
s ([str]) – [the string to escape]
- Returns
[the escaped string]
- Return type
[str]
-
static frequency(data)[source]
[check the frequency of elements in the data]
- Parameters
data ([type]) – [the data to check]
- Returns
[a dict of elements and their frequency]
- Return type
[dict]
-
static get_vowels(string: str) → list[source]
[get a list of vowels from the word]
- Parameters
string ([str]) – [the word to check]
- Returns
[a list of vowels]
- Return type
[list]
-
static has_internet(url: str = 'http://www.google.com/', timeout: int = 5) → bool[source]
[check if you have internet connection]
- Parameters
-
- Returns
[True if you have internet]
- Return type
[bool]
-
static init_assets(dir: str = 'assets') → None[source]
[creates an assets directory with nested js/css/img dirs]
- Parameters
dir (str, optional) – [default directory name]. Defaults to ‘assets’.
-
static is_linux() → bool[source]
[check if the system is a linux]
- Returns
[description]
- Return type
[bool]
-
static is_mac() → bool[source]
[check if the system is a mac]
- Returns
[True if the system is a mac]
- Return type
[bool]
-
static is_nix() → bool[source]
[check if the system is a nix based system]
- Returns
[True if it is a nix based system]
- Return type
[bool]
-
static is_windows() → bool[source]
[check if the system is a windows]
- Returns
[True if windows]
- Return type
[bool]
-
static merge_dictionaries(a: dict, b: dict) → dict[source]
[merges 2 dicts]
- Parameters
a ([dict]) – [dict a]
b ([dict]) – [dict b]
- Returns
[a new dict]
- Return type
[dict]
-
static permutations(word: str) → list[source]
[provides all the possible permutations of a given word]
- Parameters
word ([str]) – [the word to get permutations for]
- Returns
[a list of permutations]
- Return type
[list]
-
static replace_between(content: str, match: str, replacement: str, start: int = 0, end: int = 0)[source]
[replace some text but only between certain indexes]
- Parameters
content (str) – [the content whos text you will be replacing]
match (str) – [the string to find]
replacement (str) – [the string to replace it with]
start (int, optional) – [start index]. Defaults to 0.
end (int, optional) – [end index]. Defaults to 0.
- Returns
[the new string]
- Return type
[str]
-
static squash(the_list: list) → list[source]
[turns a 2d array into a flat one]
- Parameters
the_list ([list]) – [a 2d array]
- Returns
[a flattened 1d array]
- Return type
[list]
-
static to_dictionary(keys: list, values: list) → dict[source]
[take a list of keys and values and returns a dict]
- Parameters
-
- Returns
[a dictionary]
- Return type
[dict]
-
static truncate(text: str = '', length: int = 0) → str[source]
[truncates a string and appends 3 dots]
- Parameters
text (str, optional) – [the text to truncate]. Defaults to ‘’.
length (int, optional) – [the max length]. Defaults to 0.
- Returns
[the truncated string]
- Return type
[str]
-
static unescape(s: str) → str[source]
[unescape a string]
- Parameters
s ([str]) – [the string to unescape]
- Returns
[the unescaped string]
- Return type
[str]
-
static unique(some_arr: list) → list[source]
[removes duplicates from a list]
- Parameters
some_arr ([list]) – [list containing duplicates]
- Returns
[a list containing no duplicates]
- Return type
[list]
-
static untitle(string: str) → str[source]
[the opposite of title]
- Parameters
str ([str]) – [the string to change]
- Returns
[a string with the first character set to lowercase]
- Return type
[str]
-
static url2file(url: str) → str[source]
[gen a safe filename from a url. by replacing ‘/’ for ‘_’ and ‘:’ for ‘__’ ]
- Parameters
url ([str]) – [the url to turn into a filename]
- Returns
[description]
- Return type
[str]