muni-utils
v1.0.2
Published
Paquete de utils para proyectos municipales.
Downloads
207
Readme
Utils
Paquete de funciones utilitarias comunes a muchos proyectos.
- Instalación
- validateCUIT()
- validateEmail()
- formatFecha()
- formatMoney()
- getWeekDay()
- capitalize()
- randomNumber()
- sleep()
- groupBy()
Instalación
npm i muni-utils
Uso
const utils = require('muni-utils')
let test = utils.validateCUIT('20456178556')
validateCUIT(string
, guiones
)
validateCUIT('20456178556')
// returns true
validateCUIT('20-12345678-9', true);
// returns true
validateCUIT('20-123456AA');
// returns false
validateEmail(string
)
validateEmail('[email protected]');
// returns true
validateEmail('testmail.com');
// returns false
formatFecha(date
, withHours
)
Formatea fecha a 'dd/mm/yyyy' o 'dd/mm/yyyy hh:mm'
formatDate(new Date());
// returns 'dd/mm/yyyy'
formatDate(new Date(), true);
// returns 'dd/mm/yyyy hh:mm'
formatMoney(any
)
//Formatea fecha a 'dd/mm/yyyy' o 'dd/mm/yyyy hh:mm'
formatDate(new Date());
// returns 'dd/mm/yyyy'
formatDate(new Date(), true);
// returns 'dd/mm/yyyy hh:mm'
getWeekDay(date
)
getWeekDay(new Date());
// returns 'Lunes'
capitalize(string
)
capitalize('hello');
// returns 'Hello'
randomNumber(min
, max
)
capitalize('hello');
// returns 'Hello'
sleep(duration
)
sleep(1000)
// pauses execution for 1000ms
groupBy(array
, key
)
Groups an array of objects by a specified key.
array - The array of objects to group.
key - The key to group the objects by.
returns Object An object where the keys are the values of the specified key in the objects,
and the values are arrays of objects that have that key value.
const data = [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' },
{ category: 'vegetable', name: 'carrot' }
];
const groupedData = groupBy(data, 'category');
groupedData will be:
{
fruit: [
{ category: 'fruit', name: 'apple' },
{ category: 'fruit', name: 'banana' }
],
vegetable: [
{ category: 'vegetable', name: 'carrot' }
]
}