Skip to content

parsePackageJson

parsePackageJson(text): PackageJson | undefined

Defined in: parse-package-json.ts:25

Parses package.json text. Returns undefined for anything that isn’t a JSON object — invalid JSON, or valid JSON of another type (an array, null, a string) — rather than throwing. A leading byte-order mark is ignored, as npm does.

The fields PackageJson types are checked, so the result honours its type: a recognized field of the wrong type (a numeric name, an array dependencies) is left out, and the string-map fields keep only their string-valued entries. Every other field passes through untouched.

string

PackageJson | undefined