react-best-practices
v1.0.1
Published
[![npm version](https://badge.fury.io/js/angular2-expandable-list.svg)](https://badge.fury.io/js/angular2-expandable-list) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier
Downloads
1
Maintainers
Readme
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]);
isEmail
Checks if the given string is an email
isEmail("[email protected]");
//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