1.1.1 • Published 5 years ago

exstat v1.1.1

Weekly downloads
4
License
ISC
Repository
github
Last release
5 years ago

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

kind: global function returns: array - normalized set of numbers

paramtypedescription
setarrayset of numbers to normalize
rangearrayrange 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

paramtypedescription
arrarrayarray of numbers

mean(arr) ⇒ number

mean - finds the median of an array

kind: global function returns: number - the median of the array

paramtypedescription
arrarrayarray of numbers

toUTF8Array(str) ⇒ array

toUTF8Array - converts a string to a byte array

kind: global function returns: array - byte array

paramtypedescription
strstringstring 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

paramtypedescription
str1stringfirst binary string
str2stringsecond binary string

binToInt(bin) ⇒ number

binToInt - convert binary number to integer

kind: global function returns: number - interger result of binary string

paramtypedescription
binstringstring representation of binary number

trunc(str, len) ⇒ string

trunc - truncate a string to a certain length

kind: global function returns: string - truncated string

paramtypedescription
strstringstring to be truncated
lennumberlength 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

paramtypedescription
strstringbinary 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.

paramtypedescription
numnumberthe number to check
rangearraythe 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

paramtypedescription
anumbernumber to perform modulo operation on
bnumbernumber 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

paramtypedescription
numnumbernumber to pad
lennumberfinal length of resulting string
1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago