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

vikingowls-ts-snippets

v0.0.5

Published

Vikingowls typescript snippets library

Downloads

5

Readme

vikingowls-ts-snippets

A collection of often used typescript snippets


Utils

sleep()

The sleep function takes the time to sleep in milliseconds.

import { sleep } from "vikingowls-ts-snippets";

sleep(2000).then(any => {
  // do-something
})

Dom Utils

addGlobalEventListener()

The addGlobalEventListener function takes a type (string), a selector (string), a callback function, options (boolean or AddEventListenerOptions), and a parent (DOM or querySelector, etc)

import {addGlobalEventListener, qs} from "./domUtils";

addGlobalEventListener(
    "click",
    ".btn",
    () => console.log("Run once"),
    {once: true}
)

addGlobalEventListener(
    "click",
    ".btn",
    () => console.log("Only works inside the wrapper class"),
    {},
    qs(".wrapper")
)

qs()

The qs function takes a selector (string) and a parent (DOM etc)

import {qs} from "./domUtils";

// instead of document.querySelector(".btn")
qs(".btn")

qsa()

The qsa function takes a selector (string) and a parent (DOM etc) and returns an Array of Elements

import {qsa} from "./domUtils";

// instead of document.querySelectorAll(".btn")
qsa(".btn")

Formatters

formatCurrency()

The formatCurrency function takes a number and a currency (as shown). The output defaults to the locale set in the browser but can be set manually.

import { formatCurrency } from "vikingowls-ts-snippets";

formatCurrency(9_123_456.789123, "EUR", "de-de")
// prints in germany "9.123.456,79 €"
formatCurrency(9_123_456.789123, "USD")
// prints in usa "$9,123,456.79"

formatNumber()

The formatNumber function takes a number. The output defaults to the locale set in the browser but can be set manually.

import { formatNumber } from "vikingowls-ts-snippets";

formatNumber(9_123_456.789123, "de-de")
// prints in germany "9.123.456,789"
formatNumber(9_123_456.789123)
// prints in usa "9,123,456.789"

formatCompactNumber()

The formatCompactNumber function takes a number. The output defaults to the locale set in the browser but can be set manually.

import { formatCompactNumber } from "vikingowls-ts-snippets";

formatCompactNumber(9_123_456.789123, "de-de")
// prints in germany "9,1 Mio."
formatCompactNumber(9_123_456.789123)
// prints in usa "9.1M"

formatRelativeDate()

The formatRelativeDate function takes a Date (end Date). You also can set a default 'start Date'. The output defaults to the locale set in the browser but can be set manually.

import { formatRelativeDate } from "vikingowls-ts-snippets";

formatRelativeDate(new Date().getSeconds() - 20000, new Date().getSeconds(), "de-de")
// prints in germany "vor 20 Sekunden"
formatRelativeDate(new Date().getSeconds() - 20000, new Date().getSeconds())
// prints in usa "20 seconds ago"