react-best-practices

1.0.1 • Public • Published

npm version code style: prettier

React-Best-Practices

React-Best-Practices is a set of useful functional components and javascript utilities to help you write quick and clean production-ready react projects

Install

Via package managers:

# With npm
npm i react-best-practices

# With Yarn
yarn add react-best-practices

Table of contents

Functional Components

A set of useful react components to replace and rewrite everyday monotonous code

API

Array

average

Returns the average of an array of numbers

average([2, 5, 30, 60]);
//returns 24.25

median

Returns the median of an array of numbers

median([2, 5, 30, 60]);

Email

isEmail

Checks if the given string is an email

isEmail("johndoe@gmail.com");
//returns true

isEmail("i_love_react_best_practices");
//returns false

Object

areObjectsEqual

Checks to see two given objects are identical

obj1 = {
  name: "John Doe",
  age: 35,
};
obj2 = {
  name: "John Doe",
  age: 27,
};
obj3 = {
  name: "John Doe",
  age: 35,
};

areObjectsEqual(obj1, obj2);
//returns False

areObjectsEqual(obj1, obj3);
//returns True

isObjectEmpty

Checks if the given object is empty

obj1 = {
  "name": "John Doe",
  "age": 35
}
obj2 = {}

isObjectEmpty(obj1);
//returns False

isObjectEmpty(obj2;
//returns True

String

capitalizeFirstLetter

Capitalize the first letter in a sentence

capitalizeFirstLetter("hello there");
//returns Hello there

toString

Convert a number to string.

toString(2);
//returns "2"

Time

delay

Supends the execution of the following code for the given time interval

//Enter interval in milliseconds

delay(3000);
//wait 3 seconds, then alert "Hello"
alert("Hello");

useInterval

Calls a function after every given interval

useInterval(function_name, delay);
//delay in milliseconds

URL

isURL

Checks if the given input is a standard URL

isURL(
  "https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url"
);
//returns True

isURL("Am I a URL ?");
//returns False

Dependents (0)

Package Sidebar

Install

npm i react-best-practices

Weekly Downloads

0

Version

1.0.1

License

ISC

Unpacked Size

7.82 kB

Total Files

22

Last publish

Collaborators

  • the_singhs_den