std_hlpr
v1.1.6
Published
π **`std_hlpr`** is a simple JavaScript utility package that provides basic statistical functions, such as:
Readme
π¦ std_hlpr
π std_hlpr is a simple JavaScript utility package that provides basic statistical functions, such as:
- Mean (average)
- Standard Deviation
- Z-score (standard score)
- Min-Max Normalization
This package is useful for numeric data preprocessing, such as when you want to normalize data before:
- Statistical analysis
- Data visualization
- Simple machine learning processing on the frontend (e.g., React app or analytics dashboard)
π Features
- β Calculate mean (average)
- β Calculate standard deviation
- β Calculate z-score for a single value or an entire array
- β
Perform Min-Max normalization to scale values from
0 β 1 - β Lightweight and dependency-free
π§ Installation
npm install std-hlprπ Usage Example
// src/App.js (or another file)
import {
mean_s,
std_dev,
z_score_unit,
z_score_array,
std_min_max_array
} from './utils/std_hlpr';
const data = [10, 20, 30, 40, 50];
// Calculate mean
const mean = mean_s(data);
// -> 30
// Calculate standard deviation
const std = std_dev(data, mean);
// -> 14.142...
// Calculate z-score for a single value
const zSingle = z_score_unit(20, mean, std);
// -> -0.707...
// Calculate z-scores for all elements in array
const zAll = z_score_array(data);
/* ->
{
10: -1.414,
20: -0.707,
30: 0,
40: 0.707,
50: 1.414
}
*/
// Perform Min-Max normalization
const norm = std_min_max_array(data);
/* ->
{
10: 0,
20: 0.25,
30: 0.5,
40: 0.75,
50: 1
}
*/π API Reference
mean_s(array)
Calculates the mean of a numeric array.
- Parameter:
array: number[] - Return:
number(mean)
std_dev(array, mean)
Calculates the standard deviation of a numeric array.
- Parameter:
array: number[]mean: number(mean of the array, optional for efficiency) - Return:
number(standard deviation)
z_score_unit(x, mean, std)
Calculates the z-score of a single value.
- Parameter:
x: number(value to calculate)mean: number(dataset mean)std: number(dataset standard deviation) - Return:
number(z-score)
z_score_array(array)
Calculates z-scores for all elements of an array.
- Parameter:
array: number[] - Return:
Record<number, number>(object with original value as key and z-score as value)
std_min_max_array(array)
Performs Min-Max normalization to scale values between 0 β 1.
- Parameter:
array: number[] - Return:
Record<number, number>(object with original value as key and normalized value as value)
π License
MIT License Β© 2025
Free to use for personal or commercial projects. π
