This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const transformOrientationFile = (file: File): Promise<File> => ( | |
new Promise<File>(((resolve) => { | |
loadImage(file, (img) => { | |
(img as HTMLCanvasElement).toBlob((blob) => { | |
if (blob) { | |
const newFile = new File([blob], file.name, { ...file }); | |
resolve(newFile); | |
} | |
}, file.type); | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getBase64 = (file: File | Blob): Promise<string> => ( | |
new Promise((resolve, reject) => { | |
const reader = new FileReader(); | |
reader.readAsDataURL(file); | |
reader.onload = (): void => { | |
resolve(reader.result as string); | |
}; | |
reader.onerror = (error): void => { | |
reject(error); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const searchParams = location.search | |
.replace('?', '') | |
.split('&') | |
.map(pair => pair.split('=')) | |
.reduce((acc, [k, v]) => { | |
acc[k] = decodeURIComponent(v); | |
return acc; | |
}, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, useRef, useEffect, useCallback } from 'react'; | |
import throttle from 'lodash/throttle'; | |
const useDetectScrollEnd = (endPercent = 0.9) => { | |
const scrollEnded = useRef(false); | |
const [isScrollEnd, setIsScrollEnd] = useState(false); | |
const handleScroll = useCallback(throttle(() => { | |
const { scrollY, innerHeight } = window; | |
const scrollPercent = (scrollY + innerHeight) / document.body.scrollHeight; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getTodayArray = (calc = 0) => { | |
const today = new Date(); | |
const calcTime = new Date(today.getFullYear(), today.getMonth(), today.getDate() + calc); | |
const year = calcTime.getFullYear(); | |
const month = calcTime.getMonth() + 1; | |
const day = calcTime.getDate(); | |
return [year, month, day]; | |
}; | |
export const getYearMonth = ({ day = 0, month = 0 } = {}) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const numberWithCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); | |
export default {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Milliseconds | |
function sleep_ms(millisecs) { | |
var initiation = new Date().getTime(); | |
while ((new Date().getTime() - initiation) < millisecs); | |
} | |
// Seconds | |
function sleep_s(secs) { | |
secs = (+new Date) + secs * 1000; | |
while ((+new Date) < secs); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <input type="text" id="email"> | |
// <input type="text" id="name"> | |
// <input type="text" id="phone"> | |
// <div id="notice"></div> | |
function show(text) { | |
document.getElementById('notice').innerHTML = text; | |
} | |
function set() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <input type="text" id="email"> | |
// <input type="text" id="name"> | |
// <input type="text" id="phone"> | |
// <div id="notice"></div> | |
function show(text) { | |
document.getElementById('notice').innerHTML = text; | |
} | |
function set() { |
NewerOlder