is

is :: * -> Boolean

is
Parameters
x (any)
Returns
boolean:
Related
https://developer.mozilla.org/en-US/docs/Glossary/Truthy

isArray

isArray
Parameters
xs (Array)
Returns
Boolean:
Example
isArray(1); //=> false
isArray([1,2,3]); //=> true

isNot

isNot :: * -> Boolean

isNot
Parameters
x (any)
Returns
boolean:
Related
https://developer.mozilla.org/en-US/docs/Glossary/Truthy

isObject

isObject
Parameters
x (any)
Returns
boolean:

isString

isString
Parameters
x (string)
Returns
boolean:

countOccurrences

Note that the counts are not sorted and appear in the order that the values of the input array xs is traveresd.

countOccurrences
Parameters
xs (Array<string>) 1d array of strings.
Returns
Object: Where each key is a unique string and each key value is the occurrence frequency of string. Sorting by frequency is not performed.
Related
https://stackoverflow.com/a/56929965/1727232
Example
const xs = ["apple", "orange", "banana", "apple", "banana", "apple"];
countOccurrences(xs); //=> { apple: 3, orange: 1, banana: 2 }

dictGroupByKey

Takes a key and returns a function that expects an array of objects (containing a property equal to key) that finally returns an Object<K,V> where K is the key name used to group all elements of xs and V is an array of elements from xs matching the key value.

dictGroupByKey
Parameters
key (String)
Returns
function (xs: Array<T>): Object<K, V>: Where K is the key name used to group all the elements of xs .
Example
const persons = [
  { id: 1, name: "John" },
  { id: 2, name: "James" },
  { id: 3, name: "Jack" },
  { id: 4, name: "James" },
  { id: 5, name: "Jack" },
  { id: 6, name: "James" },
];

dictGroupByKey ("name") (persons); //=> {John: Array[1], James: Array[3], Jack: Array[2]}

//
// {
//   "John": [
//     { "id": 1, "name": "John" }
//   ],
//   "James": [
//     { "id": 2, "name": "James" },
//     { "id": 4, "name": "James" },
//     { "id": 6, "name": "James" }
//   ],
//   "Jack": [
//     { "id": 3, "name": "Jack" },
//     { "id": 5, "name": "Jack" }
//   ]
// }
//

dictByKey

Takes a key, returns a function that expects an array of objects, finally returns an object of unique keys.

dictByKey
Parameters
key (String)
Returns
function (xs: Array<T>): Object<T<K>, Boolean<True>>: Where K is the key value on some T and Boolean<True> is placeholder.
Example
const persons = [
  { id: 1, name: "John" },
  { id: 2, name: "James" },
  { id: 3, name: "Jack" },
  { id: 4, name: "James" },
  { id: 5, name: "Jack" },
  { id: 6, name: "James" },
];

dictByKey ("name") (persons); //=> { John: true, James: true, Jack: true }

filter

filter
Parameters
predicate (function)
Returns
function (xs: array): array:

filterFalse

Removes elements of the array that evaluate to false when coerced to Boolean.

filterFalse :: [*] -> [*]

filterFalse
Parameters
xs ([])
Returns
[]:

sliceObject

sliceObject
Parameters
$0 (Object)
Name Description
$0.start any
$0.end any
start (number)
end (number)
Returns
function (obj: Object): Object:
Example
const obj = {apple: 3, banana: 2, orange: 1};

sliceObject({start: 0, end: 1})(obj); //=> {apple: 3}
sliceObject({start: 0, end: 2})(obj); //=> {apple: 3, banana: 2}
sliceObject({start: 0, end: 3})(obj); //=> {apple: 3, banana: 2, orange: 1}
sliceObject({start: 0, end: 9})(obj); //=> {apple: 3, banana: 2, orange: 1}

sortByCountDesc

sortByCountDesc
Parameters
counts (Object)
Returns
Object:
Example
const occurrenceCounts = { apple: 3, orange: 1, banana: 2 };
sortByCountDesc(occurrenceCounts); //=> {apple: 3, banana: 2, orange: 1}

uniqValuesByKey

