📚 VIETNAMESE Documents: VIEW NOW
react-crazy-utils is a useful library for React that helps you write better code.
You can install react-crazy-utils via bun, npm or yarn:
bash bun add react-crazy-utils
bash npm install react-crazy-utils
bash yarn add react-crazy-utils
This function checks if an object is empty.
console.log("Empty Object?", isEmptyObject(obj)); // Output: true
This function checks if an array is empty.
const arr = [];
console.log("Empty Array?", isEmptyArray(arr)); // Output: true
This function limits the frequency of function calls by delaying execution until when a certain amount of time has passed.
const debouncedFunc = debounce(
() => console.log("Call debounce function"),
300
);
debouncedFunc();
const throttledFunc = throttle(
() => console.log("Call throttle function"),
500
);
throttledFunc();
This function generates a random integer in the range min
to max
.
const randomNum = randomInt(1, 10);
console.log("Random number:", randomNum);
This function removes the duplicate elements in array.
const originalArray = [1, 2, 2, 3, 3, 4];
const uniqueValues = uniqueArray(originalArray);
console.log("Array after removing duplicates:", uniqueValues);
This function creates a wait time in milliseconds.
async function exampleUsage() {
console.log("Starting waiting...");
await sleep(2000); // Wait 2 seconds
console.log("End of wait!");
}
exampleUsage();
This function formats a number to a currency string.
const formattedAmount = formatCurrency(1000000);
console.log("Formatted Amount:", formattedAmount); // Output: "1,000,000"
This function removes commas and returns a numeric value corresponding integer or NaN if the input is invalid.
const inputString = "1,000,000";
const parsedValue = parseCurrency(inputString);
console.log("Integer value:", parsedValue); // Output: 1000000
This function returns a Date object representing the current time
const currentDate = getDateNow();
console.log("Current date and time:", currentDate);
This function returns the current time as a timestamp (milliseconds / seconds)
const timestamp = getTimestamp();
console.log("Current timestamp:", timestamp);
Capitalizes the first character of the passed string.
const capitalizedString = capitalizeFirstLetter(inputString);
console.log("Capitalized string:", capitalizedString); // Output: "Hello, world!"
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Nguyen Phuc Bao Chau - GitHub Profile
This project is licensed under the MIT License.