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 🙏

© 2025 – Pkg Stats / Ryan Hefner

svelte-simple-query

v0.0.4

Published

A simple yet powerful, lightweight data query library for Svelte 5, providing full control with built-in functionalities. Built with TypeScript for easy usage and strong typing.

Readme

Svelte Simple Query

A simple yet powerful, lightweight data query library for Svelte 5, providing full control with built-in functionalities. Built with TypeScript for easy usage and strong typing.

Features

  • TypeScript Support: Fully typed for better development experience.
  • Query Management: Simple and flexible querying system.
  • Data Management: Supports fetching, caching, and mutations.
  • Dynamic Querying: Fetch dynamic endpoints effortlessly.

Installation

npm install svelte-simple-query

Usage

<script lang="ts">
	import { Query, useQuery } from 'svelte-simple-query';

	Query.setup({
		baseURI: 'https://jsonplaceholder.typicode.com'
	});

	interface UserSchema {
		id: number;
		name: string;
	}
	const users = useQuery<UserSchema[]>('/users');
	users.fetch();
</script>

<div>
	{#if users.isLoading}
		Loading...
	{:else if users.data}
		{JSON.stringify(users.data)}
	{:else if users.isError}
		{users.isError}
	{:else}
		...
	{/if}
</div>

Example

Query API

Query.setup(options) for the global configuration of queries.

  • baseURI (string) - Base API endpoint.
  • baseInit (object) - Default request options.
  • cacheTimeout (number) - Cache expiration time in milliseconds, default 2000.
  • onError(query, error) (function) - Callback for errors.
  • onSuccess(query) (function) - Callback for successful requests.
  • loadingSlowTimeout (number) - Timeout duration in milliseconds before triggering slow loading handler, default 30000.
  • onLoadingSlow(query) (function) - Callback triggered when a query is loading slower than expected.
  • shouldRetryWhenError (boolean) - Whether to retry on failure, default false.
  • retryCount (number) - Number of retries on failure, default 5.
  • retryDelay (number) - Delay between retries in milliseconds, default 10000.

Query.clear(endpoint?: optional)

Clears cached query results and resets internal query states. Useful when logging out users, refreshing data, or preventing stale responses.

Parameters:

  • endpoint (optional, string) - If provided, only clears the cache for the specified endpoint.

Usage

Query.clear(); // Clears all cached queries
Query.clear("/users"); // Clears cache only for the "/users" endpoint

Query.clearGroup(group: string)

Clears all cached queries associated with a specific group. This is useful for managing grouped queries, such as clearing related data when switching views or updating dependent resources.

Parameters:

  • group (string) - The name of the query group to clear.

Usage

const usersPageA = useQuery("/users?page=a", { group: "user-data" });
const usersPageB = useQuery("/users?page=b", { group: "user-data" });
Query.clearGroup("user-data"); // Clears all queries tagged under "user-data"

Query.group(group: string)

Clears all cached queries associated with a specific group. This is useful for managing grouped queries, such as clearing related data when switching views or updating dependent resources.

Parameters:

  • group (string) - The name of the query group to clear.

Usage

const usersPageA = useQuery("/users?page=a", { group: "user-data" });
const usersPageB = useQuery("/users?page=b", { group: "userQuery-data" });
const usersPageB = useQuery("/users", { groups: ["userQuery-data", "user-data"] });
Query.group("user-data"); // Return all queries tagged under "user-data"
Query.group("userQuery-data"); // Return all queries tagged under "userQuery-data"

API

  • useQuery(endpoint, options): Fetch data from the specified endpoint with optional settings.
  • useSingleQuery(() => string, options): Fetch a dynamic single resource dynamically with optional settings.
  • mutate(endpoint, options): Perform a mutation the given endpoint with optional settings.

Query/Data Management

query.{...} for managing data state and execution.

  • data: The response data from the query.
  • isError: Boolean indicating if an error occurred.
  • isLoading: Boolean indicating if the query is loading.
  • fetch(): Initiates a data fetch request.
  • refetch(options): Re-fetches the query data with optional configurations.
  • mutate(options): Mutate existing query data dynamically.
  • clear(): Clears the query cache, data, isError and isLoading.
  • endpoint: The API endpoint associated with the query.

License

MIT