{"id":15662476,"url":"https://github.com/jonschlinkert/normalize-pkg","last_synced_at":"2025-04-30T14:42:25.911Z","repository":{"id":15359563,"uuid":"18090503","full_name":"jonschlinkert/normalize-pkg","owner":"jonschlinkert","description":"Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.","archived":false,"fork":false,"pushed_at":"2020-03-02T02:27:08.000Z","size":179,"stargazers_count":18,"open_issues_count":6,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T17:05:59.331Z","etag":null,"topics":["javascript","jonschlinkert","json","node","nodejs","normalize","object","package","packagejson","schema"],"latest_commit_sha":null,"homepage":"https://github.com/jonschlinkert","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonschlinkert.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-25T06:08:22.000Z","updated_at":"2021-05-15T13:00:03.000Z","dependencies_parsed_at":"2022-08-27T00:11:53.359Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/normalize-pkg","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fnormalize-pkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fnormalize-pkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fnormalize-pkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fnormalize-pkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/normalize-pkg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251722857,"owners_count":21633027,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","jonschlinkert","json","node","nodejs","normalize","object","package","packagejson","schema"],"created_at":"2024-10-03T13:32:48.815Z","updated_at":"2025-04-30T14:42:25.888Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","readme":"# normalize-pkg [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68) [![NPM version](https://img.shields.io/npm/v/normalize-pkg.svg?style=flat)](https://www.npmjs.com/package/normalize-pkg) [![NPM monthly downloads](https://img.shields.io/npm/dm/normalize-pkg.svg?style=flat)](https://npmjs.org/package/normalize-pkg) [![NPM total downloads](https://img.shields.io/npm/dt/normalize-pkg.svg?style=flat)](https://npmjs.org/package/normalize-pkg) [![Build Status](https://travis-ci.org/jonschlinkert/normalize-pkg.svg?branch=master)](https://travis-ci.org/jonschlinkert/normalize-pkg)\n\n\u003e Normalize values in package.json using the map-schema library.\n\nPlease consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.\n\n## Table of Contents\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eDetails\u003c/strong\u003e\u003c/summary\u003e\n\n- [Install](#install)\n- [Install](#install-1)\n- [Usage](#usage)\n- [Features](#features)\n- [Schema](#schema)\n- [Defaults](#defaults)\n- [API](#api)\n- [Options](#options)\n  * [options.knownOnly](#optionsknownonly)\n  * [options.pick](#optionspick)\n  * [options.omit](#optionsomit)\n  * [options.fields](#optionsfields)\n  * [options.extend](#optionsextend)\n- [About](#about)\n\n\u003c/details\u003e\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/) (requires [Node.js](https://nodejs.org/en/) \u003e= 0.10.0):\n\n```sh\n$ npm install --save normalize-pkg\n```\n\n## Install\n\nInstall with [bower](https://bower.io/)\n\n```sh\n$ bower install normalize-pkg --save\n```\n\n## Usage\n\n```js\nvar config = require('./')();\nvar pkg = config.normalize(require('./package'));\n```\n\n## Features\n\nNormalizes most package.json fields, and:\n\n* converts `repository` objects to a string\n* stringifies `author` object\n* stringifies each \"person\" object in `maintainers`, `contributors` and `collaborators`\n* converts `licenses` arrays and objects to a `license` string\n* removes files that don't exist from `bin`, `main` and the `files` array\n* adds `cli.js` to `bin` if it exists\n* creates `keywords` array from `name` if not defined\n\nSee the [schema](lib/schema.js), [normalizers](lib/normalizers), and [unit tests](test) for more examples.\n\n## Schema\n\nValues are normalized using a [schema](lib/schema.js) that is passed to [map-schema](https://github.com/jonschlinkert/map-schema).\n\n* only properties that have a corresponding field on the schema will be normalized.\n* any properties that do not have a corresponding field are returned unmodified.\n\nSee the [.field docs](#field) to learn how to add or overwrite a field on the schema.\n\n## Defaults\n\nA `default` value may optionally be defined when a `.field` is registered. When `.normalize` is run and a property that is required or recommended by npm is missing, `normalize-pkg` attempts to create the field if valid data can be found in the repository.\n\nbuilt-in fields have a default value:\n\n* `version`: `'0.1.0'`\n* `license`: `'MIT'`\n* `engines`: `{node: '\u003e= 0.10.0'}`\n\nFor example:\n\n* `name`: the [project-name](https://github.com/jonschlinkert/project-name) library is used to fill in the name\n* `bin`: if empty, populated with `cli.js` or `bin` if either exists on the file system\n\n**Example**\n\nThe following:\n\n```js\nvar config = require('./')();\n\n// no package.json is passed, just an empty object\nvar pkg = config.normalize({});\nconsole.log(pkg);\n```\n\n**Results**\n\nSince an empty object was passed, `normalize-pkg` was smart enough to fill in missing fields looking for info in the project. In this case, specifically from parsing `.git` config and using any defaults defined on the schema.\n\n```js\n{ name: 'normalize-pkg',\n  version: '0.1.0',\n  homepage: 'https://github.com/jonschlinkert/normalize-pkg',\n  repository: 'jonschlinkert/normalize-pkg',\n  license: 'MIT',\n  files: [ 'index.js' ],\n  main: 'index.js',\n  engines: { node: '\u003e= 0.10.0' } }\n```\n\n## API\n\n**Params**\n\n* `options` **{Object}**\n\n**Example**\n\n```js\nconst config = new NormalizePkg();\nconst pkg = config.normalize({\n  author: {\n    name: 'Jon Schlinkert',\n    url: 'https://github.com/jonschlinkert'\n  }\n});\nconsole.log(pkg);\n//=\u003e {author: 'Jon Schlinkert (https://github.com/jonschlinkert)'}\n```\n\n* `normalize` **{Function}**: function to be called on the value when the `.normalize` method is called\n* `default` **{any}**: default value to be used when the package.json property is undefined.\n* `required` **{Boolean}**: define `true` if the property is required\n\n**Params**\n\n* `name` **{String}**: Field name (required)\n* `type` **{String|Array}**: One or more native javascript types allowed for the property value (required)\n* `options` **{Object}**\n* `returns` **{Object}**: Returns the instance\n\n**Example**\n\n```js\nconst config = new NormalizePkg();\n\nconfig.field('foo', 'string', {\n  default: 'bar'\n});\n\nconst pkg = config.normalize({});\nconsole.log(pkg);\n//=\u003e {foo:  'bar'}\n```\n\n**Params**\n\n* `pkg` **{Object}**: The `package.json` object to normalize\n* `options` **{Object}**\n* `returns` **{Object}**: Returns a normalized package.json object.\n\n**Example**\n\n```js\nconst config = new NormalizePkg();\nconst pkg = config.normalize(require('./package.json'));\n```\n\n## Options\n\n### options.knownOnly\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\nOmit properties from package.json that do not have a field registered on the schema.\n\n```js\nvar Config = require('normalize-pkg');\nvar config = new Config({knownOnly: true});\n\nvar pkg = config.normalize({name: 'my-project', foo: 'bar'});\nconsole.log(pkg);\n//=\u003e {name: 'my-project'}\n```\n\n### options.pick\n\n**Type**: `array`\n\n**Default**: `undefined`\n\nFilter the resulting object to contain only the specified keys.\n\n### options.omit\n\n**Type**: `array`\n\n**Default**: `undefined`\n\nRemove the specified keys from the resulting object.\n\n### options.fields\n\nPass a `fields` object on the options to customize any fields on the schema (also see [options.extend](#options-extend)):\n\n```js\nvar pkg = config.normalize(require('./package'), {\n  extend: true,\n  fields: {\n    name: {\n      normalize: function() {\n        return 'bar'\n      }\n    }\n  }\n});\n\nconsole.log(pkg.name);\n//=\u003e 'bar'\n```\n\n### options.extend\n\n**Type**: `boolean`\n\n**Default**: `undefined`\n\nUsed with [options.field](#options-field), pass `true` if you want to extend a field that is already defined on the schema.\n\n```js\nvar pkg = config.normalize(require('./package'), {\n  extend: true,\n  fields: {\n    name: {\n      normalize: function() {\n        return 'bar'\n      }\n    }\n  }\n});\n\nconsole.log(pkg.name);\n//=\u003e 'bar'\n```\n\n## About\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eContributing\u003c/strong\u003e\u003c/summary\u003e\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eRunning Tests\u003c/strong\u003e\u003c/summary\u003e\n\nRunning and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:\n\n```sh\n$ npm install \u0026\u0026 npm test\n```\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cstrong\u003eBuilding docs\u003c/strong\u003e\u003c/summary\u003e\n\n_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_\n\nTo generate the readme, run the following command:\n\n```sh\n$ npm install -g verbose/verb#dev verb-generate-readme \u0026\u0026 verb\n```\n\n\u003c/details\u003e\n\n### Related projects\n\nYou might also be interested in these projects:\n\n[update](https://www.npmjs.com/package/update): Be scalable! Update is a new, open source developer framework and CLI for automating updates… [more](https://github.com/update/update) | [homepage](https://github.com/update/update \"Be scalable! Update is a new, open source developer framework and CLI for automating updates of any kind in code projects.\")\n\n### Contributors\n\n| **Commits** | **Contributor** |  \n| --- | --- |  \n| 154 | [jonschlinkert](https://github.com/jonschlinkert) |  \n| 16  | [doowb](https://github.com/doowb) |  \n| 2   | [pdehaan](https://github.com/pdehaan) |  \n\n### Author\n\n**Jon Schlinkert**\n\n* [GitHub Profile](https://github.com/jonschlinkert)\n* [Twitter Profile](https://twitter.com/jonschlinkert)\n* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)\n\n### License\n\nCopyright © 2020, [Jon Schlinkert](https://github.com/jonschlinkert).\nReleased under the [MIT License](LICENSE).\n\n***\n\n_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on March 01, 2020._","funding_links":["https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick\u0026hosted_button_id=W8YFZ425KND68"],"categories":["Modules","模块"],"sub_categories":["Module management","模块管理"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fnormalize-pkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fnormalize-pkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fnormalize-pkg/lists"}