1.1.4 ⢠Published 2 years ago
hytzen-helpers v1.1.4
š hytzen-helpers
Helper functions for react projects.
š Getting started
npm:
npm install hytzen-helpersyarn:
yarn add hytzen-helpersš Documentation
Helpers
- money: Format a value to a currency shape.
- percent: Format a value to a percentage shape.
- date: Format a date string to specific shape.
- isValidateEmail: Check if the input is valid email.
- isValidateCPF: Check if the input is valid CPF.
- numonly: Returns numeric characters only.
- numtostr: Transform a number to a string.
- strtonum: Transform a string to a number.
- randonfy: Randomly change the order of an array.
- generateArrayOfNumbers: Generate an array from x to y.
- generateArrayWithXPositions: Generate an array with x positions.
- generateMongoObjectId: Generate a random mongo object ID.
- getFirstLetters: Return the two first letters of a string.
- getFirstName: Return the first name of a string.
- ctc: concat tailwind classNames.
- makePrismaFilter: Generate a string filter for prisma queries.
- px2num
- convertPXToREM
- convertPXToVH
Hooks
- useBreakpoint
- useSkipFirstRender
- useLocalStorage
- useToggle
- useFetch
- useKeyPress
- useDebounce
- useOnScreen
š» Examples
money()
money(100)
// result: R$100,00
money(100, {
  locale: 'en-US',
  currency: 'USD',
})
// result: $100.00percent()
percent(100)
// result: 100%
percent(0.2525, {
  locale: 'pt-BR',
  maximumFractionDigits: 2,
})
// result: 0.25%date()
date(new Date().toString())
// result: 01/01/2023
date(new Date().toString(), {
  locale: 'pt-BR',
  dateStyle: 'short' // 'full' | 'long' | 'medium' | 'short'
  withHour: true
  onlyHour: false
})
// result: 01/01/2023 Ć s 12:00isValidateEmail()
isValidateEmail('johndoe@mail.com')
// result: true
isValidateEmail('johndoe')
// result: falseisValidateCPF()
isValidateCPF('123.456.789-00')
// result: falsenumonly()
numonly('123.456.789-09')
// result: 12345678909numtostr()
numtostr(123)
// result: '123'strtonum()
strtonum('123')
// result: 123randonfy()
randonfy([1, 2, 3, 4, 5])
// result: [3, 5, 1, 4, 2]generateArrayOfNumbers()
generateArrayOfNumbers(1, 4)
// result: [1, 2, 3, 4]generateArrayWithXPositions()
generateArrayOfNumbers(4)
// result: [0, 1, 2, 3]generateMongoObjectId()
generateMongoObjectId()
// result: 63e2ab7da20f7c26aaab97e9getFirstLetters()
getFirstLetters('John Doe')
// result: JD
getFirstLetters('John')
// result: JOgetFirstName()
getFirstName('John Doe')
// result: Johnctc()
<div className={c('w-full', 'bg-black')} />makePrismaFilter()
const filterString = JSON.stringify({
  ...makePrismaFilter('johndoe', {
    OR: ['username'],
  }),
})px2num()
px2num('16px')
// result: 16convertPXToREM()
convertPXToREM('16px')
// result: 1remconvertPXToVH()
convertPXToVH('16px')
// result: 1.62vhā Contributing
Each PR should be specific and isolated to the issue you're trying to fix. Please do not stack features/chores/refactors/enhancements in one PR. Describe your feature/implementation in the PR. If you're unsure its useful or if it is a major change, please open an issue first and get feedback.
- Comment your code
- Write clean code
š¤ License
MIT
Made with ā¤ļø by Samara Carvalho
šš½ Entre em contato!