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

@ashirbad/js-core

v1.0.6

Published

A set of js core utility functions

Downloads

102

Readme

@ashirbad/js-core

Open Source? Yes! Maintained npm bundle size npm Downloads Test Coverage TypeScript

Features

  • 🚀 Zero Dependencies - Lightweight and efficient
  • 💪 Type Safe - Written in TypeScript with full type definitions
  • 🔥 Firebase Ready - Built-in Firebase utilities
  • 💰 Currency Formatting - Support for 160+ currencies
  • 📅 Date Utilities - Comprehensive date manipulation tools
  • Modern - ES6+ ready
  • 🧪 Well Tested - 100% test coverage

Table of Contents

Installation

npm

npm install @ashirbad/js-core

yarn

yarn add @ashirbad/js-core

pnpm

pnpm add @ashirbad/js-core

Usage

Import the functions you need:

import { formatCurrency, getDatesBetween } from '@ashirbad/js-core';

API Reference

Array Utilities

getArrFromObj(object: Record<string, any>, key?: string): Array<any>

Converts an object to an array with customizable ID field.

const obj = { '1': { name: 'John' }, '2': { name: 'Jane' } };
const arr = getArrFromObj(obj); // [{ id: "1", name: "John" }, { id: "2", name: "Jane" }]

getArrFromSnap(snapshot: FirebaseSnapshot, key?: string): Array<any>

Converts a Firebase snapshot to an array.

const arr = getArrFromSnap(snapshot); // [{ id: "doc1", ...data }]

getArrFromNestedSnap(snapshot: FirebaseSnapshot, primaryKey?: string, secondaryKey?: string): Array<any>

Flattens a nested Firebase snapshot into a single array. Useful for handling nested collections in Firebase.

// Example Firebase nested data
const snapshot = {
  val: () => ({
    store1: {
      order1: { product: 'A', quantity: 1 },
      order2: { product: 'B', quantity: 2 },
    },
    store2: {
      order3: { product: 'C', quantity: 3 },
    },
  }),
  exists: () => true,
};

// Default keys
const result1 = getArrFromNestedSnap(snapshot);
/* Output:
[
  { id: 'order1', _id: 'store1', product: 'A', quantity: 1 },
  { id: 'order2', _id: 'store1', product: 'B', quantity: 2 },
  { id: 'order3', _id: 'store2', product: 'C', quantity: 3 }
]
*/

// Custom keys
const result2 = getArrFromNestedSnap(snapshot, 'orderId', 'storeId');
/* Output:
[
  { orderId: 'order1', storeId: 'store1', product: 'A', quantity: 1 },
  { orderId: 'order2', storeId: 'store1', product: 'B', quantity: 2 },
  { orderId: 'order3', storeId: 'store2', product: 'C', quantity: 3 }
]
*/

Currency Utilities

formatCurrency(amount: number, currency?: currency): string

Formats a number as currency with proper localization.

formatCurrency(1000); // "₹1,000.00"
formatCurrency(1000, 'USD'); // "$1,000.00"
formatCurrency(1000, 'EUR'); // "€1,000.00"

Supports 160+ currencies including:

  • USD (US Dollar)
  • EUR (Euro)
  • GBP (British Pound)
  • JPY (Japanese Yen)
  • And many more...

Date Utilities

getFutureDays(numberOfDays?: number): Date[]

Returns an array of future dates.

getFutureDays(3); // Next 3 days as Date objects

getDayName(dayIndex?: number): string

Gets the name of a day by index (0-6).

getDayName(1); // "Monday"
getDayName(); // Current day name

getDatesBetween(startDate: Date, endDate: Date, includeEndDate?: boolean): Date[]

Returns an array of dates between two dates.

const dates = getDatesBetween(new Date('2024-01-01'), new Date('2024-01-05'));

TypeScript Support

This library is written in TypeScript and includes type definitions. Types are automatically imported when using TypeScript.

import { currency } from '@ashirbad/js-core';

const price: number = 1000;
const formattedPrice: string = formatCurrency(price, 'USD');

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

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

Support

  • Star this repository
  • Report issues
  • Submit Pull Requests
  • Spread the word

Made with ❤️ by Ashirbad Panigrahi