by wd006
A simple, modular, and reusable JavaScript function library providing common math, array, and utility functions.
- Basic math operations
- Number checking utilities
- Array manipulation helpers
- Modular ES6 exports for easy usage
- Clear documentation with usage examples
1- Install the package:
npm install @wd006/js-function-library2- Add the following to the package.json file in your project folder:
"type": "module"3- And import individual modules in your project like this:
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:
-> Node.js (Comes with NPM) — Execute JavaScript code from the terminal.
-> Git (optional) — Clone or download the repository easily
| 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 a 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 | toUpperCase(["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.
