{"id":18860,"library":"timer-shim","title":"timer-shim","description":"Timer-shim is a lightweight wrapper around setTimeout, setInterval, and clearTimeout/clearInterval that facilitates testing time-dependent code without modifying global state. It provides multiple aliases (e.g., timer.timeout, timer.to, timer.t) for convenience and validates arguments against NaN and non-function values. Version 0.3.0 is stable but appears unmaintained (last release 2012). Unlike sinon's fake timers, timer-shim only stubs calls without advancing time. Its key differentiator is simplicity and avoidance of global overrides, making it suitable for isolated unit tests.","status":"abandoned","version":"0.3.0","language":"javascript","source_language":"en","source_url":"git://github.com/chakrit/timer-shim","tags":["javascript","timer","setTimeout","setInterval","nextTick"],"install":[{"cmd":"npm install timer-shim","lang":"bash","label":"npm"},{"cmd":"yarn add timer-shim","lang":"bash","label":"yarn"},{"cmd":"pnpm add timer-shim","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package uses CommonJS; no ES module export.","wrong":"import timer from 'timer-shim'","symbol":"default export","correct":"const timer = require('timer-shim')"},{"note":"Both argument orders work, but the standard is (delay, fn).","wrong":"timer.timeout(fn, 100)","symbol":"timer.timeout","correct":"timer.timeout(100, fn)"},{"note":"Use timer.clear instead of global clearTimeout for consistency.","wrong":"clearTimeout(handle)","symbol":"timer.clear","correct":"timer.clear(handle)"}],"quickstart":{"code":"const timer = require('timer-shim');\nlet count = 0;\nconst handle = timer.interval(50, () => {\n  count++;\n  console.log(count);\n  if (count === 5) timer.clear(handle);\n});\ntimer.timeout(200, () => console.log('done'));\n\n// Stubbing example:\nconst sinon = require('sinon');\nsinon.stub(timer, 'timeout').callsArg(1);\nlet internalState = false;\nfunction testFn() {\n  timer.timeout(100, () => { internalState = true; });\n}\ntestFn();\nconsole.log(internalState); // true (due to stub)\ntimer.timeout.restore();","lang":"javascript","description":"Demonstrates basic usage of timer.interval and timer.timeout, then shows how to stub timer.timeout with sinon for testing."},"warnings":[{"fix":"Consider using sinon.useFakeTimers or lolex for modern timer testing.","message":"Package is unmaintained since 2012. No updates for over a decade.","severity":"deprecated","affected_versions":"all"},{"fix":"Be consistent: use (delay, function) to avoid ambiguity.","message":"Both argument orders (timeout, fn) and (fn, timeout) are supported. May confuse developers expecting strict order.","severity":"gotcha","affected_versions":"all"},{"fix":"Create a custom .d.ts file or use @ts-ignore.","message":"Package does not provide a TypeScript declaration file. No compile-time type checking.","severity":"gotcha","affected_versions":"all"},{"fix":"Use timer.clear for both, but note that it internally calls clearTimeout. Works for both since handles are just numbers.","message":"timer.clear is aliased to clearTimeout; it does not handle interval handles separately. Both timeouts and intervals are cleared with the same function.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.3.0':48 '2012':56 'advanc':69 'alias':30 'appear':52 'argument':39 'around':11 'avoid':77 'call':67 'cleartimeout/clearinterval':15 'code':22 'conveni':36 'depend':21 'differenti':73 'e.g':31 'facilit':17 'fake':60 'function':45 'global':25,79 'isol':85 'javascript':88 'key':72 'last':54 'lightweight':9 'make':81 'modifi':24 'multipl':29 'nan':41 'nexttick':92 'non':44 'non-funct':43 'overrid':80 'provid':28 'releas':55 'setinterv':13,91 'settimeout':12,90 'shim':3,6,64 'simplic':75 'sinon':58 'stabl':50 'state':26 'stub':66 'suitabl':83 'test':18,87 'time':20,70 'time-depend':19 'timer':2,5,61,63,89 'timer-shim':1,4,62 'timer.t':34 'timer.timeout':32 'timer.to':33 'unit':86 'unlik':57 'unmaintain':53 'valid':38 'valu':46 'version':47 'without':23,68 'wrapper':10","created_at":"2026-04-25T07:40:30.598472+00:00","updated_at":"2026-04-25T07:40:30.598472+00:00","problems":[{"fix":"Ensure the package is installed and use require('timer-shim'). For ES6, use const timer = require('timer-shim');","cause":"Importing the package incorrectly (e.g., using ES6 import in a CommonJS project) or the package was not installed.","error":"TypeError: timer.timeout is not a function"},{"fix":"Verify the require statement: const timer = require('timer-shim'); then call timer.clear(handle);","cause":"Attempting to call timer.clear before the module is fully loaded or using a different variable name.","error":"timer.clear is not a function"},{"fix":"Add: const timer = require('timer-shim'); at the top of the file.","cause":"The timer variable was not declared or scoped incorrectly.","error":"ReferenceError: timer is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/chakrit/timer-shim","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/timer-shim","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-24","install_tag":null}}