exstat
this is a collection of utility functions that I'm currently working on. I've been using them to work on a cryptography library, so that's what they're geared toward.
usage
npm i exstat
and then
const exstat = require("exstat")
.
exstat has three groups of functions (exstat.array
, exstat.string
, and exstat.number
), named for the type of input they take. example:
const { array: a, string: s, number: n } = require("exstat");
a.normalize([2, 3, 4, 5, 6], [0, 1])
// returns [ 0, 0.25, 0.5, 0.75, 1 ]
n.inRange(0.5, [0, 1])
// returns true
detailed information is below.
functions
- normalize(set, range) ⇒
array
normalize - normalizes an array to a certain range, or the set [0, 1] by default
- median(arr) ⇒
number
median - finds the median of an array
- mean(arr) ⇒
number
mean - finds the median of an array
- toUTF8Array(str) ⇒
array
toUTF8Array - converts a string to a byte array
- binAdd(str1, str2) ⇒
string
binAdd - add two string representations of binary numbers
- binToInt(bin) ⇒
number
binToInt - convert binary number to integer
- trunc(str, len) ⇒
string
trunc - truncate a string to a certain length
- binToHex(str) ⇒
string
binToHex - convert binary number to hex number
- inRange(num, range) ⇒
boolean
inRange - determine wether a number is within a certain range
- mod(a, b) ⇒
number
mod - finds the remainder after division of one number by another
- padZero(num, len) ⇒
string
padZero - pad a number with zeros
normalize(set, range) ⇒ array
normalize - normalizes an array to a certain range, or the set [0, 1] by default
kind: global function
returns: array
- normalized set of numbers
param | type | description |
---|
set | array | set of numbers to normalize |
range | array | range to normalize to |
median(arr) ⇒ number
median - finds the median of an array
kind: global function
returns: number
- the median of the array of numbers
param | type | description |
---|
arr | array | array of numbers |
mean(arr) ⇒ number
mean - finds the median of an array
kind: global function
returns: number
- the median of the array
param | type | description |
---|
arr | array | array of numbers |
toUTF8Array(str) ⇒ array
toUTF8Array - converts a string to a byte array
kind: global function
returns: array
- byte array
param | type | description |
---|
str | string | string to be converted |
binAdd(str1, str2) ⇒ string
binAdd - add two string representations of binary numbers
kind: global function
returns: string
- binary representation of the result of the operation
param | type | description |
---|
str1 | string | first binary string |
str2 | string | second binary string |
binToInt(bin) ⇒ number
binToInt - convert binary number to integer
kind: global function
returns: number
- interger result of binary string
param | type | description |
---|
bin | string | string representation of binary number |
trunc(str, len) ⇒ string
trunc - truncate a string to a certain length
kind: global function
returns: string
- truncated string
param | type | description |
---|
str | string | string to be truncated |
len | number | length to truncate to |
binToHex(str) ⇒ string
binToHex - convert binary number to hex number
kind: global function
returns: string
- hexadecimal number from the result of conversion
param | type | description |
---|
str | string | binary number to convert |
inRange(num, range) ⇒ boolean
inRange - determine wether a number is within a certain range
kind: global function
returns: boolean
- returns true if number is in range, false if not.
param | type | description |
---|
num | number | the number to check |
range | array | the range that num should be within |
mod(a, b) ⇒ number
mod - finds the remainder after division of one number by another
kind: global function
returns: number
- result of operation
param | type | description |
---|
a | number | number to perform modulo operation on |
b | number | number to perform modulo operation on |
padZero(num, len) ⇒ string
padZero - pad a number with zeros
kind: global function
returns: string
- string resulting from padding of number with zeros
param | type | description |
---|
num | number | number to pad |
len | number | final length of resulting string |