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

skaggr.js

v0.0.5

Published

A JavaScript interface for creating Qlik expressions via the skaggr spec

Downloads

1

Readme

skaggr.js

A JavaScript library for creating Qlik expressions via the skaggr JSON spec

skaggr.js is a JavaScript library for creating Qlik expressions. In the QlikView and Qlik Sense world, developers became very familiar with the syntax of writing Qlik expressions by hand. While this syntax is great for that usecase, it becomes difficult to automate. Qlik developers have responded by using dollar-sign expansion to create dynamic expressions.

As the APIs bring the QIX Engine closer to web developers who have no experience with QV or QS, a new approach is needed for creating and managing Qlik expressions that matches how web developers write code. skaggr.js is a library that builds Qlik expressions via JavaScript classes and methods that allow web developers to compose and maintain these expressions programmatically. A couple of examples:

Simple Example: Sum of Sales

var mySales = skaggr.Sum("Sales");
mySales.print(); // -> "sum(Sales)"

With a simple example like that, we haven't added much value. How is this any easier than writing "sum(Sales)"? It's not. However, as we scale up the syntax and want to modify our expressions over time, the interface becomes more useful. For example, lets add a total qualifier:

mySales.total();
mySales.print(); // -> "sum(TOTAL Sales)"

What if I then want to add modifiers to the total qualifier? I could redefine it on the fly easily like:

mySales.total(["Region", "Country"]);
mySales.print(); // -> "sum(TOTAL<Region,Country> Sales)"

mySales.total(false);
mySales.print(); // -> "sum(Sales)";

Advanced Example: Set Analysis

Let's try to produce a much more complicated expression:

sum({1 - $<Year = [Alt Year] - {2009,2010}, Month = P({1<Product = {Shoe}>} Month)>} TOTAL<Country,Region> Sales)

In this example, we have a complex set expression made up of multiple components, as well as total qualifiers. We can define this via skaggr.js like so:

// Init a sales expression with our total qualifier from before
var mySales = skaggr.Sum("Sales")
    .total(["Country","Region"]);

// Create the first component of the set expression
var one = skaggr.SetComponent("1");

// Create the second component of the set expression
var $ = skaggr.SetComponent("$");

// Create the year modifier for the second component
var yearMod = skaggr.SetModifier()
    .field("Year")
    .setSelection(skaggr.SetField("[Alt Year]"))
    .exclusion(skaggr.SetList(["2009","2010"]));

// Create the P() expression for the month modifier for the second component
var P = skaggr.Aggregation()
    .type("P")
    .addParameter("Month")
    .set(skaggr.SetExpression()
        .setComponent(skaggr.SetComponent("1")
            .addModifier(skaggr.SetModifier("Product")
                .setSelection(skaggr.SetList(["Shoe"]))
            )
        )
    );

// Create the month modifier for the second component
var monthMod = skaggr.SetModifier()
    .field("Month")
    .setSelection(P);

// Add the modifiers to the second component
$.addModifier(yearMod)
    .addModifier(monthMod);

// Combine the components to form the set
var diffSet = skaggr.SetExpression()
    .setComponent(one)
    .exclusion($);

// Finally, add the set to your expression and print
mySales.set(diffSet);

mySales.print(); // -> "sum({1 - $<Year = [Alt Year] - {2009,2010}, Month = P({1<Product = {Shoe}>} Month)>} TOTAL<Country,Region> Sales)"

While it is a lot to write, we are able to manage the various components of these expressions directly. For example, we could change the Year modifier to an Alt Year modifier simply by saying:

yearMod.field("[Alt Year]");
mySales.print(); // -> "sum({1 - $<[Alt Year] = [Alt Year] - {2009,2010}, Month = P({1<Product = {Shoe}>} Month)>} TOTAL<Country,Region> Sales)"

These various components can also be reused across multiple expressions, making it easy to share dynamic set analyses without relying on dollar-sign expansion.