{"id":13809,"library":"present","title":"High-Resolution Timestamps (present)","description":"The `present` package, currently at version 1.0.0, provides a unified, cross-environment API for obtaining high-resolution timestamps. It is designed to work in both Node.js, where it leverages `process.hrtime`, and various browser environments, where it attempts to use `performance.now()` and its vendor-prefixed equivalents (`webkitNow`, `msNow`, `mozNow`, `oNow`). If no high-resolution API is available, it gracefully falls back to `Date.now()`. A key differentiator is its automatic polyfilling of `performance.now` in browsers upon script inclusion, though this behavior can be reverted using `present.noConflict()`. The package aims to offer consistent, precise timing for performance measurement or other time-sensitive operations across different JavaScript runtimes. Given its version and the nature of its dependencies (native APIs), it appears to be a stable, low-maintenance utility rather than one with frequent releases, typically publishing updates only when underlying platform APIs change significantly or critical bugs are identified.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"git://github.com/dbkaplun/present","tags":["javascript","time","timestamp","high-res","high-resolution","nanosecond","millisecond","performance","now"],"install":[{"cmd":"npm install present","lang":"bash","label":"npm"},{"cmd":"yarn add present","lang":"bash","label":"yarn"},{"cmd":"pnpm add present","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS only, thus standard ES module imports will not work directly in Node.js or modern browser module environments.","wrong":"import present from 'present';","symbol":"present","correct":"const present = require('present');"},{"note":"In browser environments, 'present' is exposed as a global variable. Attempting ES module imports will fail.","wrong":"import { present } from 'present';","symbol":"present","correct":"// Accessible globally after <script src=\"path/to/present.min.js\"></script>"},{"note":"Utility methods like 'noConflict' are properties of the main 'present' function/object, not separate named exports.","wrong":"import { noConflict } from 'present';","symbol":"present.noConflict","correct":"present.noConflict(); // After importing 'present' (Node) or loading script (Browser)"}],"quickstart":{"code":"const present = require('present');\n\n// Get a high-resolution timestamp in milliseconds\nconst timestamp1 = present();\nconsole.log('First timestamp:', timestamp1);\n\n// Simulate some work\nfor (let i = 0; i < 1e6; i++) { /* busy-wait */ }\n\nconst timestamp2 = present();\nconsole.log('Second timestamp:', timestamp2);\nconsole.log('Elapsed time:', timestamp2 - timestamp1, 'ms');\n\n// Browser-specific functionality (conceptual)\n// If loaded in a browser via a <script> tag:\n// console.log('Performance.now before polyfill:', typeof performance.now);\n// present.noConflict(); // Reverts the polyfill\n// console.log('Performance.now after noConflict:', typeof performance.now);\n// present.conflict(); // Re-applies the polyfill\n// console.log('Performance.now after conflict:', typeof performance.now);\n","lang":"javascript","description":"Demonstrates how to obtain high-resolution timestamps in Node.js and conceptually shows browser-specific functions like `noConflict` to manage polyfilling."},"warnings":[{"fix":"For Node.js, use `const present = require('present');`. For browsers, load via a `<script>` tag and access the global `present` variable.","message":"This package is CommonJS (CJS) only and does not provide ES module (ESM) exports. Direct `import` statements for `present` will fail in modern Node.js environments configured for ESM or in browser module contexts.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call `present.noConflict()` immediately after the script loads if you wish to revert `performance.now` to its original state and manage polyfilling manually or via another library.","message":"In browser environments, `present.js` automatically polyfills `performance.now` upon script inclusion. This default behavior might conflict with other polyfills or if you intend to use the native `performance.now` directly without `present`'s intervention.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the target environment supports `performance.now()` for critical high-resolution timing. Add checks to verify the precision if absolute accuracy is paramount, e.g., by comparing `present()` output to expected resolution.","message":"The package falls back to `Date.now()` if `performance.now()` (or its vendor-prefixed variants) are unavailable. This can lead to silently lower precision (millisecond instead of microsecond/nanosecond resolution) on older or less capable platforms, potentially impacting the accuracy of performance measurements.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"No direct fix required for existing code, but be aware that the internal mechanisms might rely on outdated browser APIs. For new projects, consider using `performance.now()` directly if broad polyfill support is not strictly needed for extremely old browsers.","message":"The package attempts to use various deprecated `performance.vendorPrefixNow()` methods (e.g., `webkitNow`, `msNow`). While these fallbacks are harmless in modern browsers, relying on them for future compatibility is not recommended, as `performance.now()` is widely standardized.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':12 'across':111 'aim':96 'api':19,63,125,149 'appear':127 'attempt':44 'automat':77 'avail':65 'back':69 'behavior':88 'browser':40,82 'bug':154 'chang':150 'consist':99 'critic':153 'cross':17 'cross-environ':16 'current':9 'date.now':71 'depend':123 'design':28 'differ':112 'differenti':74 'environ':18,41 'equival':53 'fall':68 'frequent':140 'given':115 'grace':67 'high':2,23,61,161,164 'high-r':160 'high-resolut':1,22,60,163 'identifi':156 'inclus':85 'javascript':113,157 'key':73 'leverag':36 'low':133 'low-mainten':132 'mainten':134 'measur':104 'millisecond':167 'moznow':56 'msnow':55 'nanosecond':166 'nativ':124 'natur':120 'node.js':33 'obtain':21 'offer':98 'one':138 'onow':57 'oper':110 'packag':8,95 'perform':103,168 'performance.now':47,80 'platform':148 'polyfil':78 'precis':100 'prefix':52 'present':5,7 'present.noconflict':93 'process.hrtime':37 'provid':13 'publish':143 'rather':136 'releas':141 'res':162 'resolut':3,24,62,165 'revert':91 'runtim':114 'script':84 'sensit':109 'signific':151 'stabl':131 'though':86 'time':101,108,158 'time-sensit':107 'timestamp':4,25,159 'typic':142 'under':147 'unifi':15 'updat':144 'upon':83 'use':46,92 'util':135 'various':39 'vendor':51 'vendor-prefix':50 'version':11,117 'webkitnow':54 'work':30","created_at":"2026-04-20T01:56:25.506439+00:00","updated_at":"2026-04-20T01:56:25.506439+00:00","problems":[{"fix":"For browsers, load `present.min.js` via a `<script>` tag and access the global `present` variable. For Node.js ESM, consider using a CJS wrapper or an alternative library with ESM support.","cause":"Attempting to use `require()` in a browser environment or in a Node.js ESM module.","error":"ReferenceError: require is not defined"},{"fix":"In Node.js, ensure you use `const present = require('present');`. In browsers, verify the script tag loaded correctly and `present` is a global function.","cause":"Incorrectly importing or accessing the `present` module/global, often by attempting a named or default ES module import.","error":"TypeError: present is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.6.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/dbkaplun/present","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/present","openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}