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

timeseries-ts

v1.0.14

Published

timeseries calculations written in Typescript

Downloads

25

Readme

TimeSeries in TypeScript

TimeSeries is a typescript object designed to keep data and perform calculations on date and value timeseries.

TimeSeriesItem

The data is stored in an array of TimeSeriesItems, where TimeSeriesItem is basically

{
	timestamp: Date;
	value: number;
}

Json import

By default the TimeSeries class imports json data in the following format.

Example

{
	"key": "any id or name (optional)",
	"timestamps": ["2016-08-31", "2016-09-30", "2016-10-31", "2016-11-30"],
	"values": [1.23, 1.27, 1.24, 1.31]
}

Where:

  • key: String, any id or name, optional
  • timestamps: Array of date strings
  • values: Array of numbers

Core functions

  • clone(): Creates a deep copy of the timeseries
  • assign(): Replaces all properties in the timeseries
  • range(startDate, endDate): Like Array.slice create a sliced copy of the timeseries, from startDate to endDate
  • sort(): Sorts TimeSeriesItems in ascending date order. Which many functions and operations require. Therefore items should always be kept in ascending date order.

Basic get properties

  • values: Array of numbers
  • timestamps: Array of Date
  • start: First timestamps
  • end: Last timestamps
  • startValue: First value
  • endValue: Last value
  • count: Number of items
  • periodicity: Number of items per year rounded to one of the standard values 252 (banking daily), 52 (weekly), 12 (monthly), 4 (quarterly), 2 (semi annually), 1 (yearly)

Search functions

  • indexOf(): Returns the last index in items, where timestamp >= item.timestamp
  • latestValue(): Returns value of item found by indexOf()

By item value operators

These functions / operators modifies each item value and returns a ref to the TimeSeries object itself (for method chaining)

  • log(): Log of each value (safe log, returns Number.NaN if non positive)
  • exp(): Exp of each value
  • add(v): Add v to each value
  • mult(v): Mult v to each value
  • neg(): Negates each value
  • inverse(): 1/x of each value

Diff functions

These functions returns a timeseries one item shorter and do not modify the object itself

  • diff(): Returns a timeseries one item shorter and with item to item differences
  • return(): Returns a timeseries one item shorter and with item to item quotients (returns)
  • logReturn(): Returns a timeseries one item shorter and with item to item log quotients (log returns)

Cumulative functions

These functions returns a timeseries and do not modify the object itself

  • cumSum(): Returns a timeseries with cumulative sum values
  • cumProd(): Returns a timeseries with cumulative product values