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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@w3cj/magic-date-picker

v0.1.1

Published

A magical date picker web component with natural language date input.

Readme

@w3cj/magic-date-picker

A magical date picker web component with natural language date input.

Installation

# npm
npm install @w3cj/magic-date-picker

# pnpm
pnpm add @w3cj/magic-date-picker

# yarn
yarn add @w3cj/magic-date-picker

CDN

<script src="https://unpkg.com/@w3cj/magic-date-picker/dist/magic-date-picker.cdn.js"></script>

The CDN bundle is an IIFE with all dependencies bundled. It self-registers the <magic-date-picker> element — no additional setup needed.

Bundled Build

A pre-bundled ESM build with all dependencies included is available at @w3cj/magic-date-picker/bundled:

import "@w3cj/magic-date-picker/bundled";

This is useful when you don't want to install or manage the peer dependencies yourself (e.g. in environments without a bundler, or when you want a single-file ESM import).

Peer Dependencies

The default export (@w3cj/magic-date-picker) externalizes the following dependencies. They are listed in dependencies and will be installed automatically, but if your setup requires manual installation:

  • lit ^3.3.2
  • chrono-node ^2.9.0
  • date-fns ^4.1.0

If you use the @w3cj/magic-date-picker/bundled or CDN builds, these are already included and no additional packages are needed.

Quick Start

<script type="module">
  import "@w3cj/magic-date-picker";
</script>

<magic-date-picker></magic-date-picker>

Attributes

| Attribute | Type | Default | Description | | ------------- | ------- | ------- | -------------------------------------------- | | placeholder | string | — | Custom placeholder text | | enable-time | boolean | false | Show the time picker | | locale | string | — | Locale string for date formatting | | disabled | boolean | false | Disable all interaction | | readonly | boolean | false | Allow viewing but not editing | | theme | string | auto | "light" | "dark" | "auto" | | value | string | "" | ISO 8601 date string (reflected, read/write) |

Properties

| Property | Type | Description | | -------- | ------------------------------------- | --------------------------------------- | | value | string | ISO 8601 string of the resolved date(s) | | output | DatePickerOutput \| null | Full structured output (getter) | | output | { start: Date, end?: Date } \| null | Programmatic date setter |

value

A reflected HTML attribute containing the ISO 8601 representation of the current selection. Updated automatically on every date-change and date-clear event. Can also be set to programmatically select a date — the ISO string is parsed and resolved internally.

Date-only (no enable-time):

  • Single date: "2026-04-20"
  • Range: "2026-04-20/2026-04-25" (ISO 8601 interval)
  • Empty: "" (clears selection)

With enable-time:

  • Single date: "2026-04-20T15:30:00.000Z"
  • Range: "2026-04-20T15:30:00.000Z/2026-04-25T09:00:00.000Z"
const picker = document.querySelector("magic-date-picker");

// Read
console.log(picker.value); // "2026-04-20"
console.log(picker.getAttribute("value")); // same — it's reflected

// Write
picker.value = "2026-04-20"; // single date
picker.value = "2026-04-20/2026-04-25"; // range
picker.value = ""; // clear

output

The rich object form of the resolved date. Use the getter to read, the setter to programmatically set dates.

// Read
const out = picker.output; // DatePickerOutput | null
console.log(out?.start.iso, out?.isRange);

// Write
picker.output = { start: new Date("2026-04-20") };
picker.output = { start: new Date("2026-04-20"), end: new Date("2026-04-25") };
picker.output = null; // clear

Events

| Event | Detail Type | Description | | ------------- | ------------------ | ------------------------------------------------------------------------------- | | date-change | DatePickerOutput | Fires when a date is selected | | date-clear | — | Fires when the selection is cleared | | date-parse | DateParseDetail | Fires on every successful parse, BEFORE resolve — includes ambiguous alternates |

DatePickerOutput

type DatePickerOutput = {
  start: { iso: string; unix: number };
  end: { iso: string; unix: number };
  isRange: boolean;
  includesTime: boolean;
  text: string;
};

end is always present. For single-date outputs, end === start. Use isRange to distinguish single vs range semantics.

text is the canonical, locale-formatted rendering of the selected date or range (e.g. "Mon, Apr 20, 2026", "Mon, Apr 20, 2026 at 3:00 PM", or "Mon, Apr 20, 2026 to Sun, Apr 26, 2026"), not the original text the user typed. On every date resolution — Enter, suggestion click, calendar click, or time-picker change — the input field itself is also rewritten to this canonical form so the user sees exactly what was parsed. Round-tripping text back through the parser is guaranteed to yield the same span.

DateParseDetail

type DateParseDetail = {
  text: string; // original input at the moment of parse
  results: ParsedDateSpan[]; // all parsed interpretations (primary first)
  alternativesDescription?: string; // human-readable summary when results.length > 1
};

date-parse fires every time the parser successfully interprets the input, before the auto-resolve step. This gives consumers a live feed of parse state — including ambiguous interpretations (e.g. "3/4" can be March 4 or April 3) — which is useful for external previews, analytics, or debugging. When more than one interpretation exists, alternativesDescription mirrors the screen-reader announcement (e.g. "2 possible interpretations: Fri, Mar 4, 2026, or Sun, Apr 3, 2026. Use arrow keys to select.").

API Reference

Component

import { MagicDatePicker } from "@w3cj/magic-date-picker";

Types

import type {
  DatePickerOutput,
  DateSpan,
  HolidayEntry,
  ParsedDateSpan,
  ParseResult,
  RangeBuildingResult,
} from "@w3cj/magic-date-picker";

Utilities

import {
  buildOutput, // Build a DatePickerOutput from dates
  findHoliday, // Look up a holiday by name
  formatCanonical, // Canonical, round-trip-safe display form
  formatForAccessibility, // Screen-reader friendly form
  formatForPreview, // Canonical + duration suffix for ranges
  HOLIDAYS, // Built-in holiday list
  parse, // Parse a natural language date string
  VERSION, // Current version string
} from "@w3cj/magic-date-picker";

Development

pnpm install        # Install dependencies
pnpm dev            # Start Vite dev server
pnpm build          # Library build (ESM + CJS + bundled ESM + types)
pnpm build:cdn      # CDN IIFE bundle
pnpm test           # Vitest + Playwright tests
pnpm lint           # Lint
pnpm lint:fix       # Lint with auto-fix
pnpm typecheck      # TypeScript type checking

License

MIT