1.1.0 • Published 3 years ago

jstuff v1.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

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

ParamTypeDescription
...argsArrayArrays to be shuffled

max(array) ⇒ num

Largest number in array

Kind: global function
Returns: num - Max of array

ParamTypeDescription
arrayArrayArray to find max of

min(array) ⇒ num

Smallest number in array

Kind: global function
Returns: num - Min of array

ParamTypeDescription
arrayArrayArray to find min of

mean(array) ⇒ num

Average of array

Kind: global function
Returns: num - Mean of array

ParamTypeDescription
arrayArrayArray to find mean of

order(array) ⇒ Array

Sorts numerical array

Kind: global function
Returns: Array - sorted array

ParamTypeDescription
arrayArrayArray to sort

median(array) ⇒ num

Median of numerical array

Kind: global function
Returns: num - Median of array

ParamTypeDescription
arrayArrayArray to find median of

mode(array) ⇒ string | number

Most common value (string/number) in array

Kind: global function
Returns: string | number - Most common value

ParamTypeDescription
arrayArrayArray to find mode of

unique(array) ⇒ Array

Remove duplicate values

Kind: global function
Returns: Array - Array with no duplicates

ParamTypeDescription
arrayArrayInput array

rlencode(array) ⇒ string

Run length encodes an array into a string

Kind: global function
Returns: string - Run length encoded string

ParamTypeDescription
arrayArrayArray to encode (string only)

range(array) ⇒ number

Finds the range of an array

Kind: global function

ParamType
arrayArray

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.

ParamTypeDescription
numnumberNumber to take log of
basenumberBase of log

parseBigInt(str, radix) ⇒ BigInt

Parse a string into a bigint

Kind: global function
Returns: BigInt - Resulting bigint

ParamTypeDescription
strstringString to parse
radixnumberRadix 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

ParamTypeDescription
numnumber | BigIntNumber to take factorial of

random(min, max, step) ⇒ number

Generate a random number between two numbers.

Kind: global function
Returns: number - Random number

ParamTypeDescription
minnumberLower bound of number. Inclusive.
maxnumberUpper bound of number. Exclusive.
stepnumberDifference 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.

ParamTypeDescription
numnumberNumber to take log of
basenumberBase of log

parseBigInt(str, radix) ⇒ BigInt

Parse a string into a bigint

Kind: global function
Returns: BigInt - Resulting bigint

ParamTypeDescription
strstringString to parse
radixnumberRadix 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

ParamTypeDescription
numnumber | BigIntNumber to take factorial of

random(min, max, step) ⇒ number

Generate a random number between two numbers.

Kind: global function
Returns: number - Random number

ParamTypeDescription
minnumberLower bound of number. Inclusive.
maxnumberUpper bound of number. Exclusive.
stepnumberDifference 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

ParamTypeDescription
strstringString to reverse

chunk(str, num) ⇒ Array

Split a string into chunks

Kind: global function
Returns: Array - Array of chunks

ParamTypeDescription
strstringString to split
numnumberLength of each chunk

rot(str, num) ⇒

Rotate a string's alphabet characters.

Kind: global function
Returns: String with alphabet characters rotated by given number

ParamTypeDescription
strstringString to rotate
numnumberNum to rotate by, default is 13

rldecode(str) ⇒ Array

Run length decodes a string

Kind: global function
Returns: Array - Array of values

ParamTypeDescription
strstringString 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

ParamTypeDescription
stringstringString to change case
tostringCase to change. options: 'camel', 'pascal', 'kebab', 'screamkebab', 'snake', 'screamsnake'