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

merge-objects-by-date

v1.0.2

Published

A utility for merging multiple sorted asset arrays by exact matching date using a linear two-pointer scan.

Downloads

98

Readme

README.md

# merge-objects-by-date

A small utility to merge multiple sorted asset arrays by **exact matching date**.

It is built for cases like crypto or stock candles where each asset has the same field name for time, for example `date`.

The merge is simple:

- it only matches rows with the **same exact date**
- it does **not** do multi-timeframe merging
- it uses `keepKey` as the main asset
- fields from `keepKey` stay unchanged
- fields from the other assets are prefixed with their key name

---

## Install

```bash
npm install merge-objects-by-date

Import

import mergeObjectsByDate from 'merge-objects-by-date';

Basic example

const assets = mergeObjectsByDate({
  inputObj: {
    btc: btc_1d,
    eth: eth_1d,
    sol: sol_1d,
  },
  target: 'date',
  keepKey: 'btc',
});

Input format

Each key inside inputObj must be an array of objects.

Example:

const btc_1d = [
  { date: '2024-01-01', open: 42000, close: 43000 },
  { date: '2024-01-02', open: 43000, close: 43500 },
  { date: '2024-01-03', open: 43500, close: 44000 },
];

const eth_1d = [
  { date: '2024-01-01', open: 2200, close: 2250 },
  { date: '2024-01-03', open: 2250, close: 2300 },
];

const sol_1d = [
  { date: '2024-01-01', open: 100, close: 101 },
  { date: '2024-01-03', open: 102, close: 103 },
];

Then:

const result = mergeObjectsByDate({
  inputObj: {
    btc: btc_1d,
    eth: eth_1d,
    sol: sol_1d,
  },
  target: 'date',
  keepKey: 'btc',
});

Output:

[
  {
    date: '2024-01-01',
    open: 42000,
    close: 43000,
    eth_date: '2024-01-01',
    eth_open: 2200,
    eth_close: 2250,
    sol_date: '2024-01-01',
    sol_open: 100,
    sol_close: 101,
  },
  {
    date: '2024-01-03',
    open: 43500,
    close: 44000,
    eth_date: '2024-01-03',
    eth_open: 2250,
    eth_close: 2300,
    sol_date: '2024-01-03',
    sol_open: 102,
    sol_close: 103,
  },
]

Only rows with the same exact date in all assets are merged.


API

mergeObjectsByDate({ inputObj, target, keepKey })

Params

inputObj

An object where:

  • each key is the asset name
  • each value is an array of rows

Example:

{
  btc: btc_1d,
  eth: eth_1d,
  sol: sol_1d,
}

target

The property name that contains the date.

Example:

target: 'date'

keepKey

The main asset to keep as the base row.

Its fields are kept without prefix.

Example:

keepKey: 'btc'

How output keys work

If keepKey is btc:

  • btc fields stay as they are
  • eth fields become eth_date, eth_open, eth_close
  • sol fields become sol_date, sol_open, sol_close

Example output row:

{
  date: '2024-01-01',
  open: 42000,
  close: 43000,
  eth_date: '2024-01-01',
  eth_open: 2200,
  eth_close: 2250,
}

Rules

Your arrays should follow these rules:

  • each asset array must be sorted in ascending date order
  • dates inside the same array must not be duplicated
  • every row must contain the target field
  • all assets must use comparable date values

Supported date values

The library supports common date formats such as:

  • JavaScript Date
  • milliseconds timestamp
  • seconds timestamp
  • date strings like YYYY-MM-DD
  • full date-time strings

Example:

{ date: '2024-01-01' }
{ date: '2024-01-01T00:00:00Z' }
{ date: 1704067200000 }

Notes

This library does exact-date merging only.

It does not:

  • match nearest dates
  • fill missing dates
  • merge across different timeframes
  • do candle interpolation

If a date does not exist in every asset, that row is skipped.


Test

npm test