GithubHelp home page GithubHelp logo

react-crazy-utils's Introduction

React Crazy Utils

๐Ÿ“š VIETNAMESE Documents: VIEW NOW

react-crazy-utils is a useful library for React that helps you write better code.

Installation

You can install react-crazy-utils via bun, npm or yarn:

Using bun

bash bun add react-crazy-utils

Using npm

bash npm install react-crazy-utils

Using yarn

bash yarn add react-crazy-utils

Usage

1. isEmptyObject

This function checks if an object is empty.

console.log("Empty Object?", isEmptyObject(obj)); // Output: true

2. isEmptyArray

This function checks if an array is empty.

const arr = [];
console.log("Empty Array?", isEmptyArray(arr)); // Output: true

3. debounce

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();

4. throttle This function limits the number of function calls within a given period of time.

const throttledFunc = throttle(
  () => console.log("Call throttle function"),
  500
);

throttledFunc();

5. randomInt

This function generates a random integer in the range min to max.

const randomNum = randomInt(1, 10);
console.log("Random number:", randomNum);

6. uniqueArray

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);

7. sleep

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();

8. formatCurrency

This function formats a number to a currency string.

const formattedAmount = formatCurrency(1000000);
console.log("Formatted Amount:", formattedAmount); // Output: "1,000,000"

9. parseCurrency

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

11. getDateNow

This function returns a Date object representing the current time

const currentDate = getDateNow();
console.log("Current date and time:", currentDate);

12. getTimestamp

This function returns the current time as a timestamp (milliseconds / seconds)

const timestamp = getTimestamp();
console.log("Current timestamp:", timestamp);

13. capitalizeFirstLetter

Capitalizes the first character of the passed string.

const capitalizedString = capitalizeFirstLetter(inputString);
console.log("Capitalized string:", capitalizedString); // Output: "Hello, world!"

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Author

Nguyen Phuc Bao Chau - GitHub Profile

License

This project is licensed under the MIT License.

react-crazy-utils's People

Contributors

chaudev avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.