npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

utils-lazy-hook

v1.8.0

Published

utils-lazy-hook

Downloads

13

Readme

utils-lazy-hook

Lib

https://www.npmjs.com/package/utils-lazy-hook

How to use

npm i utils-lazy-hook or yarn add utils-lazy-hook

useInterval

useInterval(() => {
  console.log(`Hello World~`);
}, 1000);

useLogic

const {
  isTrue,
  isFalse,
  isNull,
  isUndefined,
  isZero,
  isEven,
  isOdd
  } = useLogic();

useMediaQuery

import {useMediaQuery , breakpoints} from 'utils-lazy-hook'

const isMobile = useMediaQuery("(max-width: 768px)")
const isDesktop = useMediaQuery("(min-width: 768px)")
//or
/*
  DEFAULT breakpoints
  up: {
    mobile: '(min-width: 0px)',
    tablet: '(min-width: 768px)',
    desktop: '(min-width: 1024x)',
  },
  down: {
    mobile: '(max-width: 0px)',
    tablet: '(max-width: 768px)',
    desktop: '(max-width: 1024x)',
  },
*/
const isTablet = useMediaQuery(breakpoints.up.tablet)

useFlatMap

interface CategoryProps {
  category: string;
  movies: MoviesProps[];
}

interface MoviesProps {
  name: string;
  rating: number;
}

  const data: CategoryProps[] = [
    {
      category: "drama",
      movies: [{ name: "It's Okay to not be Okay", rating: 4.0 }]
    },
    {
      category: "romantic",
      movies: [
        { name: "Titanic", rating: 5.0 },
        { name: "Titanic", rating: 5.0 },
        { name: "Titanic", rating: 5.0 },
        { name: "Titanic", rating: 5.0 },
        { name: "Titanic", rating: 5.0 },
        { name: "Titanic", rating: 5.0 }
      ]
    }
  ];

  const res = useFlatMap<CategoryProps[], MoviesProps[]>(data, "movies");

useSortRanking

  const profiles: any[] = [
    {
      name: "Lufy",
      email: "[email protected]",
      total_score: 30
    },
    {
      name: "Zoro",
      email: "[email protected]",
      total_score: 18
    },
    {
      name: "Sanji",
      email: "[email protected]",
      total_score: 18
    }
  ];

const profileSorted = useSortRanking<any[], string>(profiles, "total_score");

example result: {
  [
  {
    name: 'Lufy',
    email: '[email protected]',
    total_score: 30,
    ranking: 1
  },
  {
    name: 'Zoro',
    email: '[email protected]',
    total_score: 18,
    ranking: 2
  },
  {
    name: 'Sanji',
    email: '[email protected]',
    total_score: 18,
    ranking: 2
  }
]
}

useRandomString

  const value = useRandomString()

useOmit

const omitResult = useOmit({a: '1', b: '2', c: '3'}, ['a']);

example omitResult = {
  b: '2',
  c: '3'
}

useMinMax

const { findMin,findMax } = useMinMax();
const minNumber = findMin([1,2,3]) // 1
const maxNumber = findMax([1,2,3]) // 3

useEmailRegex

const email = '[email protected]'
const {isEmail} = useEmailRegex()
console.log(isEmail(email))
// true

useOnReachBottom

import { useState } from 'react'
import { useOnReachBottom } from 'utils-lazy-hook';

function App() {
  const [data, setData] = useState(['Item 0']);

  const elemRef = useOnReachBottom(() => loadMore());

  const getData = (offset: number, limit: number) => {
    return Array.from(new Array(limit)).map((_, i) => `Item ${offset + i}`);
  }

  const loadMore = () => {
    setData(prevData => {
      const total = prevData.length;
      const result = getData(total, 10);
      return [
        ...prevData,
        ...result
      ]
    })
  }

  return (
    <div ref={ref => elemRef.current = ref}>
      {
        data.map((item) => (
          <p key={item}>{item}</p>
        ))
      }
    </div>
  )
}

export default App

useWindowSize


interface MinMaxPair{
  minSize:number
  maxSize:number
}

 const { width, height } = useWindowSize()
 const size: MinMaxPair = [width * 0.6 - 300, height * 0.6 - 200]

usePagination

  import { usePagination } from "utils-lazy-hook";
  export default function App() {
    const {
      page,
      pages,
      nextPage,
      backPage,
      haveBackPage,
      haveNextPage
    } = usePagination({
      limit: 10,
      total: 50
    });
    return (
      <div className="App">
        <h1>
          {page} / {pages}
        </h1>
        <button onClick={backPage}>backPage</button>
        <button onClick={nextPage}>nextPage</button>
        <div>
          <div>haveBackPage : {haveBackPage ? "true" : "false"}</div>
          <div>haveNextPage : {haveNextPage ? "true" : "false"}</div>
        </div>
      </div>
    );
  }

useRandomToken

  import { useRandomToken } from "utils-lazy-hook";

  export default function App() {
    return (
      <div className="App">
        <h1>
          {useRandomToken(32, true)}
        </h1>
      </div>
    );
  }