Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

header-timers

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

header-timers

Server-Timing HTTP header helper

  • 0.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
67
decreased by-30.93%
Maintainers
0
Weekly downloads
 
Created
Source

header-timers ⏱️

Server-Timing HTTP header helper
Create timers and report to the browser with a Server-Timing header.
header-timers on npmjs.org »

Contents: InstallUsageGoalsServer-Timing Reference

Install

npm i header-timers

[!NOTE]
This is a Node.js library and won't work in a browser runtime.

Usage

Just .js samples for now:

import HeaderTimers from 'header-timers'

const timers = HeaderTimers()
const { start, stop } = timers

start('open')
stop('open')

start('database', 'collecting data') // with a description

start('analytics', 'log request data')
await new Promise(resolve => setTimeout(resolve, 100))
stop('analytics')

await new Promise(resolve => setTimeout(resolve, 500))
stop('database')

console.log('TIMER COUNT', timers.timers().length) // 3

console.log(timers.key)
// "Server-Timing" - just in case you need it!
console.log(timers.timers())
// [ Array of Timer Objects ]
console.log(timers.values())
/**
 [
   'open;dur=0.026ms',
   'database;desc="collecting data";dur=603.098792ms',
   'analytics;desc="log request data";dur=101.776917ms'
 ]
*/
console.log(timers.value()) 
// "open;dur=0.014ms, database;desc="collecting data";dur=603.512ms, analytics;desc="log request data";dur=101.475709ms"
console.log(timers.string())
// "Server-Timing: open;dur=0.014ms, database;desc="collecting data";dur=603.512ms, analytics;desc="log request data";dur=101.475709ms"
console.log(timers.object())
/**
 {
   'Server-Timing': 'open;dur=0.026ms, database;desc="collecting data";dur=603.098792ms, analytics;desc="log request data";dur=101.776917ms'
 }
*/

Also...

// ...

start("this won't work")
timers.reset()
stop("this won't work")

console.log('TIMER COUNT', timers.timers().length) // 0

start('reset')
await new Promise(resolve => setTimeout(resolve, 100))
stop('reset')

console.log('TIMER COUNT', timers.timers().length) // 1

console.log('NEW Header String', timers.string())
// NEW Header String "Server-Timing: reset;dur=101.799166ms"

And...

// names optional; be aware of the order, though!
start() // 1
stop()  // stop 1 => <1ms

start() // 2
start('foo')
start() // 3

stop() // stop 3 => <1ms

await new Promise(resolve => setTimeout(resolve, 100))

stop() // stop 2 => 100+ms
stop('foo') // => 100+ms

Goals

Be helpful and accurate. Stay small and fast. Then be intuitive. This means:

  • zero dependencies
  • measure in nanoseconds
  • option to disable
  • fast primitives/operations (this needs review)
    • no Classes
  • terse but readable API

"It's just strings all the way down"

Keywords

FAQs

Package last updated on 10 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc