Registry / devops / normalize-pkg

normalize-pkg

JSON →
library0.5.0jsnpmunverified

Library for normalizing package.json files using a schema-based approach. Version 0.5.0 (last released 2019) is stable but in maintenance mode. It standardizes fields like repository, author, license, and bin, and can infer missing values from the filesystem. Unlike simple validation tools, it transforms and completes package.json objects according to configurable schema rules. Suitable for CLI tools, scaffolding, or build processes that need consistent package metadata.

npm install normalize-pkg
INSTALL
IMPORT
SIG · NORMALIZE-PKG
N
normalize-pkg
devopsjavascriptv0.5.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import normalizePkg from 'normalize-pkg'
const normalizePkg = require('normalize-pkg')
The package exports a single function; default import is recommended for ESM. CJS require also works.
NormalizePkg
import NormalizePkg from 'normalize-pkg'
const { NormalizePkg } = require('normalize-pkg')
The constructor is the default export; named import is incorrect.
NormalizePkg options
import NormalizePkg from 'normalize-pkg'; const pkg = new NormalizePkg({ knownOnly: true });
const pkg = new NormalizePkg(); pkg.options.knownOnly = true;
Options must be passed to the constructor; setting afterwards may not apply correctly.

Demonstrates importing normalize-pkg, creating an instance, and normalizing a package.json object. Note: uses import assertions for JSON modules.

import NormalizePkg from 'normalize-pkg'; import pkgJson from './package.json' assert { type: 'json' }; const normalizer = new NormalizePkg(); const normalized = normalizer.normalize(pkgJson); console.log(JSON.stringify(normalized, null, 2));
Debug
Known issues
gotchaOptions like knownOnly must be passed to the constructor, not set after instantiation.
fix
Pass options to the constructor: new NormalizePkg({ knownOnly: true })
affects: >=0.1.0
gotchaThe normalize() method mutates the input object; pass a copy if you need to preserve the original.
fix
Use structuredClone or Object.assign: normalizer.normalize({...pkg})
affects: >=0.1.0
deprecatedBower install instructions in README are outdated; Bower is deprecated.
fix
Use npm only: npm install --save normalize-pkg
affects: >=0.1.0
gotchaSome normalizers (e.g., bin) rely on the filesystem and may fail if the current working directory is not a package root.
fix
Ensure process.cwd() contains the expected files or use options to disable filesystem checks.
affects: >=0.3.0
Errors
Common errors & fixes
TypeError: NormalizePkg is not a constructor
Importing named export instead of default export
fix
Use import NormalizePkg from 'normalize-pkg' (default import)
TypeError: config.normalize is not a function
Instantiating without new keywords or using an outdated API
fix
Use new NormalizePkg() and then call .normalize()
Error: Cannot find module 'map-schema'
Missing peer dependency when using npm < 7 or manually installed
fix
Install peer dependencies: npm install map-schema
Upgrade
Version history
0.5.0latest on npm
Audit
Dependencies
map-schemarequiredCore schema engine for field definitions and normalization
project-nameoptionalUsed to infer package name when missing
Agent activity
4 hits · last 30 days
node
4
Resources
normalize-pkg — npm install normalize-pkg · libregistry