really-usefull-functions
Version:
just some usefull functions for js that makes your life easier writing js
135 lines (96 loc) • 3.03 kB
Markdown
A JavaScript utility library that provides a collection of really useful functions to simplify everyday coding tasks. This package includes a wide array of utilities such as number checks, HTTP requests, file operations, date and time formatting, and more.
Install the package using npm:
```bash
npm install really-usefull-functions
```
Import the library in your JavaScript project:
```javascript
require('really-usefull-functions');
```
Now you can use the provided global functions.
Checks if a number is even.
```javascript
console.log(isEven(4)); // true
console.log(isEven(5)); // false
```
Checks if a number is odd.
```javascript
console.log(isOdd(5)); // true
console.log(isOdd(4)); // false
```
Will sort your array
```javascript
array = [85, 21, 46, 13, 98, 67, 32, 11, 74, 29]
let sorted_array = sort_array(array)
console.log(sorted_array) //this will log: [11, 13, 21, 29, 32, 46, 67, 74, 85, 98]
```
Performs an HTTP POST request.
```javascript
async function post() {
data = {"name": "John"}
let res = await GetReq(url, data)
console.log(res); //will log the response from the api
}
```
Performs an HTTP GET request.
```javascript
async function get() {
let res = await GetReq(url)
console.log(res); //will log the response from the api
}
```
Pauses execution for a specified duration.
```javascript
sleep(1000).then(() => console.log('Executed after 1 second'));
```
Reads the content of a file.
```javascript
async function read() {
let res = await readFromFile('./example.txt')
console.log(res)
}
```
Writes data to a file.
```javascript
writeToFile('./example.json', data);
```
Generates a random integer between `min` and `max`.
```javascript
console.log(randomInt(1, 10)); // Random number between 1 and 10
```
Gets the current date, time, or day.
```javascript
console.log(getDateTime('date')); // e.g., '2025/04/18'
console.log(getDateTime('time')); // e.g., '19:28:20'
console.log(getDateTime('day')); // e.g., 'Fri'
```
Logs the arguments to the console.
```javascript
csl('Hello', 'World!'); // Logs: Hello World!
```
```javascript
require('really-usefull-functions'); // Import the package
csl(isOdd(5)); // Logs: true
csl(randomInt(1, 100)); // Logs a random number between 1 and 100
csl(getDateTime('date')); // Logs the current date
```
Feel free to fork the repository and submit pull requests for new features or bug fixes. Contributions are always welcome!
This project is licensed under the MIT License.