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

scopey

v1.0.1

Published

A lightweight, type-safe TypeScript utility for building complex objects through method chaining

Readme

Scopey

A lightweight, type-safe TypeScript utility for building complex objects through method chaining with full type inference.

npm version

Features

  • 🎯 Type-safe: Full TypeScript support with automatic type inference
  • 🔗 Chainable API: Intuitive method chaining for building complex objects
  • 🪶 Lightweight: Zero dependencies, minimal footprint
  • 🧩 Flexible: Works with primitives, objects, arrays, and functions
  • 📦 CommonJS: Maximum compatibility with existing projects

Installation

npm install scopey

or

yarn add scopey

Usage

Basic Example

import { scope } from "scopey";

const config = scope(3000)
  .with((port) => ({ port, host: "localhost" }))
  .with(({ port, host }) => ({ url: `http://${host}:${port}` }))
  .with(({ port }) => ({ isSecure: port === 443 }))
  .value();

console.log(config);
// {
//   port: 3000,
//   host: 'localhost',
//   url: 'http://localhost:3000',
//   isSecure: false
// }

API

scope<T>(value: T)

Creates a new scope with an initial value.

const result = scope(42).value(); // 42
const result2 = scope({ name: "John" }).value(); // { name: 'John' }

.with(transformer)

Transforms the current value. If both the current value and the transformation result are objects, they are merged. Otherwise, the value is replaced.

// Object merging
scope({ a: 1 })
  .with(() => ({ b: 2 }))
  .value(); // { a: 1, b: 2 }

// Value replacement
scope("hello")
  .with(() => ({ message: "world" }))
  .value(); // { message: 'world' }

// Property overwriting
scope({ a: 1, b: 2 })
  .with(() => ({ b: 3, c: 4 }))
  .value(); // { a: 1, b: 3, c: 4 }

.only(transformer)

Replaces the entire value with the transformation result, regardless of types.

scope({ a: 1, b: 2 })
  .only(() => ({ c: 3 }))
  .value(); // { c: 3 }

scope(10)
  .only((x) => x * 2)
  .value(); // 20

.value()

Returns the final value after all transformations.

const result = scope("hello")
  .with((msg) => ({ message: msg }))
  .value(); // { message: 'hello' }

Type Safety

Scopey provides full type inference throughout the chain:

const config = scope(3000)
  .with((port) => ({ port, host: "localhost" }))
  // TypeScript knows the value is now { port: 3000, host: "localhost" }
  .with(({ port, host }) => ({ url: `http://${host}:${port}` }))
  // TypeScript knows the value is now { port: 3000, host: "localhost,
  // url: "http://localhost:3000" }
  .value();

// TypeScript error: Property 'invalid' does not exist
// .with(({ invalid }) => ({ ... }))

Development

Setup

# Install dependencies
npm install

# Run tests
npm test

# Run tests with coverage
npm run test:coverage

# Build the project
npm run build

# Run linting
npm run lint

# Type checking
npm run typecheck

Project Structure

scopey/
├── src/
│   ├── index.ts        # Main implementation
│   └── index.test.ts   # Test suite
├── dist/               # Compiled output (generated)
├── coverage/           # Test coverage reports (generated)
├── .github/
│   └── workflows/
│       └── ci.yml      # GitHub Actions CI configuration
├── package.json
├── tsconfig.json       # TypeScript configuration
├── jest.config.js      # Jest configuration
└── README.md

Testing

The project uses Jest for testing with ts-jest for TypeScript support. Tests are located alongside source files with .test.ts extension.

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Generate coverage report
npm run test:coverage

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and ensure all tests pass before submitting a PR.

License

MIT