mirror of
https://github.com/20kaushik02/spotify-manager-web.git
synced 2026-01-25 16:14:06 +00:00
setting up
This commit is contained in:
17
src/utils/ScrollToTop.js
Normal file
17
src/utils/ScrollToTop.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useEffect } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
function ScrollToTop() {
|
||||
let { pathname } = useLocation();
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
window.scrollTo(0, 0);
|
||||
}, 100);
|
||||
return () => { };
|
||||
}, [pathname]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export default ScrollToTop;
|
||||
16
src/utils/numFormatter.js
Normal file
16
src/utils/numFormatter.js
Normal file
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* Returns a string with zero padding of the number
|
||||
*
|
||||
* @param {number} num Input number (positive integer only, for now)
|
||||
* @param {number} places Number of zeroes to pad
|
||||
* @param {"before" | "after"} position Position of zeroes
|
||||
* @returns {string} Zero-padded string
|
||||
*/
|
||||
export const zeroPaddedString = (num, places, position) => {
|
||||
if (num < 0) throw new Error("negative number");
|
||||
if (places < 0) throw new Error("invalid number of zeroes");
|
||||
if (position !== "before" && position !== "after") throw new Error("invalid position (before or after only)");
|
||||
|
||||
const zeroes = "0".repeat(places);
|
||||
return position === "before" ? '' + zeroes + num : '' + num + zeroes;
|
||||
}
|
||||
Reference in New Issue
Block a user