Registry / productivity / msg-format

msg-format

JSON →
library1.0.4jsnpmunverified

A JavaScript string formatting library inspired by Java's MessageFormat class, supporting placeholder substitution ({0}, {1}), date/time formatting with patterns, and localization for 7 locales (English, French, German, Chinese, Russian, Arabic, Japanese). Current stable version is 1.0.4, last updated in 2018 with no recent releases. It offers a simple API similar to Java's MessageFormat but is limited to basic numeric placeholders and predefined locale patterns. Alternatives like Intl.MessageFormat or format-message provide more modern i18n capabilities with ICU syntax and better browser support.

npm install msg-format
INSTALL
IMPORT
SIG · MSG-FORMAT
M
msg-format
productivityjavascriptv1.0.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.

MessageFormat
import { MessageFormat } from 'msg-format'
import MessageFormat from 'msg-format'
Named export, not default. Also works with require: const { MessageFormat } = require('msg-format')
MessageLocale
import { MessageLocale } from 'msg-format'
import { MessageLocale } from 'msg-format/locale'
Named export from main package. Contains locale constants like MessageLocale.fr_FR.
MessageFormat.format
MessageFormat.format(text, arg1, arg2, ...)
MessageFormat.format(text, [arg1, arg2])
Accepts either multiple arguments after text or an array as second argument, but not both. Array form: MessageFormat.format(text, [arg1, arg2])

Shows basic placeholder substitution, date formatting, and localized format with French locale.

const { MessageFormat, MessageLocale } = require('msg-format'); // String placeholder console.log(MessageFormat.format('Hello {0}!', 'World')); // Output: Hello World! // Date/time const now = new Date(); console.log(MessageFormat.format('Today: {0, date}', now)); // Output: Today: 21/07/2018 (locale-dependent) // Localization console.log(MessageFormat.formatWithLocale('Bonjour {0}, aujourd\'hui est {1, date, EEEE}', MessageLocale.fr_FR, 'Jean', now)); // Output: Bonjour Jean, aujourd'hui est dimanche
Debug
Known issues
gotchaNo type definitions. Package does not include TypeScript declarations. Users must create their own .d.ts or use @types/msg-format (which does not exist).
fix
If using TypeScript, declare module 'msg-format' with interface or use // @ts-ignore.
affects: >=1.0.0
gotchaLimited locale support. Only 7 locales are available. Unsupported locales fall back to default English behavior, potentially causing incorrect date/time formats.
fix
Check if your target locale is in MessageLocale before using. If not, consider an alternative like Intl.DateTimeFormat.
affects: >=1.0.0
deprecatedNo updates since 2018. The package is in maintenance mode; no new features or security fixes are expected.
fix
Evaluate migration to actively maintained alternatives like intl-messageformat or format-message.
affects: >=1.0.4
gotchaFormat with locale function name differs from typical i18n libraries. Use formatWithLocale, not a separate locale parameter on format.
fix
Use MessageFormat.formatWithLocale(text, locale, ...args) instead of passing locale to format().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: MessageFormat.format is not a function
Using default import instead of named import.
fix
Use const { MessageFormat } = require('msg-format');
MessageFormat is not defined
Forgot to import the package or incorrect import path.
fix
Add const { MessageFormat } = require('msg-format'); at the top of the file.
Invalid date format: {0, date, UNKNOWN}
Unsupported date/time style or pattern.
fix
Use only the predefined styles: short, medium, long, full, or EEEE for day-of-week. Refer to documentation for supported patterns.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
msg-format — npm install msg-format · libregistry