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

@nivinjoseph/n-ext

v2.0.2

Published

Extensions for core Javascript types

Readme

n-ext

A TypeScript library providing useful extensions for core JavaScript types (Array, String, etc.) with a focus on functional programming and utility methods.

Installation

npm install @nivinjoseph/n-ext

or 

yarn add @nivinjoseph/n-ext

Usage

Import the library in your TypeScript/JavaScript project:

import '@nivinjoseph/n-ext';

Features

Array Extensions

The library provides a rich set of array manipulation methods:

// Basic operations
const numbers = [1, 2, 3, 4, 5];
numbers.contains(3); // true
numbers.remove(3); // true, removes the first occurrence
numbers.clear(); // empties the array

// Functional operations
const users = [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' },
    { id: 3, name: 'Charlie' }
];

// Ordering
const ordered = users.orderBy(u => u.name); // ascending
const orderedDesc = users.orderByDesc(u => u.name); // descending

// Grouping
const grouped = users.groupBy(u => u.name[0]); // groups by first letter

// Distinct values
const unique = [1, 2, 2, 3, 3, 3].distinct(); // [1, 2, 3]

// Pagination
const page1 = users.skip(0).take(2); // first 2 items
const page2 = users.skip(2).take(2); // next 2 items

// Async operations
await users.forEachAsync(async user => {
    await processUser(user);
}, 2); // process 2 users at a time

String Extensions

Enhanced string manipulation capabilities:

// Validation
"".isEmptyOrWhiteSpace(); // true
"  ".isEmptyOrWhiteSpace(); // true
"hello".isEmptyOrWhiteSpace(); // false

// Search
"hello world".contains("world"); // true

// Formatting
StringExt.format("Hello {0}, welcome to {1}", "Alice", "Wonderland"); // "Hello Alice, welcome to Wonderland"

// String cleaning
"abc123".extractNumbers(); // "123"
"abc123".extractCharacters(); // "abc"

// Encoding/Decoding
const encoded = StringExt.base64Encode("hello"); // "aGVsbG8="
const decoded = StringExt.base64Decode(encoded); // "hello"

// URL-safe base64
const urlSafe = StringExt.base64UrlEncode("hello"); // "aGVsbG8"
const decodedUrl = StringExt.base64UrlDecode(urlSafe); // "hello"

// Pattern matching
"abc123".matchesFormat("@@@###"); // true (3 letters followed by 3 numbers)
"abc123".matchesFormat("@@@*"); // true (3 letters followed by anything)

Object Extensions

Enhanced object manipulation capabilities:

const obj = { a: 1, b: { c: 2 } };

// Type information
obj.getTypeName(); // "Object"

// Deep property access
obj.getValue("b.c"); // 2

// Deep property assignment
obj.setValue("b.d", 3);
// obj is now { a: 1, b: { c: 2, d: 3 } }

Math Extensions

Enhanced mathematical operations:

// Percentage calculations
Math.percentage(25, 100); // 25 (25% of 100)
Math.percentagePartial(25, 100); // 25 (25% of 100)
Math.percentageWhole(25, 25); // 100 (25 is 25% of 100)

// Value clamping
Math.clamp(15, 10, 20); // 15 (within range)
Math.clamp(5, 10, 20); // 10 (clamped to min)
Math.clamp(25, 10, 20); // 20 (clamped to max)

// Statistical operations
Math.median([1, 2, 3, 4, 5]); // 3
Math.median([1, 2, 3, 4]); // 2.5

// Linear space generation
Math.linearSpace(0, 10, 5); // [0, 2.5, 5, 7.5, 10]

API Reference

Array Methods

  • contains<T>(value: T): boolean - Checks if array contains a value
  • orderBy<T>(compareFunc?: (value: T) => any): Array<T> - Sorts array in ascending order
  • orderByDesc<T>(compareFunc?: (value: T) => any): Array<T> - Sorts array in descending order
  • groupBy<T>(keyFunc: (value: T) => string): Array<{ key: string; values: Array<T>; }> - Groups array elements by key
  • distinct<T>(compareFunc?: (value: T) => any): Array<T> - Returns unique elements
  • skip<T>(count: number): Array<T> - Skips first n elements
  • take<T>(count: number): Array<T> - Takes first n elements
  • count<T>(predicate?: (value: T) => boolean): number - Counts elements matching predicate
  • remove<T>(value: T): boolean - Removes first occurrence of value
  • clear(): void - Removes all elements
  • equals<T>(compareArray: Array<T>, compareFunc?: (t1: T, t2: T) => boolean): boolean - Compares arrays
  • forEachAsync<T>(asyncFunc: (input: T) => Promise<void>, degreesOfParallelism?: number): Promise<void> - Async forEach
  • mapAsync<T, U>(asyncFunc: (input: T) => Promise<U>, degreesOfParallelism?: number): Promise<Array<U>> - Async map
  • reduceAsync<T, U>(asyncFunc: (acc: U, input: T) => Promise<U>, accumulator?: U): Promise<U> - Async reduce

String Methods

  • isEmptyOrWhiteSpace(): boolean - Checks if string is empty or whitespace
  • contains(search: string): boolean - Checks if string contains substring
  • extractNumbers(): string - Extracts only numbers from string
  • extractCharacters(): string - Extracts only letters from string
  • format(formatString: string, ...params: any[]): string - Formats string with parameters
  • base64Encode(): string - Base64 encodes string
  • base64Decode(): string - Base64 decodes string
  • base64UrlEncode(): string - URL-safe Base64 encodes string
  • base64UrlDecode(): string - URL-safe Base64 decodes string
  • hexEncode(): string - Hex encodes string
  • hexDecode(): string - Hex decodes string
  • matchesFormat(format: string): boolean - Checks if string matches format pattern

Object Methods

  • getTypeName(): string - Gets the type name of the object
  • getValue(key: string): any - Gets a value from the object using dot-notation path
  • setValue(key: string, value: any): void - Sets a value in the object using dot-notation path

Math Methods

  • percentage(partialValue: number, wholeValue: number): number - Calculates percentage
  • percentagePartial(percentage: number, wholeValue: number): number - Calculates partial value from percentage
  • percentageWhole(percentage: number, partialValue: number): number - Calculates whole value from percentage
  • clamp(value: number, min: number, max: number): number - Clamps value between min and max
  • median(values: ReadonlyArray<number>): number | null - Calculates median of values
  • linearSpace(start: number, end: number, count: number): Array<number> - Generates evenly spaced numbers

Contributing

Contributions are welcome! Please follow the existing code style and include tests for new features.

License

This project is licensed under the MIT License - see the LICENSE file for details.