uniqValuesByKey
Parameters
key (String)
Returns
function (xs: Array<T>): Array<String>:
Example
const persons = [
  { id: 1, name: "John" },
  { id: 2, name: "James" },
  { id: 3, name: "Jack" },
  { id: 4, name: "James" },
  { id: 5, name: "Jack" },
  { id: 6, name: "James" },
];

uniqValuesByKey ("name") (persons); //=> ["John", "James", "Jack"]

toTimeFromSeconds

toTimeFromSeconds(elapsedTimeInSeconds: Number): {hours: number, minutes: number, seconds: number}
Parameters
elapsedTimeInSeconds (Number)
Returns
{hours: number, minutes: number, seconds: number}:
Example
toTimeFromSeconds(501227); //=> { hours: 139, minutes: 13, seconds: 46 }

age

age
Parameters
dob (Date)
Returns
(number | NaN):

dateToYmd

dateToYmd
Parameters
date (Date)
Returns
string:

extractDayOfWeek

extractDayOfWeek
Parameters
date (string)
Returns
string: Sunday Monday ... Friday Saturday

extractDayOfWeekNumber

extractDayOfWeekNumber
Parameters
date (string)
Returns
string: 1 2 ... 30 31

extractHour

extractHour
Parameters
date (string)
Returns
string: 00 01 ... 22 23

extractMonthName

extractMonthName
Parameters
date (string)
Returns
string: January February ... November December

getCurrYear

getCurrYear :: () -> Number

getCurrYear
Returns
number:

extractYear

extractYear
Parameters
date (string)
Returns
string: 1970 1971 ... 2029 2030

getDateOneMonthAgo

getDateOneMonthAgo
Returns
Date: The date one month ago from today.

getISO8601DateWithTimeOffsetFromUTC

getISO8601DateWithTimeOffsetFromUTC
Parameters
microseconds (any = false)
Returns
string:
Related
https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators
Example
getISO8601DateWithTimeOffsetFromUTC(); //=> "2007-04-05T12:30-02:00"
getISO8601DateWithTimeOffsetFromUTC(true); //=> "2020-01-23T14:33:15.4260000-05:00"

getPrevYear

getPrevYear :: () -> Number

getPrevYear
Returns
number:

isValidDate

isValidDate
Parameters
d (string) A string represntation of some date.
Returns
boolean:
Example
new Date(undefined); //=> Invalid Date
isNaN(new Date(undefined)); //=> true
isNaN(new Date(undefined)) === false ; //=> false

isValidDate("2020-01-01"); //=> true
isValidDate(undefined); //=> false

isValidDateISO

A wrapper function over date-fns that converts errors arising from unparseable dates into a boolean.

isValidDateISO(x: Date): boolean
Parameters
x (Date)
Returns
boolean:

makeDate

makeDate
Parameters
style (String)
Returns
function (date: any): String: The formatted date string of an empty string if the date was not valid.

parseDateToStyle

Attempts to parse a date a date and return the formatted version with given style.

parseDateToStyle
Parameters
style (string)

renderDate

renderDate(d: string): string
Parameters
d (string)
Returns
string: An empty string if the date cannot be parsed otherwise the formatted date.

tryFormatDate

tryFormatDate(date: string, dateFormat: string, fallbackText: string): string
Parameters
date (string) A valid ISO8601 date like 2016-01-01 13:41:51.000
dateFormat (string)
fallbackText (string)
Returns
string: The value of fallbackText if the date cannot be parsed otherwise the formatted date.
Example
// ex. 1
tryFormatDate(
  "2016-01-01 13:41:51.000",
  "EEE MMM dd, yyyy 'at' HH:mm",
  ""
); //=> "Fri Jan 01, 2016 at 13:41"

// ex. 2
tryFormatDate(
  "",
  "EEE MMM dd, yyyy 'at' HH:mm",
  "n/a"
); //=> "n/a"

// ex. 3
const payload = { id: 123, createdAt: "2016-01-01 13:41:51.000" };
const createdAtParsed = payload.createdAt && tryFormatDate(
  payload.createdAt,
  "EEE MMM dd, yyyy 'at' HH:mm",
  ""
); //=> "Fri Jan 01, 2016 at 13:41"

first

first
Parameters
xs (Array<T>)
Returns
(T | undefined):
Example
const xs = ["a", "b", "c"];

first([]); //=> undefined

first(xs); //=> "a"

delete xs[0];
first(xs); //=> "b"

delete xs[1];
first(xs); //=> "c""

delete xs[2];
first(xs); //=> undefined

concat

concat
Parameters
x (Array<T>)
Returns
function (xs: Array<T>): Array<T>:

flatten2d

flatten2d
Parameters
xs (Array<T>) An array of primitive-laden arrays.
Returns
Array<T>: The arrays merged into one.
Example
flatten2d([[1,2,3], [4,5,6]]); //=> [1,2,3,4,5,6]

head :: [a] -> [a]

head
Parameters
xs (Array<T>)
Returns
Array<T>:

includes

includes
Parameters
x (any)
Returns
function (array): boolean:

makeRangesBetween

makeRangesBetween(positions: Array<number>)
Parameters
positions (Array<number>) An array of numbers where each number in the array should be greater than the previous number.
Example
makeRangesBetween([0]); //=> [[0,0]]
makeRangesBetween([3,21,41,136]); //=> [[0,3], [3,21], [21,41], [41,136]]
makeRangesBetween([0,-22,3,5,-7,136]); //=> [[0,-22], [-22,3], [3,5], [5,-7], [-7,136]]

searchOnKeysLenient

Extracts those objects having the exact value on one or more of the specified keys.

searchOnKeysLenient(searchTerm: string, data: array, keys: array)
Parameters
searchTerm (string) The term to search fo each filter.
data (array) A 1-d array of objects.
keys (array) A 1-d array of keys to look up values for in the data array.

searchOnKeysStrict

Extracts those objects having the exact value on every single specified key.

searchOnKeysStrict(searchTerm: string, data: array, keys: array)
Parameters
searchTerm (string) Value to match against.
data (array) A 1-d array of objects.
keys (array) A 1-d array of keys to look up values for in the data array.

shuffle

shuffle(xs: array): array
Parameters
xs (array)
Returns
array:
Related
https://stackoverflow.com/a/46545530/1727232 https://en.wikipedia.org/wiki/Schwartzian_transform

tail

tail :: [a] -> a

tail
Parameters
xs (Array<any>)
Returns
Array<any>:

unique

unique
Parameters
xs (array) A 1d array of primitives.
Returns
Array<any>:
Example
unique([]); //=> []
unique([1,1,2,3]); //=> [1,2,3]
unique(["a","b","b","c"]); //=> ["a","b","c"]

add

Adds two numbers together.

add(x: Number, y: Number): Number
Parameters
x (Number)
y (Number)
Returns
Number: The sum of adding two numbers.

get

get
Parameters
propName (string)
Returns
(function (x: Object): any | undefined): v of <k,v> or undefined

hasKeys

hasKeys
Parameters
obj (object)
Returns
boolean:

hasKeys

hasKeys
Parameters
obj (Object)
Returns
Boolean:

keys

keys
Parameters
obj (object)
Returns
Array<string>:

append

append
Parameters
appendWith (String)
Returns
function (target: String): String:
Example
append ("Hello ") ("world"); //=> "Hello world"

capitalize

capitalize
Parameters
x (String)
Returns
String:

chunkStringByIndices

chunkStringByIndices(s: string, indices: any): Array<string>
Parameters
s (string)
indices (any)
Returns
Array<string>:
Example
const str = "The quick brown fox jumps over the lazy dog";
const actual = chunkStringByIndices(str, [[0,3],[3,6]]);

const expected = [
  { segment: ["The", "quick", "brown"], keyword: false },
  { segment: ["fox"], keyword: true },
  { segment: ["jumps", "over"], keyword: false }
];

const actual2 = chunkStringByIndices(str, [[0,3],[3,6],[6,9]]);

const expected2 = [
  { segment: ["The", "quick", "brown"], keyword: false },
  { segment: ["fox"], keyword: true },
  { segment: ["jumps", "over"], keyword: false },
  { segment: ["the"], keyword: true },
  { segment: ["lazy", "dog"], keyword: false }
];

chunkStringByKeywords

Breaks apart a string where keywords are found.

