{"id":10565,"library":"bare-utils","title":"Bare Utils","description":"`bare-utils` is a JavaScript utility library designed to provide Node.js-compatible functions primarily for the Bare runtime, a specialized environment often used within the Holepunch and Hypercore ecosystems. It offers a subset of commonly used functionalities akin to Node.js's built-in `util` module, ensuring that developers can leverage familiar utility patterns when building applications for Bare. The library's current stable version is 1.6.0. Its release cadence is typically aligned with the development cycle of the Bare runtime itself, focusing on maintaining API parity and addressing specific needs of the ecosystem. A key differentiator is its explicit compatibility and optimization for the Bare environment, making it a targeted tool rather than a general-purpose utility library for standard Node.js projects.","status":"active","version":"1.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/holepunchto/bare-utils","tags":["javascript"],"install":[{"cmd":"npm install bare-utils","lang":"bash","label":"npm"},{"cmd":"yarn add bare-utils","lang":"bash","label":"yarn"},{"cmd":"pnpm add bare-utils","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary CommonJS import pattern. The module exports an object containing utility functions.","symbol":"util","correct":"const util = require('bare-utils')"},{"note":"For ESM environments, this interop import is typically used to access the default CommonJS export. Direct named imports like `import { format } = 'bare-utils'` will fail as the package is CJS-only.","wrong":"import { format } from 'bare-utils'","symbol":"util","correct":"import util from 'bare-utils'"}],"quickstart":{"code":"const util = require('bare-utils');\n\nconsole.log('Using bare-utils.format to construct strings:');\n\nconst name = 'Alice';\nconst age = 30;\nconst greeting = util.format('Hello, my name is %s and I am %d years old.', name, age);\nconsole.log(`Example 1: ${greeting}`);\n\nconst data = { id: 101, status: 'active' };\nconst dataString = util.format('User data: %j', data);\nconsole.log(`Example 2: ${dataString}`);\n\nconst pi = 3.14159;\nconst percentage = util.format('Pi to two decimal places: %.2f', pi);\nconsole.log(`Example 3: ${percentage}`);\n\nconsole.log('\\nThis quickstart demonstrates various uses of the `format` function, which behaves similarly to Node.js's `util.format`.');","lang":"javascript","description":"Demonstrates how to import and use the `format` utility function with various specifiers."},"warnings":[{"fix":"For ESM, use `import util from 'bare-utils'` and then access functions like `util.format()`.","message":"This package is primarily a CommonJS module. When used in an ES Module (ESM) environment, developers must use `import util from 'bare-utils'` for CJS interop. Direct named imports such as `import { format } from 'bare-utils'` will not work.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult the `bare-utils` source or documentation for exact API coverage. For critical functions, consider implementing polyfills or alternative solutions if `bare-utils` does not provide the exact behavior required.","message":"The API provided by `bare-utils` is a subset of Node.js's native `util` module. While it aims for compatibility, some functions or specific behaviors present in the full Node.js `util` module might be missing or subtly different. Always verify functionality if migrating from a standard Node.js environment.","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":"If in an ESM file, change `const util = require('bare-utils')` to `import util from 'bare-utils'`. Ensure your `package.json` has `\"type\": \"module\"` for ESM files or use the `.mjs` extension.","cause":"Attempting to use `require()` in an ECMAScript module (ESM) file.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Adjust the import statement in your ESM or bundled code to `import util from 'bare-utils'`, then access the function as `util.format(...)`.","cause":"A bundler (like Webpack) or an ESM environment is attempting to destructure a named export (`format`) from a CommonJS module that exports a default object.","error":"TypeError: __WEBPACK_IMPORTED_MODULE_0__.format is not a function"}],"ecosystem":"npm"}