Skip to content

Instantly share code, notes, and snippets.

View lucasdu4rte's full-sized avatar
🌎

Lucas Duarte lucasdu4rte

🌎
View GitHub Profile
// requiring path and fs modules
const path = require('path')
const fs = require('fs')
const dirTree = require('directory-tree')
const LOCALE_PATH = 'public/locales'
const SRC_PATH = 'src/'
const directoryLocalesPath = path.join(__dirname, LOCALE_PATH)
const directorySrcPath = path.join(__dirname, SRC_PATH)
@lucasdu4rte
lucasdu4rte / pagination-miragejs.js
Last active April 6, 2021 01:26
MirageJS simulate pagination
import { createServer, Model, Response } from "miragejs";
export function paginator(items, currentPage, perPageItems) {
const page = currentPage || 1
const perPage = perPageItems || 10
const offset = (page - 1) * perPage
const totalPages = Math.ceil(items.length / perPage)
const paginatedItems = items.slice(offset, page * perPage)
import { useSelector } from 'react-redux'
function useAccessControl(mode, page) {
const accessControl = useSelector((state) => state.accessControl.data) || {}
const user = useSelector((state) => state.user.profile) || {}
function can(action) {
console.log(`accessControl.${mode}.${page}.${action}`)
return Boolean(accessControl[mode][page][action])
}
@lucasdu4rte
lucasdu4rte / exportToExcel.js
Created April 29, 2019 11:49
Gerar Arquivo Excel com JSON usando a lib XLSX no Javascript
// É necessário instalar o xlsx
// Foi testado com a versão "xlsx": "^0.14.2"
function Workbook() {
if (!(this instanceof Workbook))
return new Workbook()
this.SheetNames = []
this.Sheets = {}
@lucasdu4rte
lucasdu4rte / currencyToFloat.js
Created January 24, 2019 01:57
Converter string com formato de moeda para float (Ex: 'R$ 1.000,00' => 1000.00)
function currencyToFloat (currency = '') {
const regex = /([+-]?[0-9|^.|^,]+)[\.|,]([0-9]+)$/gim
const result = regex.exec(currency)
const floatResult = result
? result[1].replace(/[.,]/g, '') + '.' + result[2]
: currency.replace(/[^0-9-+]/g, '')
return floatResult
}
const eng = {
above: 'The {{field}} should be above {{argument.0}}.',
accepted: 'The {{field}} should have been accepted',
after: 'The {{field}} should be a date after {{argument.0}}'
}
const pt = {
acima: 'O {{field}} deve estar acima de {{argument.0}}.',
aceito: 'O {{field}} deveria ter sido aceito',
after: 'O {{field}} deve ser uma data após {{argument.0}}'
@lucasdu4rte
lucasdu4rte / validation.json
Created January 23, 2019 10:54
Tradução pt-BR das validações AdonisJS
{
"above": "O campo {{field}} deve estar acima de {{argument.0}}.",
"accepted": "O campo {{field}} deveria ter sido aceito",
"after": "O campo {{field}} deve ser uma data após {{argument.0}}",
"after_offset_of": "O campo {{field}} deve ser depois de {{argument.0}} {{argument.1}} da data de hoje",
"alpha": "O campo {{field}} deve conter apenas letras",
"alpha_numeric": "O campo {{field}} deve conter apenas letrase números",
"array": "O campo {{field}} deve ser um ARRAY.",
"before": "O campo {{field}} deve ser uma dataantes de {{argument.0}}.",
"before_offset_of": "O campo {{field}} deve estar antes de {{argument.0}} {{argument.1}} da data de hoje",
@lucasdu4rte
lucasdu4rte / AuthService.js
Created August 8, 2018 15:37
AuthService
import store from 'store'
import decode from 'jwt-decode'
import axiosClient from '@/helpers/axiosClient.js'
export default class AuthService {
// Initializing important variables
constructor() {
this.fetch = this.fetch.bind(this)
this.login = this.login.bind(this)
const onOpen = (selectedDates, dateStr, instance) => {
if(!document.getElementById('selectRanges')) {
let _elem = document.getElementsByClassName(instance.calendarContainer.classList.value)[0]
let elemClone = _elem.cloneNode(true)
function createMarkup() {
return {__html: elemClone.innerHTML};
}
const ElemFinal = (props) => (
@lucasdu4rte
lucasdu4rte / renderToHtml.js
Created June 5, 2018 03:24
render JSX to HTMLText
const renderText = (component) => {
const __a = document.createElement('div')
ReactDOM.render(component, __a)
const _el = __a.outerHTML
ReactDOM.unmountComponentAtNode(__a)
return _el
}