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

@bigbinary/neeto-utils

v0.0.7

Published

NeetoUtils is a utilities library that drives the experience in all Neeto products built at BigBinary.

Downloads

11

Readme

NeetoUtils

NeetoUtils is a utilities library that drives the experience in all Neeto products built at BigBinary.

Installation

yarn add https://github.com/bigbinary/neeto-utils

Development

Install all the dependencies by executing following command.

yarn

You can create new components in the lib/components and export them from lib/index.js.

Running the yarn start command starts a CRA app which resides in example folder. Use this application to test out changes. Note that nothing in the src folder will be bundled with NeetoEditor.

Building

Running the yarn build command build a production bundle file.

Available utilities

Utils

Slugify

const Slugify = string => {
  return string
    .toString()
    .toLowerCase()
    .replace(/\s+/g, "-") // Replace spaces with -
    .replace(/&/g, "-and-") // Replace & with 'and'
    .replace(/[^\w\-]+/g, "") // Remove all non-word characters
    .replace(/\-\-+/g, "-") // Replace multiple - with single -
    .replace(/^-+/, "") // Trim - from start of text
    .replace(/-+$/, ""); // Trim - from end of text
};

Truncate

const truncate = (text = "", maxLength = 30) =>
  text.length > maxLength ? text.slice(0, maxLength - 3) + "..." : text;

Hooks

useDebounce

const useDebounce = (value, delay = 800) => {
  const [debouncedValue, setDebouncedValue] = useState(value);

  useEffect(() => {
    const handler = setTimeout(() => {
      setDebouncedValue(value);
    }, delay);

    return () => {
      clearTimeout(handler);
    };
  }, [value]);

  return debouncedValue;
};

useOnClickOutside

const useOnClickOutside = (ref, handler) => {
  useEffect(() => {
    const listener = (event) => {
      // Do nothing if clicking ref's element or descendent elements
      if (!ref.current || ref.current.contains(event.target)) {
        return;
      }
      handler(event);
    };
    document.addEventListener("mousedown", listener);
    document.addEventListener("touchstart", listener);
    return () => {
      document.removeEventListener("mousedown", listener);
      document.removeEventListener("touchstart", listener);
    };
  }, [ref, handler]);
};

useLocalStorage

useLocalStorage is a custom react hook used to read and write a specific field in application's localstorage.

const [localStorageValue, setLocalStorageValue] = useLocalStorage(
  "useLocalStorage",
  "BigBinary"
);
return (
  <input
    placeholder="Enter value"
    value={localStorageValue}
    onChange={(e) => setLocalStorageValue(e.target.value)}
  />
);

useAxios

useAxios is a custom react hook used to perform API requests. It helps reduce the duplication of the same code in the same file and across multiple files in a project.

const {
		request: createPost,
		apiResponse: { data: id },
		error: createError,
		isLoading: createLoading,
	} = useAxios(
		{
			method: "POST" // Any valid HTTP methid ,
			url: "https://jsonplaceholder.typicode.com/posts" // A valid API endpoint,
      headers: "" // Valid HTTP headers
		},
		""
	);