chunkStringByKeywords(s: string, keywords: Array<string>): Array<Object<string, Array<TextFragment>>>
Parameters
s (string)
keywords (Array<string>)
Returns
Array<Object<string, Array<TextFragment>>>:
Example
const text = "The quick brown dog jumped over the fox, but why did the dog not bark?";
const actual = chunkStringByKeywords(text, ["brown", "dog"]);

const expected = [
  { segment: ["The", "quick"], keyword: false },
  { segment: ["brown"], keyword: true },
  { segment: [], keyword: false },
  { segment: ["dog"], keyword: true },
  {
    segment: ["jumped", "over", "the", "fox,", "but", "why", "did", "the"],
    keyword: false
  },
  { segment: ["dog"], keyword: true },
  { segment: ["not", "bark?"], keyword: false }
];

findKeyword

Splits the string into an array and finds the indices where the keyword is found using a wildcard search on the end of the keyword.

findKeyword(s: string, keyword: string): Array<number>
Parameters
s (string)
keyword (string)
Returns
Array<number>: An array containing the array indices (if any) of where each keyword was after splitting the string into words.
Example
findKeyword("The quick brown fox jumps over the lazy dog", "the"); //=> [0,6]

findKeywords

Given a string, will perform a wildcard search on the exploded string for each supplied keyword and return an array of index positions found for each keyword.

Searching is case insensitive.

findKeywords(s: string, keywords: Array<string>): Object<string, Array<number>>
Parameters
s (string)
keywords (Array<string>)
Returns
Object<string, Array<number>>: An object containing the keyword and an array of numbers representing the index positions of the supplied string exploded on whitespace.
Example
const s = "The quick brown fox jumps over the lazy dog";
findKeywords(s, ["the","dog"]); //=> { "the": [0,6], "dog": [8] }

TextFragment

TextFragment

Type: {segment: Array<string>, keyword: Boolean}

getBufferedTextFragmentsAroundKeywords

getBufferedTextFragmentsAroundKeywords(text: string, keywords: Array<string>, wordBuffer: number): Object<string, Array<TextFragment>>
Parameters
text (string)
keywords (Array<string>)
wordBuffer (number)
Returns
Object<string, Array<TextFragment>>:
Example
const text = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure?";
const actual = getBufferedTextFragmentsAroundKeywords(
  text,
  ["pleasure", "great", "responsible"],
  3
);

const expected = {
  pleasure: [
    [
      { segment: ["idea", "of", "denouncing"], keyword: false },
      { segment: ["pleasure"], keyword: true },
      { segment: ["and", "praising", "pain"], keyword: false }
    ],
    [
      { segment: ["dislikes,", "or", "avoids"], keyword: false },
      { segment: ["pleasure"], keyword: true },
      { segment: ["itself,", "because", "it"], keyword: false }
    ],
    [
      { segment: ["because", "it", "is"], keyword: false },
      { segment: ["pleasure,"], keyword: true },
      { segment: ["but", "because", "those"], keyword: false }
    ],
    [
      { segment: ["how", "to", "pursue"], keyword: false },
      { segment: ["pleasure"], keyword: true },
      { segment: ["rationally", "encounter", "consequences"], keyword: false }
    ],
    [
      { segment: ["him", "some", "great"], keyword: false },
      { segment: ["pleasure."], keyword: true },
      { segment: ["To", "take", "a"], keyword: false }
    ],
    [
      { segment: ["to", "enjoy", "a"], keyword: false },
      { segment: ["pleasure"], keyword: true },
      { segment: ["that", "has", "no"], keyword: false }
    ],
    [
      { segment: ["produces", "no", "resultant"], keyword: false },
      { segment: ["pleasure?"], keyword: true },
      { segment: [], keyword: false }
    ]
  ],
  great: [
    [
      { segment: ["teachings", "of", "the"], keyword: false },
      { segment: ["great"], keyword: true },
      { segment: ["explorer", "of", "the"], keyword: false }
    ],
    [
      { segment: ["procure", "him", "some"], keyword: false },
      { segment: ["great"], keyword: true },
      { segment: ["pleasure.", "To", "take"], keyword: false }
    ]
  ],
  responsible: []
};

getSurroundingWords

Retrieves a string fragment padded with words around some word positioned at index.

getSurroundingWords(s: string, index: number, numOfWords: number): string
Parameters
s (string) The targeted string.
index (number) The array position identifying the desired word once the string has been split on whitespace.
numOfWords (number) The buffer of words before and after the word as identified by index .
Returns
string:
Example
const words = "hello world how are you doing today";

getSurroundingWords(words, 0, 0); //=> "hello"
getSurroundingWords(words, 0, 1); //=> "hello world"
getSurroundingWords(words, 2, 1); //=> "world how are"
getSurroundingWords(words, 2, 2); //=> "hello world how are you"
getSurroundingWords(words, 2, 3); //=> "hello world how are you doing"
getSurroundingWords(words, 2, 4); //=> "hello world how are you doing today"

getSurroundingWordsAroundKeywords

getSurroundingWordsAroundKeywords(s: string, keywords: Array<string>, wordBuffer: number): Object<string, Array<string>>
Parameters
s (string)
keywords (Array<string>)
wordBuffer (number) The amount of words around a keyword to return for all instances of keyword matches.
Returns
Object<string, Array<string>>: For each keyword found in the source string, returns a text fragment with a word buffer starting from the keyword position.
Example
const source = "The quick brown fox jumps over the lazy dog but, why did the dog not bark at the fox.";
const textSurroundingKeywords = getSurroundingWordsAroundKeywords(source, ["dog","lazy"], 2);

const output = {
  dog: [
    "the lazy dog but, why",
    "did the dog not bark"
  ],
  lazy: [
    "over the lazy dog but,"
  ]
};

joinWithComma

joinWithComma
Parameters
xs (Array<String>)
Returns
String:

joinWithNewLine

joinWithNewLine
Parameters
xs (Array<String>)
Returns
String:

joinWithSpace

joinWithSpace
Parameters
xs (Array<String>)
Returns
String:

lowerCase

lowerCase
Parameters
x (String)
Returns
String:

maybePluralize

maybePluralize
Parameters
condition (boolean)
Returns
function (word: string): string:
Example
maybePluralize(xs.length > 1)("result"); //=> "results"

`${[].length} ${maybePluralize([].length > 1)("result")} found.`; //=> "0 result found"
`${["a"].length} ${maybePluralize(["a"].length > 1)("result")} found.`; //=> "1 result found"
`${["a","b"].length} ${maybePluralize(["a","b"].length > 1)("result")} found.`; //=> "2 results found"

properCase

properCase
Parameters
x (string)
Returns
string:

removeCommas

removeCommas
Parameters
x (String)
Returns
String:
Example
removeCommas("hello,world"); //=> "helloworld"
removeCommas("hello, world"); //=> "hello world"
removeCommas("a,b,c"); //=> abc

removeNonDigits

removeNonDigits :: String -> String

removeNonDigits
Parameters
x (string)
Returns
string:
Example
removeNonDigits ("foo123bar"); //=> 123

replaceCommaWithWhitespace

Replaces all occurrences of commas with a single space ensuring to truncate two or more resulting adjacent spaces to a single space.

In practice, this means that a comma at the beginning or the end of a string will be replaced with a whitespace but will not be trimmed.

replaceCommaWithWhitespace :: String -> String

replaceCommaWithWhitespace

Type: (any | Array<any>)

Example
replaceCommaWithWhitespace("hello,,, world"); //=> "hello world"
replaceCommaWithWhitespace(",hello, world"); //=> " hello world"
replaceCommaWithWhitespace("hello, world,"); //=> "hello world "
replaceCommaWithWhitespace(",hello,world,"); //=> " hello world "

replaceNonNumericChars

replaceNonNumericChars
Parameters
x (String)
Returns
String:
Example
replaceNonNumericChars("a1b2c3"); //=> "123"

replaceNonNumericDashChars

replaceNonNumericDashChars
Parameters
x (String)
Returns
String:
Example
replaceNonNumericChars("a1-b2-c3"); //=> "1-2-3"

replaceString

A curried wrapper around the native string.replace function. Function is extracted from the sanctuary.js docs.

Does not truncate whitespace.

replaceString :: (String -> (String -> String)) -> String

