Skip to content

Instantly share code, notes, and snippets.

View bearkfear's full-sized avatar
🎯

Enrico Gerez Camponogara Da Silva bearkfear

🎯
View GitHub Profile
@bearkfear
bearkfear / currencyFormat.ts
Created August 26, 2021 02:45
Converte valor monetário para moeda corrente local (currency formatter)
export default function currencyFormat(value: string | number): string {
return Number(value).toLocaleString("pt-BR", {
style: "currency",
currency: "BRL",
})
}
import * as React from 'react';
import * as WebBrowser from 'expo-web-browser';
import * as Google from 'expo-auth-session/providers/google';
import { Button } from 'react-native';
WebBrowser.maybeCompleteAuthSession();
export default function App() {
const [request, response, promptAsync] = Google.useAuthRequest({
expoClientId: 'GOOGLE_GUID.apps.googleusercontent.com',
@bearkfear
bearkfear / machine.js
Created April 26, 2021 00:56
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
"55984366060".split("").reduce((p, c)=> p.replace("x", c),"(xx) xxxxx-xxxx")
@bearkfear
bearkfear / promise-any.ts
Created November 21, 2020 03:29
Retorna a primeira a dar sucesso ou um array de erros
function invertPromise (p: Promise<any>) {
return new Promise(function (resolve, reject) {
return p.then(reject, resolve)
})
}
function firstOfResolve (promises: Array<Promise<any>>) {
return invertPromise(Promise.all(promises.map(p => {
return invertPromise(p)
})))
@bearkfear
bearkfear / Auth.ts
Last active November 16, 2020 19:06
How handle errors in Axios with TypeScript
function errorHandler(error: AxiosError) {
type ErrorBody = {
message?: string;
error?: string;
}
if (error.response) {
// error in server with a response
const data = (<ErrorBody>error.response.data)
const body = `${data.error}: ${data.message}`;
alert(body);
@bearkfear
bearkfear / example.spec.ts
Last active October 2, 2020 14:44
Como fazer o Mock do axios no typescript com jest
const mockedAxios = axios as jest.Mocked<typeof axios>;
humanFormat: function(number) {
if (isNaN(number)) {
number = "";
} else {
// number = Number(number).toLocaleString(this.options.locale, {maximumFractionDigits: 2, minimumFractionDigits: 2, style: 'currency', currency: 'BRL'});
number = Number(number).toLocaleString(this.options.locale, {
maximumFractionDigits: this.options.precision,
minimumFractionDigits: this.options.precision,
});
@bearkfear
bearkfear / example.tsx
Last active November 16, 2022 22:17
Transformar URI ou URL para Blob JS React-Native
const blobfile = await (await fetch(`file://${uri}`)).blob()