jstuff
v1.1.0
Published
some useful stuff javascript is missing
Downloads
1
Readme
Jstuff
Javascript is missing a lot, so I made this.
Use in Node.js
npm install jstuff
Then, require the whole package:
const jstuff = require('jstuff')
Or pick specific sections:
const jstuff = require('jstuff/math')
Or even just use specific methods:
const { log } = require('jstuff/math')
Use in javascript
Source the main script:
<script src='unpkg.com/jstuff/jstuff.js'></script>
Or pick specific sections:
<script src='unpkg.com/jstuff/math.js'></script>
Docs generated with jsdoc2md.
API
Array functions
riffle(...args) ⇒ Array
Riffle shuffle two or more arrays
Kind: global function
Returns: Array - Shuffled array
| Param | Type | Description | | --- | --- | --- | | ...args | Array | Arrays to be shuffled |
max(array) ⇒ num
Largest number in array
Kind: global function
Returns: num - Max of array
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to find max of |
min(array) ⇒ num
Smallest number in array
Kind: global function
Returns: num - Min of array
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to find min of |
mean(array) ⇒ num
Average of array
Kind: global function
Returns: num - Mean of array
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to find mean of |
order(array) ⇒ Array
Sorts numerical array
Kind: global function
Returns: Array - sorted array
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to sort |
median(array) ⇒ num
Median of numerical array
Kind: global function
Returns: num - Median of array
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to find median of |
mode(array) ⇒ string | number
Most common value (string/number) in array
Kind: global function
Returns: string | number - Most common value
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to find mode of |
unique(array) ⇒ Array
Remove duplicate values
Kind: global function
Returns: Array - Array with no duplicates
| Param | Type | Description | | --- | --- | --- | | array | Array | Input array |
rlencode(array) ⇒ string
Run length encodes an array into a string
Kind: global function
Returns: string - Run length encoded string
| Param | Type | Description | | --- | --- | --- | | array | Array | Array to encode (string only) |
range(array) ⇒ number
Finds the range of an array
Kind: global function
| Param | Type | | --- | --- | | array | Array |
String functions
log(num, base) ⇒ number
Take the logarithm, with a certain base, of a certain number
Kind: global function
Returns: number - Logarithm of num, base base
.
| Param | Type | Description | | --- | --- | --- | | num | number | Number to take log of | | base | number | Base of log |
parseBigInt(str, radix) ⇒ BigInt
Parse a string into a bigint
Kind: global function
Returns: BigInt - Resulting bigint
| Param | Type | Description | | --- | --- | --- | | str | string | String to parse | | radix | number | Radix to parse by |
factorial(num) ⇒ number | BigInt
Takes the factorial of a number or bigint. Returns bigint if bigint is inputted, otherwise number
Kind: global function
Returns: number | BigInt - Factorial of number
| Param | Type | Description | | --- | --- | --- | | num | number | BigInt | Number to take factorial of |
random(min, max, step) ⇒ number
Generate a random number between two numbers.
Kind: global function
Returns: number - Random number
| Param | Type | Description | | --- | --- | --- | | min | number | Lower bound of number. Inclusive. | | max | number | Upper bound of number. Exclusive. | | step | number | Difference between possible numbers. |
Functions
log(num, base) ⇒ number
Take the logarithm, with a certain base, of a certain number
Kind: global function
Returns: number - Logarithm of num, base base
.
| Param | Type | Description | | --- | --- | --- | | num | number | Number to take log of | | base | number | Base of log |
parseBigInt(str, radix) ⇒ BigInt
Parse a string into a bigint
Kind: global function
Returns: BigInt - Resulting bigint
| Param | Type | Description | | --- | --- | --- | | str | string | String to parse | | radix | number | Radix to parse by |
factorial(num) ⇒ number | BigInt
Takes the factorial of a number or bigint. Returns bigint if bigint is inputted, otherwise number
Kind: global function
Returns: number | BigInt - Factorial of number
| Param | Type | Description | | --- | --- | --- | | num | number | BigInt | Number to take factorial of |
random(min, max, step) ⇒ number
Generate a random number between two numbers.
Kind: global function
Returns: number - Random number
| Param | Type | Description | | --- | --- | --- | | min | number | Lower bound of number. Inclusive. | | max | number | Upper bound of number. Exclusive. | | step | number | Difference between possible numbers. |
bkeith@Bs-MacBook-Air useful % jsdoc2md string.js
String functions
reverse(str) ⇒ string
Reverses a string
Kind: global function
Returns: string - Reversed string
| Param | Type | Description | | --- | --- | --- | | str | string | String to reverse |
chunk(str, num) ⇒ Array
Split a string into chunks
Kind: global function
Returns: Array - Array of chunks
| Param | Type | Description | | --- | --- | --- | | str | string | String to split | | num | number | Length of each chunk |
rot(str, num) ⇒
Rotate a string's alphabet characters.
Kind: global function
Returns: String with alphabet characters rotated by given number
| Param | Type | Description | | --- | --- | --- | | str | string | String to rotate | | num | number | Num to rotate by, default is 13 |
rldecode(str) ⇒ Array
Run length decodes a string
Kind: global function
Returns: Array - Array of values
| Param | Type | Description | | --- | --- | --- | | str | string | String to decode |
changeCase(string, to) ⇒
Convert a string from one case to another. Options: camelCase, PascalCase, kebab-case, SCREAMING-KEBAB-CASE, snake_case, SCREAMING_SNAKE_CASE
Kind: global function
Returns: String changed to different case
| Param | Type | Description | | --- | --- | --- | | string | string | String to change case | | to | string | Case to change. options: 'camel', 'pascal', 'kebab', 'screamkebab', 'snake', 'screamsnake' |