Skip to content

Instantly share code, notes, and snippets.

View gruhh's full-sized avatar

Christhian Gruhh gruhh

View GitHub Profile
@gruhh
gruhh / middle-truncate-text.ts
Created January 28, 2023 11:59
Truncate a string based on the number of characters before and after
/*
* Middle Truncate Text
*
* Example: middleTruncateText('123456789', 3), returns "123...789"
*
* @param {string} text - The text to be truncated
* @param {number} visibleSize - Number of chars on each side (default 5)
* @param {string} ellipsis - The string to place on truncated text (default '...')
*/
export const middleTruncateText: (
@gruhh
gruhh / validate-cpf.ts
Created January 26, 2023 00:53
Validate Brazilian CPF number with Typescript
/*
* Validate Brazilian CPF number with Typescript
*
* @param {string} cpf - A string because can start with 0
*/
export const validateCpf: (cpf: string) => (boolean) = (cpf) => {
const _cpf = cpf.replace(/\D/g, '');
if (_cpf.length < 11) {
return false;