{"id":10912,"library":"format-util","title":"Browser String Format Utility","description":"format-util is a lightweight utility that provides string formatting capabilities for browser environments, closely mirroring the functionality of Node.js's built-in `util.format()`. Its core purpose is to allow developers to use familiar C-style printf-like formatting (e.g., `%s` for strings, `%d` for numbers) within client-side JavaScript. The package is currently at version 1.0.5, with its last update recorded over nine years ago, indicating it is an an abandoned project with no ongoing development or planned release cadence. This lack of maintenance means it does not incorporate modern JavaScript features such as native ES module support or TypeScript definitions. While it once served as a convenient way to port Node.js-style utilities to the browser without heavy dependencies, its age and abandonment position it as a legacy solution for new projects. Developers should be aware of the implications regarding security, compatibility with modern toolchains, and the absence of active support.","status":"abandoned","version":"1.0.5","language":"javascript","source_language":"en","source_url":"https://github.com/tmpfs/format-util","tags":["javascript","format","string","util"],"install":[{"cmd":"npm install format-util","lang":"bash","label":"npm"},{"cmd":"yarn add format-util","lang":"bash","label":"yarn"},{"cmd":"pnpm add format-util","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only (CJS) and does not provide native ES module (ESM) exports. Direct `import` statements will fail without a bundler's CJS interop layer.","wrong":"import { format } from 'format-util';","symbol":"format","correct":"const format = require('format-util');"},{"note":"Designed for older browser environments with CJS bundling (e.g., Browserify). Modern browser applications would typically use native template literals or a more actively maintained library for string formatting, or rely on a bundler to transpile this CJS module.","wrong":"import format from 'format-util';","symbol":"format (for browser)","correct":"var format = require('format-util');"},{"note":"The package does not ship with TypeScript declarations. Users must create a `d.ts` file or use `// @ts-ignore` for TypeScript compatibility.","wrong":"import type { FormatFunction } from 'format-util';","symbol":"Type definitions","correct":"// No built-in types; define manually if using TypeScript."}],"quickstart":{"code":"const format = require('format-util');\n\n// Basic string formatting: %s for strings\nlet message1 = format('Hello, %s!', 'World');\nconsole.log(message1);\n// Expected: \"Hello, World!\"\n\n// Formatting with multiple arguments: %d for numbers\nlet message2 = format('User %d logged in from %s.', 123, '192.168.1.100');\nconsole.log(message2);\n// Expected: \"User 123 logged in from 192.168.1.100.\"\n\n// Handling objects: %j for JSON representation\nlet userInfo = { id: 456, name: 'Alice' };\nlet message3 = format('User data: %j', userInfo);\nconsole.log(message3);\n// Expected: \"User data: {\\\"id\\\":456,\\\"name\\\":\\\"Alice\\\"}\"\n\n// Combining different types and handling extra arguments\nlet message4 = format('Item: %s, Quantity: %d, Price: $%d. Remaining args: %s', 'Laptop', 2, 1200, 'extra data');\nconsole.log(message4);\n// Expected: \"Item: Laptop, Quantity: 2, Price: $1200. Remaining args: extra data\"\n\n// Example demonstrating a common type mismatch (util.format converts non-numbers to NaN for %d)\nlet message5 = format('The number is %d.', 'forty-two');\nconsole.log(message5);\n// Expected: \"The number is NaN.\"\n\n// This utility is often used for building log messages or dynamic display strings.","lang":"javascript","description":"Demonstrates basic string formatting with different specifiers (%s, %d, %j) and argument handling."},"warnings":[{"fix":"Migrate to actively maintained alternatives such as native template literals, or if in Node.js, `util.format` directly. For browser environments requiring similar functionality, consider libraries like `sprintf-js` or roll your own simple formatting utility.","message":"The `format-util` package is abandoned and no longer actively maintained. This means there will be no new features, bug fixes, or security updates. Relying on it in new projects is strongly discouraged.","severity":"breaking","affected_versions":">=1.0.5"},{"fix":"Use `const format = require('format-util');` in CJS environments. In ESM, either configure your bundler (like Webpack or Rollup) for CJS interop, or use dynamic import `import('format-util').then(module => module.exports);` (though this might not work as expected for simple exports).","message":"This package is CommonJS-only. Using it directly with ES module `import` syntax will cause runtime errors in native ESM environments (e.g., Node.js with `type: module` or modern browsers) unless a bundler provides CJS-ESM interop.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Create a declaration file (e.g., `src/types/format-util.d.ts`) with `declare module 'format-util' { function format(...args: any[]): string; export = format; }` or use `// @ts-ignore` to suppress type errors.","message":"There are no official TypeScript type definitions (`.d.ts` files) available for `format-util`. TypeScript projects will not recognize the `format` function without custom declarations.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult the `format-util` source or Node.js `util.format` documentation for specific behavior. For full Node.js `util.format` compatibility in non-Node environments, consider more comprehensive polyfills or reimplementations.","message":"The functionality of `format-util` is a simplified port of Node.js's `util.format`. It may not include all advanced specifiers or behaviors found in the latest Node.js versions of `util.format` (e.g., `%o`, `%O`, custom formatters).","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to `const format = require('format-util');` for CommonJS compatibility.","cause":"Attempting to use ES module named import syntax (`import { format } from 'format-util';`) on a CommonJS-only package.","error":"SyntaxError: Named export 'format' not found. The requested module 'format-util' does not provide an export named 'format'"},{"fix":"Ensure your bundler correctly handles CommonJS modules. In a Node.js CJS environment, stick to `const format = require('format-util');`.","cause":"Occurs when a bundler's CJS-ESM interop is misconfigured, or when attempting to use a default ESM import (`import format from 'format-util';`) where the CJS module exports a single function via `module.exports = fn;` and the interop doesn't correctly resolve it.","error":"TypeError: format is not a function"},{"fix":"Add a custom declaration file (e.g., `format-util.d.ts`) containing `declare module 'format-util' { function format(...args: any[]): string; export = format; }` to your project's `src/types` directory or similar.","cause":"This error appears in TypeScript projects because the `format-util` package lacks official type definitions.","error":"Cannot find name 'format'."}],"ecosystem":"npm"}