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

svelte-timer-store

v0.6.1

Published

Simple timer store with support for pausing and laps

Downloads

14

Readme

Svelte timer store

Simple timer store with support for pausing and laps.

Installation

This is a simple library that utilises Svelte's stores, therefore Svelte is required to use it.

Installation is done using your favourite package manager:

# npm
npm install svelte-timer-store

# pnpm
pnpm install svelte-timer-store

# yarn
yarn add svelte-timer-store

Features

  • Ability to pause and resume timer (sections)
    • Ability to add labels to sections
  • Laps
  • Timer state is presented as a readable store
  • Functions to start, stop, pause, resume, toggle, reset and do a lap

Usage

To use the timer, import the createTimer function. The function can then be used to construct the timer store:

<script>
	import { createTimer } from 'svelte-timer-store';

	const timer = createTimer({ showMs: true, updateInterval: 100 });

	const handleSave = () => {
		const state = timer.save();
		someFunctionToPersistState(state);
	};

	onMount(async () => {
		const savedState = await someFunctionToLoadState();
		timer.load(savedState);
	});
</script>

<!-- Subscribing to the store allows you to read its current state -->
<p>Status: {$timer.status}</p>
<p>Duration: {$timer.durationString}</p>

<!-- You can read the timer's sections in realtime -->
<ul>
	{#each $timer.sections as section}
	<li>
		<p>Started: {new Date(section.from).toTimeString()}</p>
		<p>Duration: {section.duration / 1000}s</p>
	</li>
	{/each}
</ul>

<!-- And also the laps -->
<ul>
	{#each $timer.laps as lap}
	<li>
		<p>Duration: {lap.durationSinceLastLap / 1000}s</p>
	</li>
	{/each}
</ul>

<!-- All available timer controls -->
<button on:click="{timer.start}">Start timer</button>
<button on:click="{timer.stop}">Stop timer</button>
<button on:click="{timer.pause}">Pause timer</button>
<button on:click="{timer.resume}">Resume timer</button>
<button on:click="{timer.toggle}">Toggle timer</button>
<button on:click="{timer.reset}">Reset timer</button>
<button on:click="{timer.lap}">New lap</button>

Reference

createTimer(opts?: TimerOptions)

Constructs the timer store.

Options:

  • showMs?: boolean - If true, milliseconds are included in the duration string
  • updateInterval?: number - How often in milliseconds to update the calculated duration

timer.start(label?: string)

Starts the timer, starting a new section. You can provide an optional label for the started section.

timer.stop()

Stops the timer while retaining all sections and laps. Only works if the timer is running.

timer.pause()

Pauses the timer, ending the current section. Only works if the timer is running.

timer.resume(label?: string)

Resumes the timer, starting a new section. Only works if the timer is paused.

timer.toggle(label?: string)

Convenience function to start, pause or resume the timer based on the current state.

You can provide an optional label for when a new section is started.

timer.lap()

Adds a new lap.

timer.reset()

Resets the timer to its initial state, clearing all sections and laps.