by wd006
A simple, modular, and reusable JavaScript function library providing common math, array, and utility functions.
npm install @wd006/js-function-library
"type": "module"
import { add, subtract } from '@wd006/js-function-library';
This project is written in JavaScript. To run or test the code locally, the following tools are optional but recommended:
Function | Description | Example Usage | Example Output |
---|---|---|---|
add(a, b) |
Adds two numbers | add(2, 3) |
5 |
subtract(a, b) |
Subtracts second number from first | subtract(5, 2) |
3 |
multiply(a, b) |
Multiplies two numbers | multiply(4, 3) |
12 |
divide(a, b) |
Divides first number by second | divide(10, 2) |
5 |
factorial(x) |
Calculates the factorial of a number | factorial(5) |
120 |
isInteger(x) |
Returns true if x is an integer |
isInteger(3.5) |
false |
isEven(x) |
Checks if number is even | isEven(4) |
true |
isOdd(x) |
Checks if number is odd | isOdd(5) |
true |
randomInt(min, max) |
Generates a random integer in the range | randomInt(3, 7) |
5 |
averageOfArray(array) |
Returns the average of an array | averageOfArray([1,2,3]) |
2 |
Function | Description | Example Usage | Example Output |
---|---|---|---|
addToArray(array, element) |
Adds element to end of array | addToArray([1,2], 3) |
[1, 2, 3] |
removeFromArray(array, e) |
Removes element from array | removeFromArray([1,2], 2) |
[1] |
arrayContains(array, e) |
Checks if array contains element | arrayContains([1,2], 2) |
true |
sortArray(array) |
Returns a sorted copy of array | sortArray([3,1,2]) |
[1, 2, 3] |
toUpperCase(array) |
Converts each element to uppercase | toUpperCase(["a", "B", "c"]) |
["A", "B", "C"] |
toLowerCase(array) |
Converts each element to lowercase | toLowerCase(["A", "b", "C"]) |
["a", "b", "c"] |
This project is licensed under the MIT License. You are free to use, modify, and distribute this project for personal or commercial use. See the LICENSE file for full details.
Contributions are welcome! Please feel free to fork the repository, make your changes, and submit a pull request.
For questions or support:
or open an issue on GitHub.