replaceString
Related
{ https://sanctuary.js.org/#curry3} { https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace}
Example
replaceString ("bar") ("") ("foo bar baz"); //=> "foo  bar" (note the double space)
replaceString (/a/gi) ("") ("foo bar baz"); //=> "foo br bz"

split

split
Parameters
x (String)
Returns
Array<String>:

splitAt

splitAt :: Number -> [A] -> [A]

splitAt
Parameters
k (number)
Returns
function (array): [[], []]:
Example
splitAt (2) (["a","b","c","d","e"]); //=> [["a","b"],["c","d","e"]]

splitComma

Returns array of substrings resulting from splitting the original string wherever a comma was found.

splitComma :: String -> [String]

splitComma
Returns
String:
Example
splitComma ("foo,bar,baz"); //=> ["foo", "bar", "baz"]
splitComma ("foo, bar, baz"); //=> ["foo", " bar", " baz"]
splitComma (""); //=> [""]

splitCommaRegex

Returns array of substrings resulting from splitting the original string wherever a comma was found.

splitComma :: String -> [String]

splitCommaRegex
Returns
String:
Example
splitCommaRegex ("foo,bar,baz"); //=> ["foo", "bar", "baz"]
splitCommaRegex ("foo, bar, baz"); //=> ["foo", " bar", " baz"]
splitCommaRegex (""); //=> [""]

splitNewLines

Breaks apart a string into an array of substrings wherever newline chars are found - these are \r\n and \n.

splitComma :: String -> [String]

splitNewLines
Returns
String:
Example
splitNewLines ("hello \n world"); //=> ["hello ", " world"]
splitNewLines ("hello \r\n world"); //=> ["hello ", " world"]
splitNewLines ("hello \n \n \n world"); //=> ["hello ", " ", " ", " world"]
splitNewLines (""); //=> [""]

splitOn

splitOn :: string -> string -> string[]

splitOn
Parameters
delimiter (string)
Returns
function (x: string): Array<string>:
Example
splits(";")("hello;world"); //=> ["hello", "world"]
splits(";")("hello;world;"); //=> ["hello", "world", ""]

splitSpace

Breaks apart a string into its array of substrings wherever the ASCII 32 SPACE character is found.

splitSpace :: String -> [String]

splitSpace
Returns
String:
Example
splitSpace ("foo bar baz"); //=> ["foo", "bar", "baz"]
splitSpace ("hello   world"); //=> ["hello", "", "", "world"]
splitSpace (""); //=> [""]

splitSpaceRegex

Breaks apart a string into its array of substrings wherever the ASCII 32 SPACE character is found.

splitSpaceRegex :: String -> [String]

splitSpaceRegex
Returns
String:
Example
splitSpaceRegex ("foo bar baz"); //=> ["foo", "bar", "baz"]
splitSpaceRegex ("hello   world"); //=> ["hello", "", "", "world"]
splitSpaceRegex (""); //=> [""]

splitWhitespace

Breaks apart a string into its array of substrings wherever whitespace characters are found.

This corresponds to all whitespace characters represented by the \s metacharacter in regex.

splitWhitespace :: String -> [String]

splitWhitespace
Returns
String:
Related
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-white-space All examples from @{splitSpace} and @{splitSpaceRegex} work in addition to all the remaining forms of whitespace characters.
Example
splitWhitespace ("hello \t world"); //=> "hello", "", "", "world"

titleCase

titleCase(x: string): string
Parameters
x (string)
Returns
string:

trim

trim
Parameters
x (String)
Returns
String:

truncateSpace

Truncates contiguous ASCII 32 SPACE chars into one.

truncateSpace :: String -> String

truncateSpace
Returns
String:
Related
https://stackoverflow.com/a/7151225/1727232 https://stackoverflow.com/a/1279878/1727232
Example
truncateSpace ("hello   world"); //=> "hello world"

truncateWhitespace

Truncates all whitespace chars to a single space char.

truncateWhitespace :: String -> String

truncateWhitespace
Returns
String:
Related
https://stackoverflow.com/a/1279874/1727232
Example
truncateWhitespace ("hello   world"); //=> "hello world"
truncateWhitespace ("foo \t \v bar"); //=> "foo bar"

upperCase

upperCase
Parameters
x (String)
Returns
String:

wrapInParens

wrapInParens
Parameters
s (string)
Returns
string:

wrapWithSpace

wrapWithSpace
Parameters
s (string)
Returns
string:

define

define
Parameters
dict (Object) An object of <k,v> items
Returns
function (k: string): string: Function expecting a key to lookup in the dict.
Example
const dict = { GL: "Gold", SI: "Silver" };

define (dict) ("GL"); //=> "Gold"
define (dict) ("CL"); //=> "CL"

delay

delay(milliseconds: Number): Promise<undefined>
Parameters
milliseconds (Number)
Returns
Promise<undefined>:

formatNumberWithComma

Note that decimal figures are dropped off.

formatNumberWithComma
Parameters
num (number)
Returns
string:
Example
formatNumberWithComma(100000); //=> "100,000"

hexToBase64

hexToBase64(hexstring: string): string
Parameters
hexstring (string)
Returns
string:

makeTimeSpent

makeTimeSpent
Parameters
hours (number)
minutes (number)
Returns
string:
Example
makeTimeSpent(0, 0); //=> ""
makeTimeSpent(1, 0); //=> "1 hr"
makeTimeSpent(7, 0); //=> "7 hrs"
makeTimeSpent(0, 1); //=> "1 min"
makeTimeSpent(0, 7); //=> "7 mins"
makeTimeSpent(1, 1); //=> "1 hr, 1 min"
makeTimeSpent(1, 7); //=> "1 hr, 7 mins"
makeTimeSpent(7, 1); //=> "7 hrs, 1 min"

parseFloats

parseFloats
Parameters
xs (Array<String>)
Returns
Array<Number>:
Example
const parsedFloats = parseFloats(["-79.8620667737253", "43.52457849715662"]);

console.log(parsedFloats); //=> [-79.8620667737253, 43.52457849715662]

prototype

prototype
Parameters
x (any)
Returns
String:
Example
prototype({});        //=> "[object Object]"
prototype([]);        //=> "[object Array]"
prototype(7);         //=> "[object Number]"
prototype("");        //=> "[object String]"
prototype(true);      //=> "[object Boolean]"
prototype(false);     //=> "[object Boolean]"
prototype(null);      //=> "[object Null]"
prototype(undefined); //=> "[object Undefined]"
prototype(void 0);    //=> "[object Undefined]"
prototype();          //=> "[object Undefined]"

extractBase64FromDataUrl

extractBase64FromDataUrl
Parameters
dataUrl (string)
Returns
string:

extractMimeTypeFromDataUrl

extractMimeTypeFromDataUrl
Parameters
dataUrl (string)
Returns
string:

readFileBase64MimeType

Returns a promise that resolves to an object containing the base64 and mimetype values of a passed in file.

readFileBase64MimeType(file: File): Promise<{base64: string, mimeType: string}>
Parameters
file (File)
Returns
Promise<{base64: string, mimeType: string}>:

readFileDataUrl

Returns a promise that reads a binary file as a dataUrl (containing a mimetype and a base64 string).

readFileDataUrl(file: File): Promise
Parameters
file (File)
Returns
Promise:

showEither

showEither :: String -> String -> String

showEither
Parameters
fallback (string)
Returns
function (x: string): string: The fallback will always be returned when an empty string or non-string values are supplied for x .
Example
// ex. 1
showEither("n/a")("blue"); //=> "blue"
showEither("n/a")(" ");    //=> " "
showEither("n/a")("");     //=> "n/a"
showEither("n/a")(null);   //=> "n/a"
showEither("n/a")(false);  //=> "n/a"
showEither("n/a")(0);      //=> "n/a"

// ex. 2
const personName = "John";
showEither("n/a")(!!personName ? `Hello ${personName}` : null); //=> "Hello John"

// ex. 3
showEither("n/a")(appendText(" kg")(toSignificantFigures(0)(80.55))); //=> "80 kg"

toSignificantFigures

toSignificantFigures
Parameters
figures (any)
Returns
function (target: String): String: False when the target cannot be parsed, otherwise the string representation of the number rounded to significant figures.
Example
toSignificantFigures (2) ("abc"); //=> false
toSignificantFigures (2) (100.999); //=> "100.99"

toString

toString :: * -> String

toString(x: any): string
Parameters
x (any)
Returns
string: