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

datestone

v1.0.7

Published

Apply a range of dates to a long list of values. Useful for saving on data transfer/bundle size as the "date column" can be removed from the dataset, and applied at run time.

Downloads

4

Readme

datestone

Apply a range of dates to a long list of values. Useful for saving on data transfer/bundle size as the "date column" can be removed from the dataset, and applied at run time.

Installation

npm i datestone

Why use datestone?

Most time series datasets contain "predictable" dates. Each row has a unique date (if not, the data can be easily shaped to have a unique date) that is usually ordered, and usually incremented by a predictable time duration each row (daily data, monthly data, etc).

Serialized JSON dates take up alot of space. A dataset containing two columns (a daily date and a random decimal number rounded to 3 decimal places) and 100 rows takes up approximately 3.7 kb of disk space. Without the date column the size drops to 1.6 kb, or 57% smaller.

When dealing with large time series datasets that need to be sent over the network or bundled into your production code, the savings can be massive. A dataset like the one described above, but with 50,000 rows can shed just over 1Mb when using datestone, even after the datestone distribution code is included.

How it works

import { mapDatesToList } from "datestone";

// this data is going to take up too much space in our bundle!
const dataWithDate = [
    ["2015-01-01", 0.0284],
    ["2015-01-02", 0.5701],
  ...
];

// delete the "date" column in the backend first!
const dataWithoutDate = [0.0284, 0.5701]

// dataForChart will now mirror "dataWithDate"
const dataForChart = mapDatesToList(dataWithoutDate, new Date(2015, 1,1), "daily")

// Highcharts use case
Highcharts.chart('container', {
    chart: {
        type: 'line'
    },

    tooltip: {
        valueDecimals: 2
    },

    xAxis: {
        type: 'datetime'
    },

    series: [{
        data: dataForChart,
        name: 'Daily data points'
    }]

});

datestone has the capability to fill dates forwards (starting date) or backwards (ending date), as well as transform the "data" column with an optional unit conversion. The best part? There is no combination of parameters that results in anything other than a single pass over the array, without any conditionals evaluated on each data point. Higher order functions are "teed up" at run time to facilitate ultra fast data processing.