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

@n0n3br/pbkit

v0.0.1

Published

A set of svelte components to facilitate the integration between your app and pocketbase

Downloads

3

Readme

pbkit

A set of svelte components to facilitate the integration between your app and pocketbase

Installation

Using pnpm (recomended)

pnpm i @n0n3br/pocketkit pocketbase

, npm

npm i @n0n3br/pocketkit pocketbase

or yarn

yarn add @n0n3br/pocketkit pocketbase

Components

PbApp

Initializes the pocketbase instance so you can use it in other components. To use this component you must provide the pocketbase address.

<script>
	import { PbApp } from '@n0n3br/pbkit';
</script>

<PbApp url="http://127.0.0.1:8090" let:pb />

PbUser

Provides info about the current user and methods to sign in (email and password) or sign up (name, email, password and password confirmation) and to sign out. It must the receive the pocketbase instance provided by PbApp to work. It has 2 slots:

  • default : provides user info and sing out method
  • signedOut: provides sign in and sign up methods to be used in your form. This slot already has a basic form provided

The transition between the default slot (user is authenticated) and the signedOut one is alreadt handled by the component.

    <script>
        import { PbApp, PbUser } from '@n0n3br/pbkit'
    </script>
    <PbApp url='http://127.0.0.1:8090' let:pb>
        <PbUser {pb} let:user let:signOut/>
            <nav>
                <span>Hello {user?.name}</span>
                <button on:click={signOut()}>Sign Out</button>
            </nav>
            <!-- optional auth form -->
            <div slot="signedOut" let:signIn let:signUp>
                <form
                    on:submit={isSignIn
                        ? signIn(email, password)
                        : signUp(name, email, password, passwordConfirm)}
                >
                    {#if !isSignIn}
                        <input type="text" placeholder="Name" minlength="5" required />
                    {/if}
                    <input type="email" placeholder="Email" required />
                    <input type="password" placeholder="Password" required minlength="6" />
                    {#if !isSignIn}
                        <input type="password" placeholder="Password confirm" minlength="6" required />
                    {/if}
                    <button type="submit">{isSignIn ? 'Sign In' : 'Sign Up'}</button>
                    <a href="/" on:click={modeChangeHandler}>{isSignIn ? 'Create account' : 'Sign In'}</a>
                </form>
            </div>
        </PbUser>
    </PbApp>

PbCollection

Provides an array of documents from a collection based on its name. As in PbUser you need to passs the pocketbase instance provided by PbApp. There's also the option to provide a filter and sort order. Besides the data retrieved, there are methods for updating (id and data object), creating (data object) and removing (id) documents.

    <script>
        import { PbApp, PbUser, PbCollection } from '@n0n3br/pbkit'
        let description:string
    </script>

    <PbApp url='http://127.0.0.1:8090' let:pb>
        <PbUser {pb} let:user />
            <!-- filter only user's todos
            and sort by created desc -->
            <PbCollection
                {pb}
                name="todos"
                let:data
                filter={`user='${user?.id}'`}
                sort="-created"
                let:update
                let:remove
                let:create
            >
                <form on:submit={ () => {
                    create({ description, done: false, user: user?.id });
                    description = ""
                }}>
                    <input type="text" bind:value={description} placeholder="New Todo" minlength="6" />
                    <button type="submit">Create</button>
                </form>
                <ul>
                {#each data ?? [] as todo}
                    <li>
                        <button on:click={ remove(todo.id) }>Delete</button>
                        <button on:click={ update(todo.id, { done: !todo.done }) }>Toggle</button>
                        { todo.description }
                    </li>
                {/each}

                </ul>

            <PbCollection>
        </PbUser>
    </PbApp>

PbDocument

Provides one single document based on the collection name and the id of the document. As in PbUser you need to passs the pocketbase instance provided by PbApp.

    <script>
        import { PbApp, PbUser, PbDocument } from '@n0n3br/pbkit'
        const taskCollection = 'tasks'
        const fakeId = 'a1r564e'
    </script>

    <PbApp url='http://127.0.0.1:8090' let:pb>
        <PbUser {pb} let:user let:signOut/>
            <PbDocument collection={tasksCollection} id={fakeId} {pb} let:document>
                { document?.description }
            </PbDocument>
        </PbUser>
    </PbApp>

Notes

  • This library should only run the the client, it is not for server-side data fetching.
  • Requires Pocketbase SDK.
  • I've have not been able to get TS generics to work right in the components, so no intellisense on the data and document slot prop.