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

time-series-generator

v0.0.5

Published

Generate time series given start, end and a time window

Downloads

456

Readme

⏰ Time Series Generator

time-series-generator is a library for generating time-series. Works on NodeJS, and browsers

Sample output

A common use-case is to generate time-series for analytics. For example, number of active users each day, start from Feb 12, 2021 to Mar 12, 2021. You can use Time Series Generator to generate a list of 28 dates (from start date to end date).

Table of content

  1. How to use
  2. Installation
  3. Build and Test
  4. License
  5. Feedback and Contribution
  6. Changelog

1. How to Use

// ES6
import TimeSeries from "time-series-generator";

// none-ES6
const TimeSeries = require("time-series-generator"); //add .default in some cases

const series = TimeSeries({
  startDate: Date,
  endDate: Date,
  interval: `millisecond` | `second` | `minute` | `hour` | `day` | `week` | `month` | `year`,
  intervalValue: number, // optional
  floorInput: boolean, // optional. `true` by default 
});

// series => [
//     { startDate: Date, endDate: Date },
//     { startDate: Date, endDate: Date },
//     .....
// ]
  • startDate: begining of datetime period
  • endDate: end of datetime period
  • interval: output series based on given interval millisecond, second, ...
  • intervalValue: the number value of interval, set to 1 by default. For example, interval=second, intervalValue=3, output will generate a list of date each 3 second.
  • floorInput: floor date inputs to the nearest interval value (i.e when interval is "minute", set all "minute", "second", "millisecond" to 0)

Note: startDate can either be less than, or greater than endDate.

See ./tests/Generator.test.js for examples


2. Installation

Via npm (supported on browser and nodejs)

time-series-generator is available via npm. You can install using npm or yarn

# with npm
$ npm install time-series-generator --save

# with yarn
$ yarn add time-series-generator

Via browser


<!-- Embed latest version from jsdelivr (replace @latest with @{version number}) -->
<!-- P/s: When you use @latest, beware of caching when the version is changed-->
<script src="https://cdn.jsdelivr.net/npm/time-series-generator@latest/browser/index.min.js"></script>

<!-- Once the script is loaded, you can call window.GenerateTimeSeries -->
<script>
const series = GenerateTimeSeries({ ... });
</script>

3. Build and Test

Note: You should build before test.

Run the following command (I'll use yarn, but also similar with npm run)

  • To build as a npm module, run yarn build. Output files will located at ./dist
  • To build for browser, run yarn build-browser. Output file will located at ./browser (only index.min.js)

A test file is located on ./tests directory.

  • Run test by run command yarn test

4. License

MIT


5. Feedback and Contribution

Please open a thread for feedback, question. Feel free to create PR for contribution.

--

6. Changelog

0.0.5 - added floorInput to floor date inputs to the nearest interval value 0.0.4 - initate