1.1.15 • Published 4 years ago

@zelaznogydna/utils v1.1.15

Weekly downloads
2
License
ISC
Repository
github
Last release
4 years ago

Utils

A collection of useful tools I often use.

List

randomColor

use it like this

import { randomColor } from '@zelaznogydna/utils'

const myColor = randomColor() // --> #fffe33 (some random color)

scrollRefIntoView

use it like this

Pass an object with a property named "current" that is a valid DOM element instance.
Compatible with React's useRef() hook

import { scrollRefIntoView } from '@zelaznogydna/utils'
import { useRef } from 'react'

const someRef = useRef()

if(condition) scrollRefIntoView(someRef) // ---> will scroll upon condition === true

isInView

use it like this

Pass an object with a property named "current" that is a valid DOM element instance.
Compatible with React's useRef() hook

import { isInView, scrollRefIntoView } from '@zelaznogydna/utils'
import { useRef } from 'react'

const someRef = useRef()

if(!isInView(someRef)) scrollRefIntoView(someRef) // ---> will scroll when element is not yet seen

mapIntoObject

Get an object given an array of objects like { id: 1238 } with an id property.

use it like this

import { mapIntoObject } from '@zelaznogydna/utils'

const a = [{
  id:   1233,
  name: 'felipe',
}, {
  id:   3223,
  name: 'poey',
}]

const newA = mapIntoObject(a) 
/*--- newA = {
        1233: {
          id: 1233,
          name: 'felipe',
        }
        ...
      }

toTitleCase

use it like this

import { toTitleCase } from '@zelaznogydna/utils'

console.log(toTitleCase("felipe poey")) // --->> Felipe Poey

setupPageBlock

/**
 * @param {boolean} active - Blocked when active is true
 * @param {{avoidBack: boolean, onBack: ()=>{}}} options - If avoidBack is in true intercepts browser's back navigation, pass a callback for onBack() to execute.
 * 
 *  setupPageBlock = (active, {avoidBack = true, onBack} = {})
 */

use it like this

import { setupPageBlock } from '@zelaznogydna/utils'
import { useEffect } from 'react'

  useEffect(() => {
    setupPageBlock(state.isDirty, { onBack: actions.cancel })
  }, [state.isDirty])
1.1.12

4 years ago

1.1.10

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago