Skip to content

Instantly share code, notes, and snippets.

View imaginamundo's full-sized avatar

Diogo Fernandes imaginamundo

View GitHub Profile
@imaginamundo
imaginamundo / timeoutFetch.js
Last active August 7, 2025 17:28
A wrapper for fetch with timeout using abort controller and a specific timeout error with url and status.
const DEFAULT_TIMEOUT = 3000;
function request(resource, options = {}) {
const { timeout = DEFAULT_TIMEOUT } = options;
delete options.timeout;
return fetch(resource, { ...options, signal: AbortSignal.timeout(timeout) });
}
export default request;
@imaginamundo
imaginamundo / read_file.ts
Created February 1, 2020 17:45
Deno read import map
import { parse } from 'https://deno.land/std/flags/mod.ts';
import readFileHelp from './read_file_help.ts';
import readFileList from './read_file_list.ts';
import readFileOutdated from './read_file_outdated.ts';
import readFileUpdate from './read_file_update.ts';
const args = parse(Deno.args);
let arg;
@imaginamundo
imaginamundo / url.js
Created December 30, 2019 16:37
Function do get and update parameter from url
export const updateParameter = (uri = '/', key, value) => {
const hasQueries = uri.includes('?');
const hasHash = uri.includes('#');
let hash = '';
if (hasHash) {
hash = uri.substr(uri.indexOf('#'));
uri = uri.substr(0, uri.indexOf('#'));
}
let queries = '';
@imaginamundo
imaginamundo / Regex telefone Brasil.md
Last active February 7, 2026 18:39
Regex para padrões de telefones brasileiros com explicação e como usar

Regex para telefones do Brasil

^(55)?(?:([1-9]{2})?)(\d{4,5})(\d{4})$

const regex = /^(55)?(?:([1-9]{2})?)(\d{4,5})(\d{4})$/;

Explicação