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

@bvhoach2393/nest-sum

v1.1.8

Published

A NestJS library for safe number summation with MAX_VALUE validation

Readme

@bvhoach2393/nest-sum

A NestJS library for safe number summation with MAX_VALUE validation.

Features

  • Validates input numbers against a configurable MAX_VALUE
  • Integrates with NestJS ConfigService
  • Provides clear error messages for validation failures
  • Full TypeScript support

Installation

npm install @bvhoach2393/nest-sum

Usage

1. Import the module

import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { NestSumModule } from '@bvhoach2393/nest-sum';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    NestSumModule,
  ],
})
export class AppModule {}

2. Use the service

import { Injectable } from '@nestjs/common';
import { NestSumService } from '@bvhoach2393/nest-sum';

@Injectable()
export class MyService {
  constructor(private readonly nestSumService: NestSumService) {}

  calculateSum(a: number, b: number): number {
    return this.nestSumService.sum(a, b);
  }
}

3. Environment configuration

Set the MAX_VALUE in your environment variables:

MAX_VALUE=1000

API

sum(a: number, b: number): number

Calculates the sum of two numbers with validation.

Parameters:

  • a: First number
  • b: Second number

Returns:

  • The sum of a and b

Throws:

  • Error if MAX_VALUE is not configured
  • Error if either a or b exceeds MAX_VALUE

Example

// With MAX_VALUE=100
nestSumService.sum(30, 40); // Returns 70
nestSumService.sum(150, 20); // Throws error: exceeds MAX_VALUE

Testing

Running Unit Tests

To run the unit tests for this library:

# Run tests for the nest-sum library
npm test -- libs/nest-sum

# Run tests with coverage
npm run test:cov -- libs/nest-sum

# Run tests in watch mode
npm run test:watch -- libs/nest-sum

Test Coverage

The library includes comprehensive unit tests covering:

  • ✅ Service initialization
  • ✅ Valid sum calculation within MAX_VALUE
  • ✅ Error handling when MAX_VALUE is not configured
  • ✅ Validation when parameters exceed MAX_VALUE
  • ✅ Console logging for error cases

Development

Local Development

  1. Clone the repository
  2. Install dependencies: npm install
  3. Set up environment: cp .env.example .env
  4. Build the library: npm run build:lib
  5. Run tests: npm test -- libs/nest-sum

Building

# Build the library
npm run build:lib

# Build all projects
npm run build

Publishing to NPM Registry

Prerequisites

  1. Create an NPM account at npmjs.com
  2. Login to NPM: npm login
  3. Verify your account: npm whoami

Publishing Steps

# 1. Navigate to the library directory
cd libs/nest-sum

# 2. Update version in package.json if needed
npm version patch  # or minor/major

# 3. Build the library
cd ../..
npm run build:lib

# 4. Navigate back to library directory
cd libs/nest-sum

# 5. Publish to NPM
npm publish --access public

# For scoped packages, use:
npm publish --access public

Version Management

# Patch version (1.0.0 -> 1.0.1)
npm version patch

# Minor version (1.0.0 -> 1.1.0)
npm version minor

# Major version (1.0.0 -> 2.0.0)
npm version major

Publication Checklist

  • [ ] All tests pass: npm test -- libs/nest-sum
  • [ ] Build successful: npm run build:lib
  • [ ] Version updated in package.json
  • [ ] README.md is up to date
  • [ ] Dependencies are correctly specified as peer dependencies
  • [ ] NPM account has appropriate permissions

Peer Dependencies

  • @nestjs/common: ^10.0.0 || ^11.0.0
  • @nestjs/config: ^3.0.0 || ^4.0.0
  • @nestjs/core: ^10.0.0 || ^11.0.0
  • reflect-metadata: ^0.1.13 || ^0.2.0
  • rxjs: ^7.0.0

License

MIT