# `NPM.Exports`
[🔗](https://github.com/elixir-volt/npm_ex/blob/v0.5.3/lib/npm/exports.ex#L1)

Parse and resolve the `exports` field from `package.json`.

Modern npm packages use the `exports` field (a.k.a. "export map") to
define entry points and restrict access to internal modules.

Supports:
- String shorthand: `"exports": "./index.js"`
- Subpath exports: `"exports": { ".": "./index.js", "./utils": "./lib/utils.js" }`
- Conditional exports: `"exports": { "import": "./esm.js", "require": "./cjs.js" }`
- Nested conditions: `"exports": { ".": { "import": "./esm.js", "default": "./cjs.js" } }`

# `export_map`

```elixir
@type export_map() :: String.t() | %{required(String.t()) =&gt; export_map()} | nil
```

# `conditions`

```elixir
@spec conditions(map() | nil) :: [String.t()]
```

Extracts all conditions used in the export map.

# `exported?`

```elixir
@spec exported?(String.t(), map() | nil) :: boolean()
```

Checks if a subpath is exported by the export map.

# `module_type`

```elixir
@spec module_type(map()) :: :esm | :cjs
```

Detect whether a package uses ESM (`type: "module"`) or CJS.

# `parse`

```elixir
@spec parse(map()) :: %{required(String.t()) =&gt; String.t() | map()} | nil
```

Parse the exports field from a package.json map.

Returns a normalized map of subpath → target mappings, or nil if no exports field.

# `resolve`

```elixir
@spec resolve(map(), String.t(), [String.t()]) :: {:ok, String.t()} | :error
```

Resolve an import path against an export map.

Given a subpath (e.g. `"."`, `"./utils"`) and a list of conditions
(e.g. `["import", "default"]`), returns the resolved file path.

# `subpaths`

```elixir
@spec subpaths(map()) :: [String.t()]
```

List all exported subpaths from an export map.

# `validate`

```elixir
@spec validate(map() | nil, String.t()) ::
  {:ok, [String.t()]} | {:error, [String.t()]}
```

Validates that all export paths resolve to existing files.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
