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

viki-web-utils

v0.0.18

Published

Utils used by the Viki web app

Downloads

3

Readme

viki-web-utils

Web utilities used by the Viki web app

Installation

npm install -S viki-web-utils

Documentation

For full documentation, see it the docs page or in /docs directory.

ScrollTracker

Keeps track of the furthest point on page that user has scrolled to (in percentage). Returns most updated value everytime percentageSeen() is called.

Usage

import Viki from 'viki-web-utils';

const tracker = new Viki.ScrollTracker();
tracker.init();

console.log('percentage of page seen', tracker.percentageSeen()) // e.g. 5
console.log('percentage of page seen rounded to granularity of 10', tracker.percentageSeenRounded(10)) // e.g. 10

LocalStorageTabCounter

Keeps track of number of tabs user has open in current session. Saves current count to user's localStorage.

Usage

import Viki from 'viki-web-utils';

const counter = new Viki.LocalStorageTabCounter();

// open 2 tabs with current session

console.log(counter.getCount()) // 2

ResizeCounter

Tracks number of times user has resized the window. Debounced at 300ms to prevent too many function calls.

Usage

import Viki from 'viki-web-utils';

const counter = new Viki.ResizeCounter(function() {
  // do something, maybe fire an event
});

// resize browser window

console.log(counter.getCount()) // e.g. 1

BlockedResourceChecker

Tests if a resource is blocked on client side. Returns a Promise on test that is passed in blocked and resource values.

Usage


// create checker
const checker = new BlockedResourceChecker('https://badresource.blah');

// test resource returns a Promise
checker
  .test()
  .then((res) => {
    console.log(res.resource, res.blocked) // https://badresource.blah true
  });

PerformanceTimingTracker

Pulls information from the client's performance timing API, and allows for augmentation on the information along with retrieving all the stats as a JSON object. If the target browser does not support the performance timing API, an empty JSON object is returned instead.

Usage

import Viki from 'viki-web-utils';

let performanceTracker = new Viki.PerformanceTimingTracker();

// Set a custom metric - with a string key and another value of any type
performanceTracker.set('customDeferFullyLoaded', Date.now());

// Retrieve a custom or present metric in browser performance api
// If the value is not present, null is returned
// View more @ https://www.w3.org/TR/resource-timing-1/#h-performanceresourcetiming
console.log(performanceTracker.get('redirectStart'));

// Set a new metric value that is the numerical difference between two currently tracked values
performanceTracker.setDifferenceAsValue('customDeferFullyLoaded', 'redirectStart');

// Retrieve all metric data as a json object
console.log(performanceTracker.extractMetrics());

Development

Install dependencies

npm install

Run tests

npm run test

Karma wil prompt you to open browser on Google Chrome. To trigger tests, modify and save any src file.

Build and publishing

npm run build
npm run build-docs // generates JSDoc documentation to /docs dir
npm publish //script automatically builds before publish