UNPKG

really-usefull-functions

Version:

just some usefull functions for js that makes your life easier writing js

135 lines (96 loc) 3.03 kB
# really-usefull-functions 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. ## Installation Install the package using npm: ```bash npm install really-usefull-functions ``` ## Usage Import the library in your JavaScript project: ```javascript require('really-usefull-functions'); ``` Now you can use the provided global functions. ## Available Functions ### 1. `isEven(num)` Checks if a number is even. ```javascript console.log(isEven(4)); // true console.log(isEven(5)); // false ``` ### 2. `isOdd(num)` Checks if a number is odd. ```javascript console.log(isOdd(5)); // true console.log(isOdd(4)); // false ``` ### 3. `sort_array(array)` 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] ``` ### 3. `PostReq(url, data)` 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 } ``` ### 4. `GetReq(url)` Performs an HTTP GET request. ```javascript async function get() { let res = await GetReq(url) console.log(res); //will log the response from the api } ``` ### 5. `sleep(ms)` Pauses execution for a specified duration. ```javascript sleep(1000).then(() => console.log('Executed after 1 second')); ``` ### 6. `readFromFile(file)` Reads the content of a file. ```javascript async function read() { let res = await readFromFile('./example.txt') console.log(res) } ``` ### 7. `writeToFile(file, data)` Writes data to a file. ```javascript writeToFile('./example.json', data); ``` ### 8. `randomInt(min, max)` Generates a random integer between `min` and `max`. ```javascript console.log(randomInt(1, 10)); // Random number between 1 and 10 ``` ### 9. `getDateTime(input)` 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' ``` ### 10. `csl(...args)` Logs the arguments to the console. ```javascript csl('Hello', 'World!'); // Logs: Hello World! ``` ## Example ```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 ``` ## Contribution Feel free to fork the repository and submit pull requests for new features or bug fixes. Contributions are always welcome! ## License This project is licensed under the MIT License.