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

@js-idiots/aragorn

v1.0.3

Published

A Type script library to create traces based on start and end time of an event and measure the latency difference

Downloads

3

Readme

Aragorn

The Strider

A Simple Type Script Library, to track events in our JS code bases.

And easiest way to track performance of some UI/ BE event is to calculate the time taken from the starting and ending point of the event.

Aragorn helps the JS devs to carry out this easily in his/her code base by just asking to start and stop an event when needed and Aragorn the legendary tracer will do the rest and will either return the time elapsed for an event or will throw a cautionary error warning for the mortals to correct his/her request.

Its usage is very simple , import Aragorn wherever you want to avail his services.

import Aragorn from './Aragorn';
{
Aragorn.startTrace('CUSTOM_EVENT_NAME');
//code block you want to trace
}
{
//code block you want to trace
Aragorn.stopTrace('CUSTOM_EVENT_NAME',printEventDuration)
}

Note: Aragorn also takes a function when you ask him to stop the trace.

Aragorn will return details like event name and event duration for you to use.

function printEventDuration(traceObj: any) {
  if (traceObj) console.log('Event : ' + traceObj.key + ' Duration:' + traceObj.duration);
}

Use Cases

Use Case 1 : values of event name is given with delay

Aragorn.startTrace('CUSTOM_EVENT_1');
//add delay then stop
setTimeout(() => { Aragorn.stopTrace('CUSTOM_EVENT_1',printEventDuration)},2000);

Case 2 : values of event is given without any delay

Aragorn.startTrace('CUSTOM_EVENT_2');
//piece of code you want to track for time
Aragorn.stopTrace('CUSTOM_EVENT_2',printEventDuration)

Case 3 : clear all exisiting traces

Aragorn.clearAllTrace();

Case 4 : Log all event activity

Aragorn.enableLogs(true);

Case 5 : Pass Extra Properties with the events

let traceProperties = new Map();  
  
traceProperties.set('property1', 'value1');     
traceProperties.set('property2', 'www.androidiots.in');       


Aragorn.startTrace('CUSTOM_EVENT_WITH_MAP', traceProperties);
//add delay then stop
setTimeout(() => { Aragorn.stopTrace('CUSTOM_EVENT_WITH_MAP',printEventDurationAndMap)},2000);


function printEventDurationAndMap(traceObj){
  
  if(traceObj)
  console.log("Event : " +traceObj.key + " Duration:" + traceObj.duration);
  
  if(traceObj.properties)
  {
    traceObj.properties.forEach((value: string, key: string) => {
      console.log(key, value);
  });
  }
}

All the Use Cases are also available under samples/index.js


Edge Cases

Case 1 : event stop is called incorrectly before starting the trace

Aragorn.stopTrace('CUSTOM_EVENT_3',printEventDuration) //reference error will be thrown 
Aragorn.stopTrace(122,printEventDuration) //type error will be thrown

Case 2 : event start is is called multiple times before

Eg

let count = 5;
var myVar = setInterval(startIntervalTimer, 1000);

function startIntervalTimer() {
    if (--count === 0) {
    console.log('Stop Trace Called')
    Aragorn.stopTrace('CUSTOM_EVENT_4',printEventDuration);
    stopIntervalTimer();
    }
    else {
        console.log('Start trace started called ' + (5 - count) + ' time');
        Aragorn.startTrace('CUSTOM_EVENT_4');
    }
  }
  
  function stopIntervalTimer() {
    clearInterval(myVar);
  }

Case 3 : null is passed as key to start or stop trace

  Aragorn.startTrace(null); // Reference error will be thrown

  Aragorn.stopTrace(null);  // Reference error will be thrown