Registry / productivity / dayjs-twitter

dayjs-twitter

JSON →
library0.5.0jsnpmunverified

A day.js plugin that formats dates like Twitter (e.g., 'Now', '10s', '1m', '23h', 'Aug 28', 'Aug 28, 2018'). Version 0.5.0 (stable). Lightweight, localized (supports multiple languages), and extends day.js via the plugin system. Different from similar tools like moment-twitter by being day.js-specific and smaller. Release cadence is low; last update was a few years ago.

npm install dayjs-twitter
INSTALL
IMPORT
SIG · DAYJS-TWITTER
D
dayjs-twitter
productivityjavascriptv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dayjsTwitter
import dayjsTwitter from 'dayjs-twitter'
import { dayjsTwitter } from 'dayjs-twitter'
Default export (not named). Ensure dayjs is imported and extended.
dayjs
import dayjs from 'dayjs'
const dayjs = require('dayjs')
ESM import is preferred; CommonJS requires default export handling.
dayjs.extend
dayjs.extend(dayjsTwitter)
dayjsTwitter()
Must call dayjs.extend() with the plugin, not call plugin directly.

Basic usage: extend dayjs with the plugin and call .twitter() on a dayjs object to get relative time strings.

import dayjs from 'dayjs'; import dayjsTwitter from 'dayjs-twitter'; dayjs.extend(dayjsTwitter); console.log(dayjs().twitter()); // 'Now' console.log(dayjs().subtract(10, 'second').twitter()); // '10s' console.log(dayjs().subtract(1, 'minute').twitter()); // '1m' console.log(dayjs().subtract(23, 'hour').twitter()); // '23h' console.log(dayjs().subtract(1, 'day').twitter()); // 'Aug 28' console.log(dayjs().subtract(1, 'year').twitter()); // 'Aug 28, 2018'
Debug
Known issues
gotchadayjs must be imported and extended before calling .twitter().
fix
Ensure dayjs.extend(dayjsTwitter) is called once before usage.
affects: >=0.1.0
gotchaThe .twitter() method is only available on dayjs instances, not on the dayjs object itself.
fix
Call the method on a dayjs instance, e.g., dayjs().twitter() or dayjs('2020-01-01').twitter().
affects: >=0.1.0
gotchaLocalization: if using a locale other than English, ensure dayjs locale is set before calling .twitter().
fix
Set locale via dayjs.locale('es') before using the plugin.
affects: >=0.1.0
gotchaThe plugin may not work correctly if dayjs version is not compatible. Test with dayjs 1.x.
fix
Use dayjs version 1.x (currently 1.11.x).
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: dayjs(...).twitter is not a function
dayjsTwitter was not extended via dayjs.extend() or was incorrectly imported.
fix
Ensure dayjs.extend(dayjsTwitter) is called after importing the plugin.
SyntaxError: The requested module 'dayjs-twitter' does not provide an export named 'default'
Using named import instead of default import.
fix
Use import dayjsTwitter from 'dayjs-twitter' (no curly braces).
Module not found: Can't resolve 'dayjs-twitter'
dayjs-twitter is not installed or not in node_modules.
fix
Run npm install dayjs-twitter.
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
dayjsrequiredRequired peer dependency; the plugin extends dayjs.
Agent activity
20 hits · last 30 days
node
18
OpenAI (training)
1
Resources
dayjs-twitter — npm install dayjs-twitter · libregistry