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

via-script

v0.2.2

Published

A library for storing and manipulating time series data.

Downloads

5

Readme

Via Script

Via Script is a superset of functions build with normal JavaScript to allow for easier manipulation of time series data. Data is stored in an array-like structure called a Series that abstracts away some of the more annoying aspects of working with date-value pairs.

Series

A series is an array-like data structure that contains date-value pairs. In fact, the Series class extends the Javascript Array object. Within the series object, data is stored as a list of ordered pairs.

[
    [Date, Value],
    [Date, Value],
    [Date, Value],
    ...
]

As the Series is just an extension of an Array, it contains all of the Array methods. However, many methods have been overridden to allow for easier manipulation of the data within the series. It is much more common to manipulate data (y-values) than it is to manipulate the underlying dates themselves.

Series can be manipulated functionally using the built in functions of Via Script. Most of these functions will only accept a series as their primary argument. For example, to add a constant to every value in the series:

const series_plus_seven = add(series, 7);

In this case, the function add will return a new series with the constant added to each of the original items.

const sum_of_two_series = add(series_one, series_two);

This will add two series together, one value at a time. Obviously, series must be of the same length to be manipulated in this way.

Series Methods

Create a Series

const series = new Series();

Insert a Value

Returns Undefined

Add a value to the Series. Date must be a JavaScript date object. Values can be anything, Via Script is unopinionated about this. However, you may need a Series with a certain value type in order to use certain functions (e.g. you must have a Series of numbers in order to use add).

series.set(date, value);

Get a Value

Returns A Value

You can certainly use bracket notation (as with any JS array), but this provides a simpler alias for retrieving values at a certain index.

//Simple alias
series.get(index);

//Other method for retrieving values
//Note that series[index][0] is the Date that corresponds to this value
series[index][1];

Availability of a Date Range

Returns Boolean

This function is not implemented yet.

Check to see if a Series contains values for all dates within a certain range, with a certain granularity. For example, does the Series contain values for all days between 1 Jan 2018 and 31 Jan 2018?

const available = series.available(start_date, end_date, granularity_in_milliseconds);

Map

Returns Series

This function is an override of the JS Array.map function. It will map all values to a new value, without transforming the keys (dates). It will return a new series and not modify the original series.

const new_series = series.map((value, index) => transform(value));

Entries

Returns Series

This function is similar to the Object.entries function. It will map all values to a array containing both the key and value. It will return a new series and not modify the original series. Please note, this does not return an Array like Object.entries does. It returns a new Series, like other functions do.

//Entries is a Series of arrays, each containing [original_key, original_value]
const entries = series.entries((value, index) => transform(value));

Via Script Functions

...To Be Continued.