Javascript is missing a lot, so I made this.
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')
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.
- riffle(...args) ⇒
Array
Riffle shuffle two or more arrays
- max(array) ⇒
num
Largest number in array
- min(array) ⇒
num
Smallest number in array
- mean(array) ⇒
num
Average of array
- order(array) ⇒
Array
Sorts numerical array
- median(array) ⇒
num
Median of numerical array
- mode(array) ⇒
string
|number
Most common value (string/number) in array
- unique(array) ⇒
Array
Remove duplicate values
- rlencode(array) ⇒
string
Run length encodes an array into a string
- range(array) ⇒
number
Finds the range of an array
Riffle shuffle two or more arrays
Kind: global function
Returns: Array
- Shuffled array
Param | Type | Description |
---|---|---|
...args | Array |
Arrays to be shuffled |
Largest number in array
Kind: global function
Returns: num
- Max of array
Param | Type | Description |
---|---|---|
array | Array |
Array to find max of |
Smallest number in array
Kind: global function
Returns: num
- Min of array
Param | Type | Description |
---|---|---|
array | Array |
Array to find min of |
Average of array
Kind: global function
Returns: num
- Mean of array
Param | Type | Description |
---|---|---|
array | Array |
Array to find mean of |
Sorts numerical array
Kind: global function
Returns: Array
- sorted array
Param | Type | Description |
---|---|---|
array | Array |
Array to sort |
Median of numerical array
Kind: global function
Returns: num
- Median of array
Param | Type | Description |
---|---|---|
array | Array |
Array to find median of |
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 |
Remove duplicate values
Kind: global function
Returns: Array
- Array with no duplicates
Param | Type | Description |
---|---|---|
array | Array |
Input array |
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) |
Finds the range of an array
Kind: global function
Param | Type |
---|---|
array | Array |
- log(num, base) ⇒
number
Take the logarithm, with a certain base, of a certain number
- parseBigInt(str, radix) ⇒
BigInt
Parse a string into a bigint
- factorial(num) ⇒
number
|BigInt
Takes the factorial of a number or bigint. Returns bigint if bigint is inputted, otherwise number
- random(min, max, step) ⇒
number
Generate a random number between two numbers.
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 |
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 |
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 |
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. |
- log(num, base) ⇒
number
Take the logarithm, with a certain base, of a certain number
- parseBigInt(str, radix) ⇒
BigInt
Parse a string into a bigint
- factorial(num) ⇒
number
|BigInt
Takes the factorial of a number or bigint. Returns bigint if bigint is inputted, otherwise number
- random(min, max, step) ⇒
number
Generate a random number between two numbers.
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 |
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 |
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 |
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
- reverse(str) ⇒
string
Reverses a string
- chunk(str, num) ⇒
Array
Split a string into chunks
- rot(str, num) ⇒
Rotate a string's alphabet characters.
- rldecode(str) ⇒
Array
Run length decodes a string
- changeCase(string, to) ⇒
Convert a string from one case to another. Options: camelCase, PascalCase, kebab-case, SCREAMING-KEBAB-CASE, snake_case, SCREAMING_SNAKE_CASE
Reverses a string
Kind: global function
Returns: string
- Reversed string
Param | Type | Description |
---|---|---|
str | string |
String to reverse |
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 |
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 |
Run length decodes a string
Kind: global function
Returns: Array
- Array of values
Param | Type | Description |
---|---|---|
str | string |
String to decode |
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' |