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

week-utils

v1.1.0

Published

A collection of week util written with TypeScript, inspired by moment.js, depend nothing.

Downloads

180

Readme

Week-Utils

A collection of week util written with TypeScript, inspired by moment.js, depend nothing.

  • get the total weeks in year
  • get the current (or specific date) week number in year
  • get the start and end date of a week, specific by year and week number

Week Numbering Systems

Currently, the library support two kinds of week numbering system:

  • ISO 8601 (default, Most of European and Asian countries)

The first day of the week is Monday and Sunday is the last. The week that contains Jan 4th is the first week of the year.

  • North American (USA, Canada, most of Latin America, Japan, Israel, South Korea)

The first day of a week is Sunday and Saturday is the last. The first week (numbered 1) of any given year is the week which contains January 1st.

Install

npm install week-utils

The doy calculate rule

doy is calculated as 7 + dow - janX, where janX is the x-th January that must belong to the week No. 1.

Usage

the default week system is IOS 8601, the necessary params is:

  • dow : 1 (1st day of week is Monday)
  • doy : 4 (The week that contains Jan 4th is the first week of the year.);doy=(7 + 1 - 4)

the corresponding fields - firstDay: 1 (Monday) lastDay: 7 (Sunday)

you can send param dow: 0, doy: 6 to use the North American system.

  • dow : 0 (1st day of week is Sunday)
  • doy : 6 (1st week of the year is the one that contains the 1st of January);doy=(7 + 0 - 1)

the corresponding fields - firstDay: 0 (Sunday) lastDay: 6 (Saturday)

// const WeekUtils = require("week-utils").default;
import WeekUtils from "week-utils";

// IOS 8601, default
const weekUtils = new WeekUtils();
// get the total weeks of a year
weekUtils.localWeeks(2018);  //52

const aDate = new Date(2019, 7-1, 14);
// get the current week number of the year
weekUtils.curWeek(aDate); //28
// get the start and end date of a week
weekUtils.getWeekDate(2019, 28).weekStart // 2019-07-08 (Date)
weekUtils.getWeekDate(2019, 28).weekEnd // 2019-07-14 (Date)

// North American system
const weekUtils = new WeekUtils(0, 6); // params: dow=0, doy=6
// usage is the same
...

Api

| Method | Description | Default | | --- | --- | --- | | localWeeks | get the total weeks of a year | get current year's total weeks | | curWeek | get the current week number of the year according by a specific date | get current week number | | getWeekDate | get the start and end date of a week | - |

License

MIT