Types
NumberMode = enum Number, FloatNumber, NoNumber, LowWord, CapWord, UpWord, FloatLowWord, FloatCapWord, FloatUpWord, Roman
-
Type of number to display
Int Number. Float Number. No number
Words can be like "two hundred eighty-eight"
Lower case word, Capitalized word, Upper case word
Words that use a float number like "two point one"
Roman number like XXI
Consts
Vowels = ['a', 'e', 'i', 'o', 'u']
Consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']
Minute = 60
Hour = 3600
Day = 86400
Month = 2592000
Year = 31536000
Powers = [("hundred", 2), ("thousand", 3), ("million", 6), ("billion", 9), ("trillion", 12)]
Tens = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
Teens = ["ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"]
Digits = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
Symbols = [("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1)]
Morse = (data: [(0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-8873259922900124793, 100, "-.."), (8342452838373489416, 54, "-...."), (7239222394256622087, 95, "..--.-"), (0, 0, ""), (517012403755787147, 102, "..-."), (0, 0, ""), (-7903714019551877491, 39, ".----."), (0, 0, ""), (8335848251648200591, 111, "---"), (0, 0, ""), (-2200606867630800367, 49, ".----"), (8918329976139103890, 103, "--."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-7074746107464171113, 38, ".-..."), (0, 0, ""), (6976072046530000921, 99, "-.-."), (4641731221724435865, 114, ".-."), (0, 0, ""), (-7971308710080522340, 115, "..."), (-7735177970118391908, 117, "..-"), (0, 0, ""), (-6370990134431913313, 46, ".-.-.-"), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (2081286092677608996, 52, "....-"), (-5451865323959630683, 63, "..--.."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-5027170248768959831, 119, ".--"), (-5340964688531826903, 47, "-..-."), (8810441968359124267, 56, "---.."), (9021190906325794348, 51, "...--"), (0, 0, ""), (-2184948978477078098, 48, "-----"), (1431135165460418735, 112, ".--."), (-4708809695820797393, 116, "-"), (3848473405950785070, 61, "-...-"), (0, 0, ""), (0, 0, ""), (6067020622403669428, 41, "-.--.-"), (0, 0, ""), (0, 0, ""), (1510552602102226487, 108, ".-.."), (-4478592245859895240, 98, "-..."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (8394969970134436156, 110, "-."), (1284149594550294460, 113, "--.-"), (-1662807736027766211, 50, "..---"), (9147201994791625791, 101, "."), (-1153189567419900995, 43, ".-.-."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (3823974986434800326, 59, "-.-.-."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-124785542862574260, 55, "--..."), (7095226049739885645, 118, "...-"), (0, 0, ""), (0, 0, ""), (-1463840930393405872, 105, ".."), (-4250869863185719728, 64, ".--.-."), (7522575977827817042, 120, "-..-"), (-6310729832322003117, 107, "-.-"), (0, 0, ""), (-4471540845343456427, 36, "...-..-"), (0, 0, ""), (0, 0, ""), (-1123825773370310952, 33, "-.-.--"), (0, 0, ""), (0, 0, ""), (-8804310308688710565, 34, ".-..-."), (5479171323004962908, 44, "--..--"), (0, 0, ""), (0, 0, ""), (0, 0, ""), (661948602591176288, 97, ".-"), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-8525655625207859868, 104, "...."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (5855890389300015211, 106, ".---"), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-7088134873746566927, 121, "-.--"), (6285845842184796145, 58, "---..."), (0, 0, ""), (-6913149447469539596, 40, "-.--."), (0, 0, ""), (0, 0, ""), (2581362390628829559, 57, "----."), (2530230247324136056, 122, "--.."), (0, 0, ""), (0, 0, ""), (0, 0, ""), (0, 0, ""), (-5847369087369713155, 109, "--"), (-6679268314346976898, 53, "....."), (-173515851481370370, 45, "-....-")], counter: 54)
Procs
proc multistring(num: SomeNumber; s_word, p_word: string; mode = Number): string
-
Purpose: Avoid strings like "1 days" when it should be "1 day"
Send the number of the amount of things. 1 == singular
Send the singular word and the plural word
Accepts an optional NumberMode
Example:
assert multistring(1, "day", "days") == "1 day" assert multistring(3, "cat", "cats") == "3 cats" assert multistring(4, "dog", "dogs", NoNumber) == "dogs" assert multistring(4, "dog", "dogs", LowWord) == "four dogs" assert multistring(4, "DOG", "DoGs", CapWord) == "Four DoGs" assert multistring(1, "dog", "dogs", UpWord) == "ONE dog" assert multistring(1.2, "thing", "things", Number) == "1 thing" assert multistring(1.2, "thing", "things", FloatNumber) == "1.2 things" assert multistring(1.2, "thing", "things", LowWord) == "one thing" assert multistring(1.2, "thing", "things", FloatUpWord) == "ONE POINT TWO things" assert multistring(1.2, "thing", "things", Roman) == "I thing"
proc numberwords(num: SomeNumber): string
-
Purpose: Turn numbers into english words
Submit the number that is transformed into words
Example:
assert numberwords(0) == "zero" assert numberwords(10) == "ten" assert numberwords(122) == "one hundred twenty-two" assert numberwords(3_654_321) == "three million six hundred fifty-four thousand three hundred twenty-one" assert numberwords(9.1818) == "nine point two" assert numberwords(603000000) == "six hundred three million"
proc countword(text: string): int {...}{.raises: [], tags: [].}
-
Purpose: Get the sum of letter index values
Example:
assert countword("a") == 1 assert countword("z") == 26 assert countword("abc") == 6 assert countword("2 abc #$% 2") == 10
proc timeago(date_1, date_2: int64; mode = Number): string {...}{. raises: [ValueError, Exception], tags: [RootEffect].}
-
Purpose: Get the timeago message between two dates
Used for simple messages like "posted 1 hour ago"
The dates are 2 unix timestamps in seconds
Accepts an optional NumberMode
Example:
assert timeago(0, 10) == "10 seconds" assert timeago(0, 140) == "2 minutes" assert timeago(0, 140, FloatNumber) == "2.3 minutes" assert timeago(0, Hour * 3, LowWord) == "three hours" assert timeago(0, Month, CapWord) == "One Month" assert timeago(0, Year * 10, UpWord) == "TEN YEARS"
proc wordtag(num: int; vowels_first: bool = true; rng: var Rand = randgen): string {...}{. raises: [], tags: [].}
-
Purpose: Generate random string tags
It alternates between vowels and consonants
Receives a number to set the length
Receives a boolean to set if vowels go first
A rand seed can be provided as an extra argument
Example:
let wtag = wordtag(3, true) assert wtag.len == 3 assert wtag[0] in Vowels assert wtag[1] in Consonants
proc leetspeak(text: string): string {...}{.raises: [], tags: [].}
-
Purpose: Turn a string into 'leet speak'
Example:
assert leetspeak("maple strikter") == "m4pl3 s7r1k73r"
proc numerate(lines: openArray[string]; left, right: string; mode = Number): string {...}{. raises: [ValueError, Exception], tags: [RootEffect].}
-
Purpose: Add numbers to lines
Send an array of lines
And the left and right parts around the number
Accepts an optional NumberMode
Example:
assert numerate(["This line", "That line"], "", ")") == "1) This line\n2) That line" assert numerate(["This line", "That line"], "[", "]", LowWord) == "[one] This line\n[two] That line" assert numerate(["This line", "That line"], "[", "]", CapWord) == "[One] This line\n[Two] That line" assert numerate(["This line", "That line"], "[", "]", UpWord) == "[ONE] This line\n[TWO] That line" assert numerate(["This line", "That line"], "(", ")", Roman) == "(I) This line\n(II) That line"
proc insertnum(text, token: string; mode = Number): string {...}{. raises: [ValueError, Exception], tags: [RootEffect].}
-
Purpose: Replace token with an incrementing number
Send the text and token
Accepts an optional NumberMode
Example:
assert insertnum("This is $ and this is $", "$") == "This is 1 and this is 2" assert insertnum("Hello _ and _", "_", LowWord) == "Hello one and two" assert insertnum("Hello _ and _", "_", CapWord) == "Hello One and Two" assert insertnum("Hello _ and _", "_", UpWord) == "Hello ONE and TWO" assert insertnum("x x x x x", "x", Roman) == "I II III IV V"
proc linesummary(lines: openArray[string]; words, characters: bool; mode = Number): string {...}{.raises: [ValueError, Exception], tags: [RootEffect].}
-
Print the number of words and characters per line
Send an array of lines
And two booleans to enable/disable words & chars
Example:
assert linesummary(["hello there"], true, true) == "hello there (2 words) (10 chars)" assert linesummary(["ab", "c d e"], false, true) == "ab (2 chars)\nc d e (3 chars)" assert linesummary(["ab", "c d e"], false, true, CapWord) == "ab (Two Chars)\nc d e (Three Chars)"
proc romano(num: SomeNumber): string
-
Convert regular numbers to roman numbers
Example:
assert romano(21) == "XXI" assert romano(1994) == "MCMXCIV" assert romano(1) == "I" assert romano(0) == "0" assert romano(-11) == "-XI"
proc wordsnumber(text: string): Option[float] {...}{.raises: [ValueError], tags: [].}
-
Change number words to numbers
Example:
import std/options assert wordsnumber("six hundred three").get() == 603.0 assert wordsnumber("six hundred three million").get() == 603000000.0 assert wordsnumber("six million three hundred ten thousand six hundred thirty-two").get() == 6310632.0 assert wordsnumber("zero").get() == 0 assert wordsnumber("minus four thousand two").get() == -4002.0 assert wordsnumber("thirty-three point three").get() == 33.3 assert wordsnumber("thirty three point five hundred thirty two thousand eleven").get() == 33.532011 assert wordsnumber("three hundred forty").get() == 340 assert wordsnumber("One HUNDRED NiNeteen").get() == 119 assert wordsnumber("minus three three two one seven point five").get() == -33217.5 assert wordsnumber("nothing here") == none(float) assert wordsnumber("nothing two here forty").get() == 240
proc writemorse(text: string): string {...}{.raises: [KeyError], tags: [].}
-
Turn a string into morse code
Words in the result are separated by a slash
Example:
assert writemorse("a b c") == ".- / -... / -.-." assert writemorse("420") == "....- ..--- -----" assert writemorse("hunter 2") == ".... ..- -. - . .-. / ..---" assert writemorse("@$.,") == ".--.-. ...-..- .-.-.- --..--" assert writemorse("what 112 !!?") == ".-- .... .- - / .---- .---- ..--- / -.-.-- -.-.-- ..--.." assert writemorse("100 + 200") == ".---- ----- ----- / .-.-. / ..--- ----- -----"
proc readmorse(text: string): string {...}{.raises: [KeyError], tags: [].}
-
Turn morse code into a string
Words should be separated by a slash
Example:
assert readmorse(".-- .... .- - / .---- .---- ..--- / -.-.-- -.-.-- ..--..") == "what 112 !!?" assert readmorse("- .... . / -- .- --. .. -.-. .. .- -.") == "the magician" assert readmorse(".---- ----- ----- / .-.-. / ..--- ----- -----") == "100 + 200"
proc shufflewords(text: string; rng: var Rand = randgen): string {...}{.raises: [], tags: [].}
-
Shuffle words around
Send a string to be shuffled
A rand seed can be provided as an extra argument
Example:
import std/random var rng = initRand(100) assert shufflewords("this thing is", rng) == "thing is this" assert shufflewords("this thing is", rng) == "this thing is" assert shufflewords("this thing is", rng) == "thing this is"
proc textnumbers(text: string; mode = Number): string {...}{.raises: [], tags: [RootEffect].}
-
Replace all numbers in a string
Send a text string
It checks every word in search for numbers
Accepts an optional NumberMode
Example:
assert textnumbers("Number 3.2 and 8.9") == "Number 3 and 8" assert textnumbers("Number 3.2 and 8.9", FloatNumber) == "Number 3.2 and 8.9" assert textnumbers("Number 3 and 8", LowWord) == "Number three and eight" assert textnumbers("Number 3 and 8", Roman) == "Number III and VIII" assert textnumbers("3.2 and 8.9", FloatCapWord) == "Three Point Two and Eight Point Nine"
proc wordslen(text: string; keep_word: bool; mode = Number): string {...}{. raises: [ValueError, Exception], tags: [RootEffect].}
-
Replace all words with their string length
Send a text string
Send a boolean to specify if words are kept
Accepts an optional NumberMode
Example:
assert wordslen("what is there", false) == "4 2 5" assert wordslen("what is there", true) == "what (4) is (2) there (5)" assert wordslen("what is there", false, CapWord) == "Four Two Five" assert wordslen("what is there", true, Roman) == "what (IV) is (II) there (V)"
proc dumbspeak(text: string; caps_first: bool): string {...}{.raises: [], tags: [].}
-
Capitalize every other letter
Send a text string
Send a boolean to specify if caps go first
Example:
assert dumbspeak("hello there", true) == "HeLlO tHeRe" assert dumbspeak("hello there", false) == "hElLo ThErE"
proc nobreaks(text: string): string {...}{.raises: [], tags: [].}
-
Remove linebreaks into a single fluid line
Example:
assert nobreaks("this.\nthing") == "this. thing"
proc charframe(text: string; max_width: SomeNumber; token: char): string
-
Add a frame around the text with a certain character
Send a text string
Send the max width of the output
Send the token used as the frame
Linebreaks get removed from the string
Example:
let s1 = """ ############ # One line # # Another # # line # ############""" let s2 = """ ################ # One line # # Another line # ################""" let s3 = """ ######################### # One line Another line # #########################""" assert charframe("One line\nAnother line", 10, '#') == s1 assert charframe("One line\nAnother line", 15, '#') == s2 assert charframe("One line\nAnother line", 25, '#') == s3
proc longestwords(text: string): seq[string] {...}{.raises: [], tags: [].}
-
Get a list of the longest words
All words in the output are of equal length
Example:
assert longestwords("Is that the only solution to this problem?") == @["solution", "problem?"]
proc shortestwords(text: string): seq[string] {...}{.raises: [], tags: [].}
-
Get a list of the longest words
All words in the output are of equal length
Example:
assert shortestwords("Is that the only solution to this problem?") == @["is", "to"]
proc repstring(text: string; chars: openArray[char]; replace_with: string = ""): string {...}{. raises: [], tags: [].}
-
Remove chars from strings
Send a text string
Send an array of chars to replace
Send an optional replace_with string
Example:
assert repstring("what !is! this???!", ['!', '?']) == "what is this" assert repstring("what??is this", ['?', 's'], "@") == "what@@i@ thi@"
proc asciistring(text: string; keep_numbers: bool = true): string {...}{.raises: [], tags: [].}
-
Remove all non-ascii chars
Send an optional bool to set if numbers are kept
Example:
assert asciistring("That thing!!") == "That thing" assert asciistring("N!u!mber 22...") == "Number 22" assert asciistring("w2h2a2t 5is t4hi9s", false) == "what is this"
proc keepchars(text: string; chars: openArray[char]): string {...}{.raises: [], tags: [].}
-
Remove all chars except the given ones
Send a text string
Send an array of chars to keep
Example:
assert keepchars("hello these thing", ['e', 'l']) == "ell ee" assert keepchars("eeEEmsteeEm", ['E', 'm']) == "EEmEm"
proc remove_punctuation(text: string): string {...}{.raises: [RegexError], tags: [].}
-
Remove punctuation at the end of words
Example:
assert remove_punctuation("hello, what is this?") == "hello what is this" assert remove_punctuation("hello!! ok; ??") == "hello ok" assert remove_punctuation("Hello #12") == "Hello #12" assert remove_punctuation("Hello?!!?:?!:;; There") == "Hello There"
proc count_vowels(text: string): int {...}{.raises: [], tags: [].}
-
Count the number of vowels in a string
Example:
assert count_vowels("la pacha") == 3
proc count_consonants(text: string): int {...}{.raises: [], tags: [].}
-
Count the number of consonants in a string
Example:
assert count_consonants("la pacha") == 4
proc countletters(text: string): int {...}{.raises: [], tags: [].}
-
Count the number of letters in a string
Doesn't count whitespace
Example:
assert countletters("hello world") == 10
proc printwords(text: string; max_words: SomeNumber; delay: SomeNumber)
-
Print words every x milliseconds
Send a text string
Send the max number of words per line
Send the sleep delay in ms
proc flashwords(text: string; max_words: SomeNumber; delay: SomeNumber)
- Same as printwords but erases the previous line