canirequire

canirequireCommonJS › toformat

Is toformat ESM-only? Can you require() it?

Adds a `toFormat` instance method to decimal.js or big.js

Last verified Sep 9, 2026 against toformat@2.0.0. JSON

CommonJS CommonJS — require() works on every Node.js version

toformat ships CommonJS only. require("toformat") works everywhere. import "toformat" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Latest
2.0.0 (Oct 16, 2017)
Module format
CommonJS
Last CommonJS version
2.0.0
TypeScript types
None
Node engines
not declared
Weekly downloads
254K
License
MIT

Does toformat@2.0.0 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("toformat") from a CommonJS file and import "toformat" from an ES module.

Runtimerequire("toformat")import "toformat"
Node.js 18✓ works✓ works
Node.js 20✓ works✓ works
Node.js 22✓ works✓ works
Node.js 24✓ works✓ works
Node.js 26✓ works✓ works
Bun 1.4✓ works✓ works

How to import toformat

ES modules (import)

import toformat from "toformat";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const toformat = require("toformat");

Module format by version

Derived from the type, main and exports fields of every stable release on npm (2 versions; the newest 2 shown).

VersionsFormatFirst published
1.0.0 – 2.0.0CommonJSFeb 10, 2016

Frequently asked

Is toformat ESM-only?

toformat@2.0.0 is a CommonJS package. toformat ships CommonJS only. require("toformat") works everywhere. import "toformat" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import toformat with ES module syntax?

Yes. import toformat from "toformat" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does toformat work in Bun?

Yes. import "toformat" loaded successfully in Bun 1.4 on Sep 9, 2026.

Does toformat ship TypeScript types?

No. toformat ships no type declarations and there is no @types package for it.

Links

Other commonjs packages

Similar popularity