Skip to content

Instantly share code, notes, and snippets.

View jonathanborges's full-sized avatar

Jonathan Borges jonathanborges

  • Brazil, Minas Gerais
View GitHub Profile
const ms = require('ms');
const c = require('colors');
class Debugger {
debug(description) {
let prevTime = this.prevTime;
let curr = +new Date();
let milliseconds = curr - (prevTime || curr);
function toMoney(value) {
value += '';
x = value.split('.');
x1 = x[0];
x2 = '';
if (x.length > 1 ) {
if (x[1].length < 2) {
x[1] = x[1]+'0';
} else {
const { DateTime } = require('luxon')
function eachDays(d1, d2, response = 'DateTime') {
let parse = (date) => {
switch(date.constructor) {
case Date:
return DateTime.fromJSDate(date).startOf('day')
case String:
return DateTime.fromSQL(date).startOf('day')
export const currency = (value, decimalPlaces = 2, symbol = true) => {
let formatedValue = parseFloat(value).toFixed(decimalPlaces)
.replace('.', ',')
.replace(/\d(?=(\d{3})+,)/g, '$&.')
return (symbol) ? `R$ ${formatedValue}` : formatedValue
}
const MongoClient = require('mongodb').MongoClient
const url = `mongodb://root:mo1542653!@localhost:27017/?authMechanism=SCRAM-SHA-1&authSource=admin`
var _connInstance
const getInstance = async () => {
if (!_connInstance) {
_connInstance = await getConnection()
}
return _connInstance