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

@adaskothebeast/http-params-processor-value-to-ms-timestamp

v12.0.0

Published

Millisecond timestamp output strategy for HttpParamsProcessor date values.

Readme

⏲️ @adaskothebeast/http-params-processor-value-to-ms-timestamp

Millisecond timestamp output strategy for HttpParamsProcessor: dates as epoch milliseconds, for example 1704067200000.

npm license

Core only, zero runtime dependencies. ESM + CJS. sideEffects: false.


📦 Install

npm i @adaskothebeast/http-params-processor-value-to-ms-timestamp @adaskothebeast/http-params-processor-core

🎯 What it does

This is a value-to strategy: the second half of the conversion pipeline. Pair it with a value-from strategy (-value-from-luxon, -value-from-dayjs, -value-from-moment, -value-from-js-joda, or the DefaultDateValueFromStrategy from core) using createValueConverter.

| Class | Serializes | Example output | | ---------------------------- | ---------- | --------------- | | MsTimestampValueToStrategy | Date | 1704067200000 |

The output is exactly Date.prototype.getTime(), the number JavaScript itself uses internally. It is therefore lossless: feeding the string back into new Date(Number(value)) reproduces the original instant to the millisecond. That makes it the natural choice for Node/JVM backends, Elasticsearch epoch_millis, and cursor style pagination where two events can share a second.


⚡ Usage

import { DefaultDateValueFromStrategy, ParamsProcessor, createValueConverter } from '@adaskothebeast/http-params-processor-core';
import { LuxonDateTimeValueFromStrategy } from '@adaskothebeast/http-params-processor-value-from-luxon';
import { MsTimestampValueToStrategy } from '@adaskothebeast/http-params-processor-value-to-ms-timestamp';
import { DateTime } from 'luxon';

const processor = new ParamsProcessor({
  valueConverters: [
    createValueConverter(new LuxonDateTimeValueFromStrategy(), new MsTimestampValueToStrategy()),
    // keep native Dates working too
    createValueConverter(new DefaultDateValueFromStrategy(), new MsTimestampValueToStrategy()),
  ],
});

processor.process('p', {
  from: DateTime.fromISO('2024-01-01T00:00:00.123Z'),
  to: new Date('2024-06-15T14:30:45.500Z'),
});
// [['p.from', '1704067200123'], ['p.to', '1718461845500']]

Only dates are covered here. If the same request also carries durations or periods, register a converter for them with -value-to-iso or -value-to-nodatime.


🎛️ Options and formats

No constructor options - the output is always date.getTime() rendered as a decimal string.

| Rule | Behaviour | | ----------------- | ---------------------------------------------------------------- | | Unit | Whole milliseconds since 1970-01-01T00:00:00Z | | Time zone | None. The instant is absolute, so the local offset never appears | | Sub-second digits | Preserved exactly, no rounding and no truncation | | Type | string (a decimal integer, no exponent notation, no + sign) |

Compared with the sibling -value-to-unix-timestamp package:

| Instant | ms-timestamp | unix-timestamp | | -------------------------- | --------------- | -------------- | | 2024-01-01T00:00:00.000Z | 1704067200000 | 1704067200 | | 2024-01-01T00:00:00.123Z | 1704067200123 | 1704067200 | | 2024-01-01T00:00:00.999Z | 1704067200999 | 1704067200 |


📤 Output examples

p.from=1704067200000       # 2024-01-01T00:00:00.000Z
p.exact=1704067200123      # 2024-01-01T00:00:00.123Z, milliseconds preserved
p.to=1718461845500         # 2024-06-15T14:30:45.500Z
p.epoch=0                  # 1970-01-01T00:00:00.000Z
p.moon=-14182940000        # 1969-07-20T20:17:40.000Z, pre-epoch dates are negative

⚠️ Edge cases

  • canHandle accepts only real Date instances. Strings such as '2024-01-01' and already-numeric timestamps such as 1704067200000 are rejected, so they fall through to the next converter and reach the default serialization untouched.
  • Invalid dates (new Date('invalid')) are rejected, so NaN never reaches the query string.
  • Pre-1970 dates serialize as negative integers. Backends that parse the parameter into an unsigned type will reject them.
  • The number is well inside Number.MAX_SAFE_INTEGER for any realistic date, so no precision is lost in JavaScript - but a backend that parses it into a 32-bit integer will overflow immediately, since even a present day instant needs far more than 32 bits in milliseconds.
  • The value is timezone agnostic by design. A parameter meant to be a local calendar day should not be an epoch timestamp; use -value-to-date-fns with yyyy-MM-dd instead.
  • Sub-millisecond precision from richer libraries (Luxon, Temporal, js-joda nanoseconds) is already gone by the time the value reaches this strategy, because the neutral shape handed over by every value-from strategy is a JavaScript Date.
  • Timestamps are opaque in logs and dashboards. If a human reads the query string, prefer -value-to-iso, which is equally lossless.

🔗 Related packages

Full matrix and adapter recipes: main README.


📄 License

MIT © Adam Pluciński