Members
# (constant) markr
Simple wrapper for chalk
- Since:
- v2.2.0
- Source:
Example
await markr.info('Hello world')
await markr.success('Hello world')
await markr.warn('Hello world')
await markr.warn('Hello world')
# (constant) spinner
Namespace for console spinner (Node.js only)
- Since:
- v2.1.1
- Source:
Methods
# abbr(string, keepCaseopt)
Abbreviates a given string
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string | string | The string to abbreviate | ||
keepCase | boolean | <optional> | false | Whether to keep the case of the string (eg lowercase to uppercase, or unchanged) |
- Since:
- v3.0.0
- Source:
string
abbr('Attack of the Clones') // => AOTC
abbr('Attack of the Clones', true) // => AotC
# afterEl(array, el)
Gets the values of an array after the specified element, not including the element at the position specified.
Name | Type | Description |
---|---|---|
array | array | The array to get the value from |
el | * | The element in the array that values will be taken from after |
- Since:
- v1.1.2
- Source:
Array
afterEl([1, 2, 3, "hello", "5", 6, 7, 8], "hello")
# afterPos(array, position)
Gets the values of an array before the specified position, not including the element at the position specified.
Name | Type | Description |
---|---|---|
array | array | The array to get the value from |
position | number | The position that values will be retrieved from after (let's say |
- Since:
- v1.1.2
- Source:
Array
beforePos([1, 2, 3, 4, 5, 6, 7, 8], 4)
# arrayify(value)
Turns a value into an array
Name | Type | Description |
---|---|---|
value | * | The value to add to a new array |
- Since:
- v0.1.3
- Source:
Array
arrayify('Hello') //=> ['Hello']
# assert(condition, message, throwErropt)
A simple assert function
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
condition | expression | The condition for the check to pass, for example | ||
message | string | Check failed | The message to throw as an error if the check does not pass | |
throwErr | boolean | <optional> | true | The message to throw as an error if the check does not pass |
- Since:
- v1.0.1
- Source:
Array
assert(typeof 'object' === 'object', '', false) // this does not crash the script and does not show any errors
# atob(string)
Encodes a string into Base 64
Name | Type | Description |
---|---|---|
string | string | The value convert to Base 64 |
- Since:
- v0.1.3
- Source:
string
atob('hello') //=> aGVsbG8=
# beforeEl(array, position)
Gets the values of an array before the specified element, not including the element at the position specified.
Name | Type | Description |
---|---|---|
array | array | The array to get the value from |
position | number | The element in the array that values will be taken from before |
- Since:
- v1.1.2
- Source:
Array
beforeEl([1, 2, 3, "four", 5, "6", 7, 8], "four")
# beforePos(array, position)
Gets the values of an array before the specified position, not including the element at the position specified.
Name | Type | Description |
---|---|---|
array | array | The array to get the value from |
position | number | The position that values will be retrieved from before (let's say |
- Since:
- v1.1.2
- Source:
Array
beforePos([1, 2, 3, 4, 5, 6, 7, 8], 4)
# binarySearch(array, key) → {number}
Conducts a binary search on an array with the given key and returns the index of the key. The return behaviour of this function is the same as Array.prototype.indexOf()
.
Name | Type | Description |
---|---|---|
array | Array.<any> | The array to get the index of the given key from. IMPORTANT NOTE: The array provided must be sorted |
key | * | The key to search for |
- Since:
- v3.10.0
- Source:
- Type
- number
binarySearch
# btoa(string)
Dencodes a Base 64 string
Name | Type | Description |
---|---|---|
string | string | The value decode |
- Since:
- v0.1.3
- Source:
string
btoa('aGVsbG8=') //=> hello
# camelCase(string)
Turns a string into camel case
Name | Type | Description |
---|---|---|
string | string | The string to turn into camel case |
- Since:
- v1.1.3
- Source:
string
camelCase('Hello there') //=> 'helloThere'
# chunk(array, lengthopt)
Splits an array into chunks
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
array | array | The array to split | ||
length | number | <optional> | 1 | The number of elements in each chunk |
- Since:
- v2.5.2-beta.5
- Source:
array - The array of chunks
chunk(['a', 'b', 'c', 'd'], 2);
# circleArea(radius, piopt) → {number}
Gets the area of a circle with a given radius
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
radius | number | The radius of the circle | ||
pi | number | <optional> | Math.PI | The value of pi |
- Since:
- v3.8.0
- Source:
- Type
- number
circleArea(9) // => 254.46900494077323
# compact(string)
Removes line breaks, trims whitespaces, and reduces all spaces with more than 1 space to 1 space
Name | Type | Description |
---|---|---|
string | string | The string to |
- Since:
- v0.4.4
- Source:
string
let str = `I'm
a multiline
string!`
compact(str) //=> "I'm a multiline string"
# deMorse(string)
Converts morse code to string
Name | Type | Description |
---|---|---|
string | string | The string to convert |
- Since:
- v2.5.2-beta.8
- Source:
string
deMorse('... --- ... / .... . .-.. .--.')
# diff(arr1, arr2) → {Array}
Finds the difference between two arrays
Name | Type | Description |
---|---|---|
arr1 | Array | The first array to compare |
arr2 | Array | The second array to compare |
- Since:
- v2.5.2-beta.4
- Source:
- Type
- Array
const arr1 = [1,2,3];
const arr2 = [2,3];
diff(arr1, arr2); //=> [1]
# ellipsis(string, position, options)
Splits the text at the specified character position (number) and replace the text behind it with an ellipsis (...)
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
string | string | The string to edit | ||||||||||
position | number | The position to split the string at | ||||||||||
options | object | The options to pass to the function Properties
|
- Since:
- v0.4.9
- Source:
string
ellipsis('Hello! I am Joe!', 5, { ellipsis: '....' }) //=> 'Hello....'
# fill(arr, value, startopt, endopt) → {Array}
Fills elements of array with value from start
up to, but not including, end
.
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
arr | Array | The array to fill | ||
value | * | The value to fill the array with | ||
start | number | <optional> | 0 | The start position |
end | number | <optional> | arr.length | The end position |
- Since:
- v3.5.0
- Source:
- Type
- Array
fill(Array(5), 'a') // => ['a', 'a', 'a', 'a', 'a']
# flatten(array)
Flattens array
Name | Type | Description |
---|---|---|
array | array | The array flatten |
- Since:
- v0.4.5
- Source:
array
flatten([[[1, [1.1]], 2, 3], [4, 5]]); //=> [1, 1.1, 2, 3, 4, 5]
# formatNumber(number, thousandsSeparatoropt) → {String}
Formats a number (aka insert thousands separator)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
number | Number | The number to format | ||
thousandsSeparator | String | <optional> | , | The thousands separator |
- Since:
- v3.6.0
- Source:
- Type
- String
formatNumber(1000) // => '1,000'
# getBrowser()
Find the browser information (includes code from this SO post).
- Since:
- v2.12.0
- Source:
String
getBrowser();
# (async) getOS()
Find the OS information (includes code from this SO post). (PS This is nowhere as polished as libraries dedicated to only detecting the OS details)
- Since:
- v2.11.0
- Source:
String
await getOS();
# hexToRgb(hex)
Converts an Hexadecimal color code to RGB
Name | Type | Description |
---|---|---|
hex | String | The hexadecimal color code |
- Since:
- v2.9.0
- Source:
string
Tess.hexToRgb(''#ff64c8') ///=> 255, 100, 200
# includes(value, array)
Returns true if the given n-dimensional array contains a given value
Name | Type | Description |
---|---|---|
value | * | The value to search for in the array |
array | array | The array to search for the given value |
- Since:
- v2.10.0
- Source:
Boolean
includes(2, [[[1,3,5],2]])
# isNil(value)
Returns true if the value is null or undefined
Name | Type | Description |
---|---|---|
value | * | The value to check |
- Since:
- v0.0.1
- Source:
boolean
isNill(null) //=> true
isNill(undefined) //=> true
isNill('') //=> false
isNill([]) //=> false
isNill({}) //=> false
# isString(value)
Checks if the given value is a string.
Name | Type | Description |
---|---|---|
value | * | The value to check. |
- Since:
- v2.5.2-beta.1
- Source:
string
isString('value') // true
# kebabCase(string)
Turns a string into kebab case
Name | Type | Description |
---|---|---|
string | string | The string to turn into kebab case |
- Since:
- v3.4.0
- Source:
string
kebabCase('hello there') //=> hello-there
# m(metres, toopt)
Converts metres to a different unit or vice-versa
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
metres | Number | The amount to convert | ||
to | String | <optional> | km | What the metres should be converted to Accepted units: |
- Since:
- v2.5.2-beta.3
- Source:
string
m('1 km', 'm') // 1000
# mean(numbers) → {number}
Gets the mean for an array of numbers
Name | Type | Description |
---|---|---|
numbers | Array.<number> | The array to get the mean from |
- Since:
- v3.7.0
- Source:
- Type
- number
mean([1, 6, 8, 16, 28]) // => 11.8
# median(numbers)
Gets the median for an array of numbers
Name | Type | Description |
---|---|---|
numbers | Array.<Number> | The array to get the median from |
- Since:
- v3.7.0
- Source:
number
median([8, 6, 1, 16, 28]) // => 8
# mode(numbers)
Gets the mode for an array of numbers
Name | Type | Description |
---|---|---|
numbers | Array.<number> | The array to get the mean from |
- Since:
- v3.7.0
- Source:
number
mode([1, 6, 8, 16, 28, 8]) // => 8
# numeronym(string)
Turns a word into a numeronym
Name | Type | Description |
---|---|---|
string | string | The string to turn into a numeronym |
- Since:
- v3.2.0
- Source:
string
numeronym('internationalization') // => i18n
# pascalCase(string)
Turns a string into pascal case
Name | Type | Description |
---|---|---|
string | string | The string to turn into pascal case |
- Since:
- v1.1.3
- Source:
string
pascalCase('hello there') //=> 'HelloThere'
# pickRan(array) → {*}
Picks a random item from an array
Name | Type | Description |
---|---|---|
array | array | The array to pick the item from |
- Since:
- v0.4.1
- Source:
- Type
- *
let array = ['1', '2', '3', '4', '5']
pickRan(array)
# (async) progressBar(typeopt, numberopt, numberopt)
Creates a console progress bar (Node.js only)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type | number | <optional> | 1 | The type of the progress bar |
number | number | <optional> | 80 | The time in |
number | number | <optional> | 20 | The number length of the progress bar |
- Since:
- v2.1.1
- Source:
Promise
progressBar(1, 80)
//=> [-----------=========] 55%
progressBar(2)
//=> [....................] 100%
# ranBool()
Selects a random boolean (true/false)
- Since:
- v0.2.0
- Source:
Boolean
ranBool()
# ranFloat(min, max)
Selects a random float point
Name | Type | Description |
---|---|---|
min | number | The smallest number of the range to pick the random float from |
max | number | The largest number of the range to pick the random float from |
- Since:
- v0.2.0
- Source:
number
ranFloat(3,10)
# ranInt(min, max)
Selects a random number
Name | Type | Description |
---|---|---|
min | number | The smallest number of the range to pick the random number from |
max | number | The largest number of the range to pick the random number from |
- Since:
- v0.2.0
- Source:
number
ranInt(3,10)
# ranKey(length)
Generates a random key
Name | Type | Description |
---|---|---|
length | number | The length of the key |
- Since:
- v2.2.0
- Source:
string
ranKey(10)
# reverse(string)
Reverse a string
Name | Type | Description |
---|---|---|
string | string | The string to reverse |
- Since:
- v0.4.9
- Source:
string
reverse('Hello') //=> 'olleH'
# rgbToHex(red, green, blue)
Converts an RGB color code to a hexadecimal string
Name | Type | Description |
---|---|---|
red | number | The amount of red |
green | number | The amount of green |
blue | number | The amount of blue |
- Since:
- v2.9.0
- Source:
string
rgbToHex(255, 100, 200) ///=> #ff64c8
# rmFalsey(array)
Removes falsy values from an array
Name | Type | Description |
---|---|---|
array | array | The array to remove falsey values from |
- Since:
- v0.4.4
- Source:
array
let array = [undefined, null, NaN, 1, 2, 3, 'hello']
rmFalsey(array) //=> [1, 2, 3, 'hello']
# roman(val)
Converts a number to/from Roman Numerals. If the argument received is a string, it will be converted to a number. If the argument received is a number, it will be converted to a roman numeral.
Name | Type | Description |
---|---|---|
val | Number | The value to convert from/to Roman Numerals |
- Since:
- v2.5.2-beta.7
- Source:
number/string
roman('IV')
roman(4)
# shuffle(array)
Shuffles an array
Name | Type | Description |
---|---|---|
array | array | The array to shuffle |
- Since:
- v0.4.8
- Source:
Array
shuffle([1,2,3,4,5,6]) //=> [2,4,3,1,6,5]
# snakeCase(string)
Turns a string into snake case
Name | Type | Description |
---|---|---|
string | string | The string to turn into snake case |
- Since:
- v3.4.0
- Source:
string
snakeCase('hello there') // => hello_there
# sparseEach(array, function)
async
-friendly for-each functions for sparse arrays from this post
This function will make a fine addition to my collection
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
array | array | The array to loop through (The array to s | ||||||||||||||||
function | function | A function to be run for each element in the array. Properties
|
- Since:
- v1.0.1
- Source:
Array
const a = [];
a[5] = "five";
a[10] = "ten";
a[100000] = "one hundred thousand";
a.b = "bee";
sparseEach(a, function(currentValue, index, arr) {
console.log("Value at " + index + " is " + value);
// arr is the array object
});
# squash(…arrays) → {Array}
Squashes all the given arrays. Note: values like undefined × 1
or undefined × 40
are left out and not squashed.
Name | Type | Attributes | Description |
---|---|---|---|
arrays | Array | <repeatable> | The arrays to squash |
- Since:
- v3.1.0
- Source:
- Type
- Array
squash([1, 2], [3, 4]); // => [1, 2, 3, 4]
# stdDev(array)
Gets standard deviation from an array
Name | Type | Description |
---|---|---|
array | Array.<number> | The array to get the standard deviation from |
- Since:
- v2.6.0
- Source:
number
stdDev([1, 6, 8, 16, 28])
# strToNumArray(string, separatoropt) → {Array}
Turns a string into an array of numbers
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
string | string | The string to turn into an array of numbers | ||
separator | string | <optional> | <space> | The separator that is used to separate numbers |
- Since:
- v3.3.0
- Source:
- Type
- Array
strToNumArray('1 2 3 4') // => [1, 2, 3, 4]
# temp(temperature)
Converts a temperature into different units
Name | Type | Description |
---|---|---|
temperature | string | The temperature to convert. You should enter in this format: |
- Since:
- v2.5.2-beta.9
- Source:
object with keys and values of different temperatures. The possible propnames are: K (Kelvin), F (Farenheit), C (Celsius)
Tess.temp('20 C')['F'];
Tess.temp('20 F')['C'];
Tess.temp('100 K')['F'];
# terminalVelocity(density, projectedArea, dragCoefficient, gravityopt) → {function}
Sets the options for the function to calculate the terminal velocity of an object (this is probably gonna be useless)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
density | number | The density of the fluid the object is falling through | ||
projectedArea | number | the projected area of the object. This means the area of the object if you projected it onto a plane that was perpendicular to the direction the object is moving | ||
dragCoefficient | number | the drag coefficient. This number depends on the shape of the object. The more streamlined the shape, the lower the coefficient. | ||
gravity | number | <optional> | 9.8 | the acceleration due to gravity. On Earth this is approximately 9.8 meters per second |
- Since:
- v3.9.0
- Source:
a function that accepts a single parameter (the mass of the falling object)
- Type
- function
# time(time, toopt)
Converts a given time. If the given time is a number, it will be interpreted as minutes. Accepted units:
m, s, h, ms, d, y, us (microsecond), w, mth (month)
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
time | number | string | The amount to convert | ||
to | string | <optional> | ms | What the time should be converted to |
- Since:
- v2.5.8
- Source:
string
time('2 y', 'mth') // 24
# toJSON(Map)
Converts a map to JavaScript objects. To convert to JSON, just use JSON.stringify()
. To get the object back from the string, use JSON.parse()
Name | Type | Description |
---|---|---|
Map | Map | The map to convert to JavaScript objects |
- Since:
- v2.5.2-beta.6
- Source:
Object
const map = new Map([
['foo', 'bar'],
['baz', 42]
]);
const obj = toJSON(map); // get the JS object
const JSONObjectLiteral = JSON.stringify(obj); // get the JSON object literal
const JSObj = JSON.parse(JSONObjectLiteral); // get the JavaScript object back
# toMorse(string)
Converts a string to morse code
Name | Type | Description |
---|---|---|
string | string | The string to convert |
- Since:
- v2.5.2-beta.8
- Source:
string
toMorse('Hello there')
# typeOf(value) → {string}
An improved typeof operator
Name | Type | Description |
---|---|---|
value | * | The value to find the type of |
- Since:
- v2.5.2-beta.5
- Source:
- Type
- string
typeOf(null); //=> null
# uniq(list, compareopt, sortedopt)
Removes duplicate values from an array
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
list | array | The array to remove duplicate values from | ||
compare | function | <optional> | Optional. A function that defines an alternative sort order. The function should return a negative, zero, or positive value, depending on the arguments, like | |
sorted | boolean | <optional> | false | Optional. Whether the array is already sorted |
- Since:
- v0.4.6
- Source:
array
uniq([1, 1, 1.1, 2, 2, 3, 4, 5, 5, 5]) //=> [1, 1.1, 2, 3, 4, 5]
# wait(ms)
wait
s a specific period of time (in ms)
Name | Type | Description |
---|---|---|
ms | number | The amount of time to wait in milliseconds |
- Since:
- v0.4.2
- Source:
promise
(async () => {
console.log('Hi');
await wait(1000);
console.log('Hi after 1 second');
}());
# weight(weight, toopt)
Converts a weight into different units. If the weight received is a number, it will be taken as grams.
Supported units: kg, lb, g, mg, tonne, ton (US Ton), st (stone), oz, mcg
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
weight | string | The weight to convert | ||
to | string | <optional> | g | The unit to convert the weight to |
- Since:
- v2.5.7
- Source:
number
Tess.weight('10 kg', 'g')