Skip to content

Instantly share code, notes, and snippets.

View esaramago's full-sized avatar
💻
Working as a freelancer

Emanuel Saramago esaramago

💻
Working as a freelancer
View GitHub Profile
@esaramago
esaramago / toBase64.ts
Created December 15, 2024 11:34
Image to base64
type MaxFileSize = number // in KB
export default (file: File, maxFileSize?: MaxFileSize) => {
let base64 = ''
if (!file) return base64
const sizeInKb = file.size / 1024
@esaramago
esaramago / fetchApi.ts
Last active December 20, 2024 15:43
Fetch API Util
const API_URL = ''
const fetchApi = async (endpoint: string, options?: object) => {
const response = await fetch(`${API_URL}/${endpoint}`, options)
const data = await response.json()
return {
data,
success: response.ok,
}
@esaramago
esaramago / validateNIF.ts
Last active December 15, 2024 11:37
Validação NIF português (typescript)
function validateNIF(value: string) {
// has 9 digits?
if (/^[0-9]{9}$/.test(value) === false) return false
// starts with 5 (Pessoa coletiva)
if(!['1', '2', '3', '5', '6', '8'].includes(value.substring(0,1)) &&
!['45', '70', '71', '72', '77', '79', '90', '91', '98', '99'].includes(value.substring(0,2)))
return false
@esaramago
esaramago / block.json
Last active December 24, 2024 16:34
Wordpress Block
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 3,
"name": "THEME_NAME/BLOCK_NAME",
"version": "0.1.0",
"title": "BLOCK_TITLE",
"description": "",
"category": "THEME_NAME",
"textdomain": "THEME_NAME",
"keywords": [],