This file contains hidden or 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 intlFormat = (num) => { | |
| return new Intl.NumberFormat().format(Math.round(num * 10) / 10); | |
| }; | |
| export const makeCountFriendly = (num) => { | |
| if (num >= 1000000) return intlFormat(num / 1000000) + "M"; | |
| if (num >= 1000) return intlFormat(num / 1000) + "k"; | |
| return intlFormat(num); | |
| }; |
This file contains hidden or 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 getExtention = (path) => { | |
| return path.split("?")[0].split("#")[0].split(".").pop(); | |
| }; |
This file contains hidden or 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 StringHelper from "~/classess/Helpers/StringHelper"; | |
| export const objectUrlToFile = async (blob) => { | |
| return new Promise(async (resolve) => { | |
| let blb = await fetch(blob).then((r) => r.blob()); | |
| resolve( | |
| new File([blb], StringHelper.getRandomString(100), { | |
| type: blb.type, | |
| }) | |
| ); |
This file contains hidden or 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 getHeightAndWidthFromFile = (file) => | |
| new Promise((resolve) => { | |
| const dataURL = URL.createObjectURL(file); | |
| const img = new Image(); | |
| img.onload = () => { | |
| resolve({ | |
| height: img.height, | |
| width: img.width, | |
| }); | |
| }; |
This file contains hidden or 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 swapArrayIndex = (array, currentIndex, moveIndex) => { | |
| if (!array[moveIndex] || !array[currentIndex]) return array; | |
| let changedArray = [...array]; | |
| changedArray[currentIndex] = array[moveIndex]; | |
| changedArray[moveIndex] = array[currentIndex]; | |
| return changedArray; | |
| }; |
This file contains hidden or 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 getRandomString = (len) => { | |
| let result = ""; | |
| const characters = "abcdefghijklmnopqrstuvwxyz0123456789"; | |
| const charactersLength = characters.length; | |
| for (let i = 0; i < len; i++) { | |
| result += characters.charAt(Math.floor(Math.random() * charactersLength)); | |
| } | |
| return result; | |
| }; |
This file contains hidden or 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 getVideoDuration = async (file) => { | |
| const url = URL.createObjectURL(file); | |
| return new Promise((resolve) => { | |
| const video = document.createElement("video"); | |
| const source = document.createElement("source"); | |
| source.src = url; | |
| video.preload = "metadata"; | |
| video.appendChild(source); | |
| video.onloadedmetadata = () => { | |
| resolve(video.duration); |
This file contains hidden or 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 asyncMap = async (array, callback) => { | |
| const results = array.map(async (item, index) => await callback(item, index)); | |
| return await Promise.all(results); | |
| }; |