Registry / productivity / lit-date

lit-date

JSON →
library1.0.5jsnpmunverified

Lit-date is a lightweight (~1kB gzipped) and fast datetime formatter for modern browsers, using template literals for formatting. Version 1.0.5 is the current stable release. Unlike moment.js or date-fns, it uses tagged template literals (e.g., litdate`${'YYYY'}/${'MM'}/${'DD'}`(date)) and supports internationalization via custom functions. It is significantly faster than Moment.js and Day.js based on benchmarks. The library ships TypeScript types and supports both Node.js and browser environments via ESM or UMD bundles.

npm install lit-date
INSTALL
IMPORT
SIG · LIT-DATE
L
lit-date
productivityjavascriptv1.0.5
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.

litdate
✓ import litdate from 'lit-date'
✗ const litdate = require('lit-date')
lit-date is an ESM-only package; CommonJS require() will not work.
litdate (default export as function)
✓ import litdate from 'lit-date'; const format = litdate`${'YYYY'}/${'MM'}/${'DD'}`;
✗ const { litdate } = require('lit-date')
litdate is the default export, not a named export.
TypeScript types
✓ import litdate from 'lit-date'
TypeScript types are included; no separate @types package needed.

Demonstrates basic usage of lit-date with a template literal to format a Date object into a custom string pattern.

import litdate from 'lit-date'; const format = litdate`${'YYYY'}/${'MM'}/${'DD'} ${'HH'}:${'mm'}:${'ss'}`; const now = new Date(); console.log(format(now)); // e.g., "2023/04/01 12:30:45"
Debug
Known issues
gotchaTemplate literal placeholders must be string literals like `${'YYYY'}`, not variables. Using variables like `${year}` will not work.
fix
Ensure all placeholders are string literals: `${'YYYY'}` instead of `${year}`.
affects: >=1.0.0
gotchaThe function returned by the tagged template is curried; you must call it with a Date object to get a string. Forgetting the second invocation returns a function.
fix
Always call the result: litdate`...`(date).
affects: >=1.0.0
gotchalit-date does not support timezone formatting; dates are always formatted in local time.
fix
Use a library like date-fns-tz if timezone support is needed.
affects: >=1.0.0
gotchaThe package is ESM-only; it cannot be used with require() in Node.js without dynamic import or transpilation.
fix
Use import or dynamic import(). For CommonJS projects, consider using a bundler or switching to a compatible library.
affects: >=1.0.0
gotchaBundlePhobia shows the package as ~1kB gzipped, but tree-shaking may not remove unused format tokens because the template literal structure is static.
fix
Only include the format tokens you need; unused tokens add minimal size.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected template string
Using variables inside template literal instead of string literals, e.g., litdate`${year}` instead of litdate`${'year'}`.
fix
Replace variable placeholders with string literals: litdate`${'YYYY'}`.
TypeError: litdate is not a function
Attempting to use require() to import the package, which is ESM-only.
fix
Change to import litdate from 'lit-date' or use dynamic import().
ReferenceError: litdate is not defined
Forgetting to import the package or using a CDN script without proper module type.
fix
Add <script type="module"> and import litdate from the CDN URL.
TypeError: (intermediate value) is not a function
Calling the result of litdate`...` incorrectly, e.g., litdate`${'YYYY'}`(new Date()) where the tagged template returns a function, but forgetting to call it.
fix
Ensure the template literal is immediately invoked: litdate`${'YYYY'}`(new Date()).
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
lit-date — npm install lit-date · libregistry