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

@kkapoor/utils

v4.1.0

Published

Utility functions and components

Readme

@kkapoor/utils

A collection of utility functions and types for TypeScript/JavaScript projects, with a focus on Next.js applications.

Current version: 4.0.0

This package provides both full and mini distributions. The mini distribution (/dist/mini) contains a subset of utilities optimized for smaller bundle sizes. You can import from the mini distribution using:

import { ... } from '@kkapoor/utils/mini';

Installation

npm install @kkapoor/utils
# or
yarn add @kkapoor/utils
# or
pnpm add @kkapoor/utils

Features

Type Utilities

  • NonEmptyObject<T>: Ensures an object has at least one required property
  • NonEmptyArray<T>: Type for arrays that must have at least one element

Caching Utilities

The package provides a powerful caching mechanism through the createCacher function, which integrates with Next.js's unstable_cache:

import { createCacher } from '@kkapoor/utils/cache';

const cache = createCacher({
    cacheSubjects: ['users', 'posts'],
    logPrimaryTagInDev: true,
});

const fetchUser = cache(
    async (params: { id: string }) => {
        // Your async function here
        return await fetchUserData(params.id);
    },
    { tags: { subject: 'users' }, revalidate: 60 * 5 }
);

The createCacher function is no longer applicable when using cacheComponents from NextJS v16 onwards, and it is suggested to use the 'use cache' directive. However, other utilities can be used from this submodule.

General Utilities

Development Logging

import { devLog } from '@kkapoor/utils/general';

devLog('This will only log in development mode');

Maybe Function

import { maybe } from '@kkapoor/utils/general';

const value = maybe(someValue); // Returns null if value is falsy

Pipe Functions

import { pipe, createPipeFn } from '@kkapoor/utils/general';

// Direct pipe
const result = pipe(initialValue, transform1, transform2, transform3);

// Create reusable pipe function
const myPipe = createPipeFn(transform1, transform2, transform3);
const result = myPipe(initialValue);

Time Utilities

import { getSeconds } from '@kkapoor/utils/general';

const seconds = getSeconds({
    days: 1,
    hours: 2,
    minutes: 30,
    seconds: 45,
});

Authentication Utilities - DEPRECATED

npm install @kkapoor/next-jose-auth

The package provides a robust JWT-based authentication system through the createAuthenticationClient function:

import { createAuthenticationClient } from '@kkapoor/utils/auth';

const auth = createAuthenticationClient({
    tokenPreferences: {
        ACCESS: {
            cookieName: 'access_token',
            maxAge: 60 * 15, // 15 minutes
            secret: process.env.JWT_ACCESS_SECRET!,
        },
        REFRESH: {
            cookieName: 'refresh_token',
            maxAge: 60 * 60 * 24 * 7, // 7 days
            secret: process.env.JWT_REFRESH_SECRET!,
        },
    },
    routePreferences: {
        routes: [
            { path: '/api', private: true },
            { path: '/dashboard', private: true },
            { path: '/auth', ignore: true },
        ],
        redirects: {
            onAuth: '/dashboard',
            onNoAuth: '/auth/login',
        },
    },
    JWTDefaultSettings: {
        issuer: 'your-app',
        alg: 'HS256',
    },
});

// Sign tokens and set cookies
await auth.signTokensAndSetCookie({ userId: '123' });

// Get current session
const session = await auth.getSession();

// Refresh token middleware
export async function middleware(request: NextRequest) {
    return auth.refreshToken(request);
}

## Requirements

-   Node.js 18 or later
-   Next.js >= 15.0.0 (peer dependency)

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

### Constants

```typescript
import { __DEV__ } from '@kkapoor/utils/constants';

if (__DEV__) {
    // Development-only code
}