{"id":26481,"library":"tiny-tim","title":"tiny-tim","description":"A minimal, zero-dependency timer utility for Node.js and the browser. Current stable version 0.0.4 (unreleased release cadence). Tiny-tim provides a simple timer that returns elapsed time in configurable units (ms, s, m, h) with optional suffix. Its key differentiator is extreme small size (156 bytes minified) and simplicity, offering a single function that creates a reusable stopwatch. Compiled with babili for both ES6+ and CommonJS environments. No dependencies, suitable for lightweight instrumentation.","status":"active","version":"0.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/sdgluck/tiny-tim","tags":["javascript","timer","tiny","profile","stopwatch","stop","watch","tim"],"install":[{"cmd":"npm install tiny-tim","lang":"bash","label":"npm"},{"cmd":"yarn add tiny-tim","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiny-tim","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default export is a function. ESM import works directly; CommonJS require returns the function itself, not a module with default property.","wrong":"const timer = require('tiny-tim').default","symbol":"default","correct":"import timer from 'tiny-tim'"},{"note":"CommonJS require returns the timer function directly. ESM default import matches this pattern.","wrong":"import { timer } from 'tiny-tim'","symbol":"default","correct":"const timer = require('tiny-tim')"}],"quickstart":{"code":"import timer from 'tiny-tim';\n\n// Create a timer in seconds with suffix\nconst stopwatch = timer('s', true);\n\nsetTimeout(() => {\n  const elapsed = stopwatch();\n  console.log(elapsed); // '10s'\n}, 10000);\n\n// Reuse the same timer\nsetTimeout(() => {\n  console.log(stopwatch()); // '15s'\n}, 15000);\n\n// Create timer in milliseconds without suffix\nconst msTimer = timer();\nsetTimeout(() => {\n  console.log(msTimer()); // 1000 (number)\n}, 1000);","lang":"javascript","description":"Creates a reusable timer, demonstrates returning elapsed time with suffix as string and without suffix as number."},"warnings":[{"fix":"Check the type of the returned value if relying on specific data type.","message":"Timer function returns either a string (with suffix) or a number (without suffix). Developers may expect consistent types.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Recreate the timer for a new measurement; cannot restart an existing timer.","message":"The timer is not paused or reset externally; calling the returned function stops the timer and returns the elapsed time. Subsequent calls return the same value (timer dead after first call).","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use only 'ms', 's', 'm', or 'h'.","message":"Units are single-letter strings. Using full words like 'seconds' will be treated as unrecognized unit, defaulting to milliseconds silently.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Validate unit string before passing to timer().","message":"No error thrown for invalid units; timer silently defaults to milliseconds.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'import timer from \"tiny-tim\"' instead of 'import { timer } from \"tiny-tim\"'.","cause":"Importing as named import instead of default import in ESM.","error":"timer is not a function"},{"fix":"Use 'const timer = require(\"tiny-tim\")' directly without .default.","cause":"Trying to access .default on CommonJS require result, which already returns the function.","error":"require(...).default is not a function"},{"fix":"Run 'npm install tiny-tim' in your project root.","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'tiny-tim'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}