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

nestql

v1.1.4

Published

A lightweight utility library for extracting and transforming prefixed keys from flat objects into organized nested structures with customizable casing.

Readme

nestql

A lightweight utility library for extracting and transforming prefixed keys from flat objects into organized nested structures with customizable casing.

Features

  • Prefix-based extraction: Isolate keys with a specific prefix followed by an underscore.
  • Flexible casing: Convert keys to camelCase, snake_case, PascalCase, or keep original casing.
  • Key filtering: Include (pick) or exclude (omit) specific keys; omit takes precedence if both are provided.
  • Error handling: Graceful error handling with optional error throwing.
  • Type-safe: Full TypeScript support with type definitions.

Installation

npm install nestql

Usage

Basic Example

import nestql from "nestql";

const flatUserObject = {
  user_username: "john_doe",
  user_email: "[email protected]",
  user_password: "secretpassword120",
  user_profile_picture: "profile.jpg",
  user_id: 1,
  user_created_at: "2026-05-05T10:30:00.000Z",
  user_updated_at: "2026-05-06T12:00:00.000Z",
  user_is_verified: true,
  user_role: "admin",
  user_last_login_at: "2026-05-07T08:15:45.000Z",
  app_name: "MyApp",
};

const user = nestql(flatUserObject, {
  prefix: "user",
  omit: ["password", "email", "role"], // Exclude sensitive fields
});

// user = {
//   username: 'john_doe',
//   profilePicture: 'profile.jpg',
//   id: 1,
//   createdAt: '2026-05-05T10:30:00.000Z',
//   updatedAt: '2026-05-06T12:00:00.000Z',
//   isVerified: true,
//   lastLoginAt: '2026-05-07T08:15:45.000Z'
// }

Options

| Option | Type | Required | Description | | -------------- | ---------------------------------------- | -------- | ------------------------------------------------------------------------------------- | | prefix | string | Yes | The prefix to filter keys by prefixes (e.g. user, user_info) | | casing | "camel" | "snake" | "pascal" | "keep" | No | Case conversion for keys (default: "camel") | | pick | string[] | No | Only include these keys (flat version & unprefixed). Cannot be used with omit | | omit | string[] | No | Exclude these keys (flat version & unprefixed). Overrides pick if both are provided | | throwOnError | boolean | No | Throw errors instead of logging (default: false) |

Casing Examples

// camelCase (default)
nestql(
  { user_profile_picture: "pic.jpg" },
  { prefix: "user", casing: "camel" }
);
// { profilePicture: 'pic.jpg' }

// snake_case
nestql(
  { user_profile_picture: "pic.jpg" },
  { prefix: "user", casing: "snake" }
);
// { profile_picture: 'pic.jpg' }

// PascalCase
nestql(
  { user_profile_picture: "pic.jpg" },
  { prefix: "user", casing: "pascal" }
);
// { ProfilePicture: 'pic.jpg' }

// Keep original
nestql({ user_profile_picture: "pic.jpg" }, { prefix: "user", casing: "keep" });
// { profile_picture: 'pic.jpg' }

Filtering Keys

// Include only specific keys
nestql(obj, {
  prefix: "user",
  pick: ["username", "email"], // Only these keys
});

// Exclude specific keys
nestql(obj, {
  prefix: "user",
  omit: ["password"], // Exclude these keys
});

Utilities

The library also exports helpful utility functions:

  • capitalize(str: string) - Capitalize the first letter of a string.
  • toSnakeCase(str: string) - Convert a string to snake_case.
  • toCamelCase(str: string) - Convert a string to camelCase.
  • toPascalCase(str: string) - Convert a string to PascalCase.
  • toCasedKey(key: string, casing?: Case) - Convert a key to the specified case.
  • isPureObject(value: unknown) - Check if a value is a pure object (not array, null, etc.).

Error Handling

// Log errors (default behavior)
nestql(invalidInput, { prefix: "user" });
// Console: "nestql: flat object must be a pure object"

// Throw errors
try {
  nestql(invalidInput, { prefix: "user", throwOnError: true });
} catch (error) {
  console.error(error.message);
}

License

MIT