rykit-v2
v1.0.1
Published
A multi-purpose JavaScript utility module designed to simplify common programming tasks.
Downloads
19
Maintainers
Readme
RyKit-v2
RyKit-v2 is a multi-purpose JavaScript utility module designed to simplify common programming tasks. It includes a variety of functions for string manipulation, array processing, mathematical operations, and more.
Features
- Deep copying objects: Creates a deep copy of an object, allowing changes to the copied object without affecting the original.
- Random number generation: Generates random numbers within specified ranges.
- Mathematical operations:
- Factorial calculation
- Permutation calculation
- Combination calculation
- Sine, cosine, and tangent calculations for angles in degrees
- UUID generation: Generates a unique identifier (UUID) using the
generateUUID()
function. - SHA-256 hashing: Calculates the SHA-256 hash of a given string.
- Deep equality checking: Compares two objects for deep equality.
- Query parameter extraction: Extracts query parameters from a URL.
- Execution time measurement: Measures the execution time of a given function or code block.
- Async iteration: Implements an asynchronous version of the
forEach()
method using async/await syntax. - Hex-to-RGB and RGB-to-Hex conversions: Converts between hexadecimal color codes and RGB values.
- Array utilities:
- Unique array generation
- Random array element selection
- Shuffling array elements
- Chunks array into specified number of pieces
Installation
Install the module using npm:
npm install rykit-v2
Install the module using yarn:
yarn add rykit-v2
Install the module using bun:
bun add rykit-v2
Usage
Import the functions you need from the module:
const rykit = require("rykit-v2");
Functions
1. getMinecraftServer(ip, options)
Fetches information about a Minecraft server.
const ip = "mc.hypixel.net";
const type = "java";
const server = await rykit.getMinecraftServer(ip, { type });
console.log("Server:", server);
2. replaceWord(text, oldWord, newWord)
Replaces occurrences of oldWord
with newWord
in a given string.
const text = "Hello world! The world is beautiful.";
const newText = rykit.replaceWord(text, "world", "universe");
console.log(newText);
// "Hello universe! The universe is beautiful."
3. joinStrings(array, separator)
Joins an array of strings into a single string with a specified separator.
const words = ["JavaScript", "is", "a", "powerful", "language"];
const joinedSentence = rykit.joinStrings(words, " ");
console.log(joinedSentence);
// "JavaScript is a powerful language"
4. findAndReplace(array, findValue, replaceValue)
Finds all occurrences of findValue
in an array and replaces them with replaceValue
.
const numbers = [1, 2, 3, 4, 5, 3];
const updatedNumbers = rykit.findAndReplace(numbers, 3, 99);
console.log(updatedNumbers);
// [1, 2, 99, 4, 5, 99]
5. sortArray(array, ascending = true)
Sorts an array either in ascending or descending order.
const unsortedArray = [5, 3, 8, 1, 2];
const sortedArrayAsc = rykit.sortArray(unsortedArray); // Ascending
console.log(sortedArrayAsc);
// [1, 2, 3, 5, 8]
const sortedArrayDesc = rykit.sortArray(unsortedArray, false); // Descending
console.log(sortedArrayDesc);
// [8, 5, 3, 2, 1]
6. filterArray(array, callback)
Filters an array based on a provided callback function.
const mixedArray = [1, 2, 3, 4, 5, 6];
const evenNumbers = rykit.filterArray(mixedArray, (num) => num % 2 === 0);
console.log(evenNumbers);
// [2, 4, 6]
7. deleteKey(object, key)
Deletes a specified key from an object.
const person = { name: "John", age: 30, city: "New York" };
const updatedPerson = rykit.deleteKey(person, "age");
console.log(updatedPerson);
// { name: 'John', city: 'New York' }
8. addKey(object, key, value)
Adds a key-value pair to an object.
const person = { name: "John", age: 30, city: "New York" };
const newPerson = rykit.addKey(person, "country", "USA");
console.log(newPerson);
// { name: 'John', age: 30, city: 'New York', country: 'USA' }
9. shallowCopy(object)
Creates a shallow copy of an object.
const originalObj = { a: 1, b: { c: 2 } };
const shallowCopiedObj = rykit.shallowCopy(originalObj);
shallowCopiedObj.b.c = 3;
console.log(originalObj.b.c);
// 3 (Shallow copy affects the original)
10. deepCopy(object)
Creates a deep copy of an object.
const originalObj = { a: 1, b: { c: 2 } };
const deepCopiedObj = rykit.deepCopy(originalObj);
deepCopiedObj.b.c = 4;
console.log(originalObj.b.c);
// 2 (Deep copy does not affect the original)
11. getRandomNumber(min, max)
Generates a random number between min
and max
.
const randomNum = rykit.getRandomNumber(1, 10);
console.log(`Random Number: ${randomNum}`);
// Example: Random Number: 7
12. factorial(n)
Calculates the factorial of a number.
const fact = rykit.factorial(5);
console.log(`5! = ${fact}`);
// 5! = 120
13. permutation(n, r)
Calculates the number of permutations.
const perm = rykit.permutation(5, 3);
console.log(`P(5, 3) = ${perm}`);
// P(5, 3) = 60
14. combination(n, r)
Calculates the number of combinations.
const comb = rykit.combination(5, 3);
console.log(`C(5, 3) = ${comb}`);
// C(5, 3) = 10
15. sin(degrees)
Calculates the sine of an angle in degrees.
const sineValue = rykit.sin(30);
console.log(`sin(30°) = ${sineValue}`);
// sin(30°) = 0.5
16. cos(degrees)
Calculates the cosine of an angle in degrees.
const cosineValue = rykit.cos(60);
console.log(`cos(60°) = ${cosineValue}`);
// cos(60°) = 0.5
17. tan(degrees)
Calculates the tangent of an angle in degrees.
const tangentValue = rykit.tan(45);
console.log(`tan(45°) = ${tangentValue}`);
// tan(45°) = 1
18. generateUUID()
Generates a UUID (Universally Unique Identifier).
const uuid = rykit.generateUUID();
console.log(`Generated UUID: ${uuid}`);
// Example: Generated UUID: 110ec58a-a0f2-4ac4-8393-c866d813b8d1
19. sha256(message)
Calculates the SHA-256 hash of a message.
rykit.sha256("rykit version 2").then((hash) => {
console.log(`SHA-256 Hash: ${hash}`);
// Example: SHA-256 Hash: 5cc790f28fdac9beef4dc298532b71c0b2a5c48af2c818d9d2bc31510aad4173
});
20. deepEqual(obj1, obj2)
Performs a deep equality check between two objects.
const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 3 } };
console.log(rykit.deepEqual(obj1, obj2));
// false
21. getQueryParams(url)
Extracts query parameters from a URL as an object.
const params = rykit.getQueryParams("https://example.com?page=1&limit=10");
console.log(params);
// { page: '1', limit: '10' }
22. measureExecutionTime(callback)
Measures the execution time of a given function.
const executionTime = rykit.measureExecutionTime(() => {
for (let i = 0; i < 1000000; i++) {}
});
console.log(`Execution Time: ${executionTime}ms`);
23. asyncForEach(array, callback)
Asynchronous for-each loop implementation.
rykit.asyncForEach([1, 2, 3], async (num) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
console.log(num);
});
24. rgbToHex(r, g, b)
Converts RGB color values to HEX.
const hexColor = rykit.rgbToHex(255, 87, 51);
console.log(`RGB to Hex: ${hexColor}`);
// RGB to Hex: #FF5733
25. hexToRgb(hex)
Converts HEX color values to RGB.
const rgbColor = rykit.hexToRgb("#ff5733");
console.log(`Hex to RGB: ${rgbColor}`);
// Hex to RGB: rgb(255, 87, 51)
26. uniqueArray(array)
Returns an array with unique values.
const array = [1, 2, 2, 3, 4, 4, 5];
const unique = rykit.uniqueArray(array);
console.log(`Unique Array: ${unique}`);
// Unique Array: [1, 2, 3, 4, 5]
27. getRandomArrayElement(array)
Gets a random element from an array.
const items = ["apple", "banana", "cherry", "orange", "kiwi"];
const randomItem = rykit.getRandomArrayElement(items);
console.log(`Random Array Element: ${randomItem}`);
// Example: Random Array Element: kiwi
28. shuffle(array)
Shuffles the order of elements in an array.
const shuffleFunction = rykit.shuffle(["a", "b", "c", "d", "e", "f"]);
console.log(shuffleFunction);
//[ 'e', 'a', 'd', 'b', 'c', 'f' ]```
29. chunk(array, num)
It divides the array you provide into the number of pieces you specify.
const chunkFunction = rykit.chunk(["a", "b", "c", "d", "e", "f"], 2);
console.log(chunkFunction);
// [ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e', 'f' ] ]