{"id":15703,"library":"microseconds","title":"Microsecond Time Utility","description":"The `microseconds` package provides a utility to generate and parse timestamps with microsecond precision. It currently stands at version 0.2.0, with its last update occurring approximately six years ago (December 2019). This indicates that the package is no longer actively maintained. It intelligently adapts to the execution environment, utilizing `process.hrtime` for high-resolution timing in Node.js and `performance.now()` in browsers. If neither is available, it falls back to `Date.now() * 1000` for a lower-resolution microsecond timestamp. Key functionalities include `μs.now()` for current microsecond timestamps, `μs.parse()` to convert a microsecond value into a structured object or human-readable string, and `μs.since()` to calculate elapsed time. Due to its abandoned status, developers should consider more modern and actively maintained alternatives for critical applications requiring robust time precision.","status":"abandoned","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/kamicane/microseconds","tags":["javascript","microseconds","microtime","time parser"],"install":[{"cmd":"npm install microseconds","lang":"bash","label":"npm"},{"cmd":"yarn add microseconds","lang":"bash","label":"yarn"},{"cmd":"pnpm add microseconds","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only. Attempting to use ESM `import` syntax will likely fail or require transpilation/configuration in modern JavaScript environments.","wrong":"import μs from 'microseconds'","symbol":"μs","correct":"const μs = require('microseconds')"},{"note":"The `now()` method is directly available on the default CommonJS export to get a microsecond timestamp.","symbol":"μs.now","correct":"const now = μs.now()"},{"note":"The `parse()` method takes a microsecond timestamp and returns an object or a human-readable string representation via `toString()`.","symbol":"μs.parse","correct":"const parsed = μs.parse(timestamp)"}],"quickstart":{"code":"const μs = require('microseconds');\n\n// Get current timestamp in microseconds\nconst now = μs.now();\nconsole.log(`Current microseconds: ${now}`);\n// Example output: Current microseconds: 1713540843123456\n\n// Simulate some work\nfor (let i = 0; i < 10000; i++) {\n  Math.sin(i);\n}\n\n// Get time elapsed since 'now'\nconst elapsed = μs.since(now);\nconsole.log(`Time elapsed (microseconds): ${elapsed}`);\n// Example output: Time elapsed (microseconds): 12345\n\n// Parse a microsecond value into an object\nconst parsed = μs.parse(123456789123456);\nconsole.log('Parsed object:', parsed);\n// Example output: Parsed object: { microseconds: 456, milliseconds: 123, seconds: 89, minutes: 23, hours: 14, days: 1428 }\n\n// Convert parsed object to a human-readable string\nconsole.log('Parsed string:', parsed.toString());\n// Example output: Parsed string: 1428 days 14 hours 23 minutes 89 seconds 123 milliseconds 456 microseconds\n\n// Parse a smaller value\nconsole.log(μs.parse(5000).toString()); // 5 milliseconds\nconsole.log(μs.parse(1).toString());   // 1 microsecond","lang":"javascript","description":"Demonstrates generating current microsecond timestamps, calculating elapsed time, and parsing microsecond values into structured objects and human-readable strings."},"warnings":[{"fix":"Consider migrating to actively maintained alternatives like `precise-now` or `microtime` (by wadey) for high-resolution timing, which offer better compatibility and ongoing support.","message":"This package is no longer maintained. It was last published over six years ago, meaning it does not receive updates for new Node.js versions, browser API changes, or security fixes. Users should be aware of potential compatibility issues or unaddressed vulnerabilities.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"Ensure your project is configured for CommonJS, or use `require()` within an ESM module (e.g., `import { createRequire } from 'module'; const require = createRequire(import.meta.url); const μs = require('microseconds');`) or use a bundler that handles CJS-to-ESM conversion.","message":"The package is CommonJS-only. Attempting to use ESM `import` syntax (`import μs from 'microseconds'`) directly in a pure ES module environment will result in errors.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Always test the actual resolution in your target environment. For critical applications, ensure the high-resolution timers are indeed available and not falling back to lower precision.","message":"Precision and resolution can vary across environments. While it attempts to use high-resolution timers (`hrtime`, `performance.now`), it falls back to `Date.now() * 1000` if those are unavailable. This fallback significantly reduces actual microsecond precision.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Use the correct CommonJS `require` syntax: `const μs = require('microseconds')`.","cause":"Attempting to `import μs from 'microseconds'` in an ESM module, or incorrectly destructuring a CommonJS module that exports a single function/object.","error":"TypeError: microseconds is not a function"},{"fix":"Either convert your project to an ES module (by adding `\"type\": \"module\"` to `package.json` and potentially refactoring other `require`s) or revert to the CommonJS `require()` statement for this package: `const μs = require('microseconds')`.","cause":"Trying to use `import μs from 'microseconds'` in a Node.js script that is interpreted as CommonJS (e.g., a `.js` file without `\"type\": \"module\"` in `package.json`).","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}