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 { useCallback, useEffect, useRef, useState } from "react"; | |
import { | |
StatusBar, | |
Image, | |
FlatList, | |
Dimensions, | |
Animated, | |
Text, | |
View, | |
SafeAreaView, |
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 enNums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; | |
export const faNums = ["۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"]; | |
export const arNums = ["٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩"]; | |
export const enDigitsRegex = /[0-9]/g; | |
export const faDigitsRegex = /[۰۱۲۳۴۵۶۷۸۹]/g; | |
export const arDigitsRegex = /[٠١٢٣٤٥٦٧٨٩]/g; | |
const ar2p = (value) => String(value).replace(arDigitsRegex, (char) => faNums[arNums.indexOf(char)]) |
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 speakeasy from "speakeasy"; | |
export const generateOtp = (secret: string): string => | |
speakeasy.time({ | |
encoding: "base32", | |
secret, | |
digits: 4, | |
step: 300, // expire after 5 mins | |
}); |
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 { RequestHandler } from "express"; | |
import jwt, { Secret } from "jsonwebtoken"; | |
import { errors } from "@util/locale/errors"; | |
export const generateToken = (userId: string) => | |
jwt.sign(userId, process.env.SECRET as Secret); | |
export const verifyToken = (async (req, res, next) => { | |
const bearerHeader = req.headers["authorization"] as string; |
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 regexes = { | |
iran_melli_code: /^(?!(\d)\1{9})\d{10}$/, | |
number_only: /^[0-9\b]+$/, | |
latin_number_only: /^[0-9]+$/, | |
iran_phone: /^(0)9(0[1-5]|[1 3]\d|2[0-2]|9[0-4]|98)\d{7}$/, | |
iran_shaba: /^(?:IR)(?=.{24}$)[0-9]*$/, | |
}; | |
// How to use | |
// const isValidPhone = regexes.iran_phone.test("09371101600") |
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 toLocaleString = ( | |
num: number, | |
options?: Intl.NumberFormatOptions | |
) => num.toLocaleString("fa-IR", options).replace(/\٬/g, ","); |