Registry / serialization / moment-guess

moment-guess

JSON →
library1.2.4jsnpmunverified

A utility package for guessing a date string's format and outputting it as either moment.js format tokens or strftime format tokens. Current version 1.2.4. It relies on moment.js and date-and-time parsers to tokenize input, then applies refiners and assigners to produce the best guess. Useful for developers who need to reverse-engineer a date format from an example string. Unlike other date detection libraries, it supports moment.js and strftime output and handles ambiguous input by returning all possible matches. The package is maintained but has low release cadence.

npm install moment-guess
INSTALL
IMPORT
SIG · MOMENT-GUESS
M
moment-guess
serializationjavascriptv1.2.4
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.

default
const guessFormat = require('moment-guess')
import guessFormat from 'moment-guess'
The package provides a CommonJS default export; ESM import may fail in Node.js without a bundler or ESM wrapper.
guessFormat
const guessFormat = require('moment-guess')
const { guessFormat } = require('moment-guess')
The package exports a single function as default, not named. Destructuring will result in undefined.
guessFormat
const guessFormat = require('moment-guess').default ?? require('moment-guess')
const guessFormat = require('moment-guess')
If using TypeScript or ESM, some bundlers may export default as .default. For safety, check both patterns.

Shows how to guess date format from a string using moment-guess, including default and strftime outputs, and handling ambiguous input.

const guessFormat = require('moment-guess'); // Default moment format try { console.log(guessFormat('31/12/2020')); // 'DD/MM/YYYY' } catch (err) { console.error(err.message); } // Strftime format try { console.log(guessFormat('Fri, January 30th 2020, 10:00 AM', 'strftime')); // '%a, %B %o %Y, %I:%M %p' } catch (err) { console.error(err.message); } // Ambiguous input returns array try { console.log(guessFormat('01/01/2020')); // ['DD/MM/YYYY', 'MM/DD/YYYY'] } catch (err) { console.error(err.message); }
Debug
Known issues
gotchaThe function returns an array when input is ambiguous (e.g., '01/01/2020' for both US and UK formats). Do not assume a single string return.
fix
Always handle the result as either a string or an array of strings.
affects: >=1.0.0
gotchaInput that cannot be parsed at all throws an error with message 'Couldn't parse date'. This includes completely invalid strings.
fix
Wrap calls in try-catch or validate input beforehand.
affects: >=1.0.0
gotchaThe 'strftime' format may throw 'Couldn't find strftime modifier for <token>' for unsupported tokens like 'Mo'.
fix
Check the list of supported tokens in documentation or use default format as fallback.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: guessFormat is not a function
Attempting to use ES module import (import guessFormat from 'moment-guess') without proper transpilation or in CommonJS environment.
fix
Use CommonJS require: const guessFormat = require('moment-guess');
Couldn't parse date
Input date string does not match any recognized pattern.
fix
Ensure the date string follows supported formats (ISO 8601, RFC 2822, slash/dot/dash separated, month-name variants).
Cannot read property 'default' of undefined
Using import guessFormat from 'moment-guess' in TypeScript with default export not properly resolved.
fix
Use import * as guessFormat from 'moment-guess' or const guessFormat = require('moment-guess').default;
Upgrade
Version history
1.2.4latest on npm
Audit
Dependencies
momentrequiredCore dependency for parsing and formatting dates; the library uses moment's token system.
Agent activity
2 hits · last 30 days
node
2
Resources
moment-guess — npm install moment-guess · libregistry