{"id":25954,"library":"moment-guess","title":"moment-guess","description":"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.","status":"active","version":"1.2.4","language":"javascript","source_language":"en","source_url":"https://github.com/apoorv-mishra/moment-guess","tags":["javascript"],"install":[{"cmd":"npm install moment-guess","lang":"bash","label":"npm"},{"cmd":"yarn add moment-guess","lang":"bash","label":"yarn"},{"cmd":"pnpm add moment-guess","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for parsing and formatting dates; the library uses moment's token system.","package":"moment","optional":false}],"imports":[{"note":"The package provides a CommonJS default export; ESM import may fail in Node.js without a bundler or ESM wrapper.","wrong":"import guessFormat from 'moment-guess'","symbol":"default","correct":"const guessFormat = require('moment-guess')"},{"note":"The package exports a single function as default, not named. Destructuring will result in undefined.","wrong":"const { guessFormat } = require('moment-guess')","symbol":"guessFormat","correct":"const guessFormat = require('moment-guess')"},{"note":"If using TypeScript or ESM, some bundlers may export default as .default. For safety, check both patterns.","wrong":"const guessFormat = require('moment-guess')","symbol":"guessFormat","correct":"const guessFormat = require('moment-guess').default ?? require('moment-guess')"}],"quickstart":{"code":"const guessFormat = require('moment-guess');\n\n// Default moment format\ntry {\n  console.log(guessFormat('31/12/2020')); // 'DD/MM/YYYY'\n} catch (err) {\n  console.error(err.message);\n}\n\n// Strftime format\ntry {\n  console.log(guessFormat('Fri, January 30th 2020, 10:00 AM', 'strftime'));\n  // '%a, %B %o %Y, %I:%M %p'\n} catch (err) {\n  console.error(err.message);\n}\n\n// Ambiguous input returns array\ntry {\n  console.log(guessFormat('01/01/2020')); // ['DD/MM/YYYY', 'MM/DD/YYYY']\n} catch (err) {\n  console.error(err.message);\n}","lang":"javascript","description":"Shows how to guess date format from a string using moment-guess, including default and strftime outputs, and handling ambiguous input."},"warnings":[{"fix":"Always handle the result as either a string or an array of strings.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap calls in try-catch or validate input beforehand.","message":"Input that cannot be parsed at all throws an error with message 'Couldn't parse date'. This includes completely invalid strings.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check the list of supported tokens in documentation or use default format as fallback.","message":"The 'strftime' format may throw 'Couldn't find strftime modifier for <token>' for unsupported tokens like 'Mo'.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use CommonJS require: const guessFormat = require('moment-guess');","cause":"Attempting to use ES module import (import guessFormat from 'moment-guess') without proper transpilation or in CommonJS environment.","error":"TypeError: guessFormat is not a function"},{"fix":"Ensure the date string follows supported formats (ISO 8601, RFC 2822, slash/dot/dash separated, month-name variants).","cause":"Input date string does not match any recognized pattern.","error":"Couldn't parse date"},{"fix":"Use import * as guessFormat from 'moment-guess' or const guessFormat = require('moment-guess').default;","cause":"Using import guessFormat from 'moment-guess' in TypeScript with default export not properly resolved.","error":"Cannot read property 'default' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}