NPM.TypeField (NPM v0.6.0)

Copy Markdown View Source

Analyzes the type field from package.json.

The type field determines whether .js files are treated as ES modules ("module") or CommonJS ("commonjs", the default).

Summary

Functions

Checks if the package uses CommonJS.

Checks if a package is a dual CJS/ESM package.

Checks if the package uses ES modules.

Returns the type field value (default: "commonjs").

Determines the module system for a given file path.

Returns the counts of ESM vs CJS packages.

Functions

cjs?(data)

@spec cjs?(map()) :: boolean()

Checks if the package uses CommonJS.

dual?(data)

@spec dual?(map()) :: boolean()

Checks if a package is a dual CJS/ESM package.

esm?(data)

@spec esm?(map()) :: boolean()

Checks if the package uses ES modules.

get(arg1)

@spec get(map()) :: String.t()

Returns the type field value (default: "commonjs").

module_type(filepath, data)

@spec module_type(String.t(), map()) :: :esm | :cjs

Determines the module system for a given file path.

stats(packages)

@spec stats([map()]) :: map()

Returns the counts of ESM vs CJS packages.