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

@svonk/util

v1.0.5

Published

Toasts, Popups, and more!

Downloads

32

Readme

@svonk/util

Easy-to-use Toasts, Popups, and more common utilities for my projects

Installation


Install to your project with:

npm i @svonk/util@latest

Usage


In your main javascript file, import with:

import {parts} from "@svonk/util"

see below for more info on how to use these parts!

Toasts


new Toast("message", "type", #duration#, "iconPath", "action")

"message"

  • the toast message text to be displayed

"type"

  • a string, either:
    • "boxed"
    • "default"
    • "transparent"
  • indicates which style to use (see ./util.css for more info)

#duration#

  • a number, in ms, of how long to display the toast for

"iconPath" (optional)

  • path to the icon to be shown on the toast (should be square, about 40x40)

"action" (optional)

  • path to redirect to (set with window.location.href) after the duration passes
  • if this is set, the page will also be dimmed slightly while the toast is showing to make it stand out more

Toast Variants


all variants have an optional last argument action (type string) that when specified will redirect to that url using window.location.href when the toast animates out

new ErrorToast("preface", "error", #duration#)

A normal toast, except with the icon set to ./assets/error-icon by default, and the option to reuse a preface for multiple errors

"preface"

  • A string, which will be concatonated with a colon and the message

"error"

  • A string with the error message. I suggest using the cleanError function to get a readable message from error codes

#duration#

  • see parent

new WarningToast("message", #duration#)

A normal toast, except with the icon set to ./assets/warning-icon by default

"message", #duration#

  • see parent

new SuccessToast("message", #duration#)

A normal toast, except with the icon set to ./assets/success-icon by default

"message", #duration#

  • see parent

new placeholderToast()

takes no arguments, used to show that a feature is incomplete, or will be added in its place later, uses ./assets/unimplemented-icon

Popups


new Popup("message", "type", #duration#, "iconPath", [action])

creates an Andriod 13-style popup with styled action buttons based on an imput array. Can be removed with removePopup(), or will automatically animate out after the set duration

"message"

  • the popup message text to be displayed
  • either
    • an array ["title", "message"]
    • a string "message"

"type"

  • a string, currently unused, but you could define your own styles for this

#duration#

  • a number, in ms, of how long to display the popup for

"iconPath" (optional)

  • path to the icon to be shown on the popup

[action] (optional)

  • an array of action buttons to be shown, each of which should have:
    • an array within it of: ["onclick", "text", "class"]
    • "onclick"
      • text, to be eval()ed when clicked
    • "text"
      • text to be shown on the button
    • "class"
      • class added to the button, to allow it to be styled, or setup listeners for when it's clicked
      • .primary-action, .secondary-action, and .delete-color are pre-defined

Popup Utilities

removePopup()

takes no arguments. Will remove any displaying popups, animating them out first.

Other Functions


cleanError({error})

takes in an error object (from firebase) and attempts to clean it up into something readable from error.code, if it's not able to, it returns "Error ${error.message}"

{error}

  • a keyed object with error.message and error.code properties, both of which are strings

$()

proxy import for jquery, since it's imported for use in ./util.js anyways