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-view

v1.0.1

Published

Simple raw javascript bar-like datepicker.

Downloads

268

Readme

Week View

A simple mobile UI widget for picking a date within a period.

Getting Started

Demo

Installing

npm

npm install week-view

ES2015 module import

import WeekView from 'week-view'

Load it via ~~a link tag and~~ a script tag

<!-- css is included in js -->
<script src="/path/to/week-view.js"></script>

Usage

new WeekView(element[, options])
  • element
    • Type: CSS selector or HTMLElement
    • The container for the widget, normally a div at the top of the page
  • options (optional)

Options

num

  • Type: Number
  • Default: 7

Length of the period. Restricted in [1, 14].

startDate

  • Type: Date
  • Default: new Date()

Initial start date of the period.

minDate

  • Type: Date
  • Default: new Date()

Minimum date. If given is later than startDate, it'll be set to startDate.

maxDate

  • Type: Date or null
  • Default: null

Maximum date. If given is earlier than minDate, it'll be set to null.

onSelect

  • Type: function
  • Default: date => {}

Function to be called when a date is selected.

Param: Date - the date selected.

onChangePeriod

  • Type: function
  • Default: (oldStart, currentStart) => {}

Function to be called when the period is changed.

Params:

  • oldStart - the old period's start date
  • currentStart - current period's start date

showHeader

  • Type: Boolean
  • Default: true

Whether to show the header, which contains header text and prev/next buttons.

headerText

  • Type: function
  • Default: date => date.toLocaleDateString()

Header text.

Param: Date - the date selected.

cellClass

  • Type: Object
  • Default: {}

A set of key-value pairs where key is your custom css class, and value is a function who receives a Date and returns Boolean. The class will be added to corresponding cell element when the function returns true.

e.g.

{
    'week-end': date => return [6,0].includes(date.getDay())
}

will add 'week-end' on weekend cells.

days

  • Type: Array
  • Default: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']

Day texts from Sunday to Saturday.

API

setStart(start[, offset])

  • start
    • Type: Date
  • offset (optional)
    • Type: Number
  • (return value)
    • Type: this

Set the period starting from start, set offsetth date in the period selected.

refresh()

  • (return value)
    • Type: this

Re-render current period, e.g. new options set.

setOptions(options)

  • options
    • Type: Object
  • (return value)
    • Type: this

Set new options for the instance, automatically refresh.

num, startDate, minDate, maxDate are not supported.

selectDate(date)

  • date
    • Type: Date
  • (return value)
    • Type: this

Try to set the given date selected.

destroy()

Destroy the instance.

dates

  • Type: Array

Dates within the current period.

selected

  • Type: Date

Selected date.

Browser Support

  • Chrome latest
  • Firefox latest
  • QQ Browser latest

License

MIT.