{"id":15732493,"url":"https://github.com/jonschlinkert/expand-pkg","last_synced_at":"2025-05-13T05:00:20.106Z","repository":{"id":60775053,"uuid":"54955454","full_name":"jonschlinkert/expand-pkg","owner":"jonschlinkert","description":"Parse string values in package.json into objects.","archived":false,"fork":false,"pushed_at":"2020-04-01T00:06:55.000Z","size":76,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-13T05:00:02.836Z","etag":null,"topics":["expand","jonschlinkert","json","normalize","object","package","package-json","packagejson","parse","pkg","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":"2016-03-29T07:32:48.000Z","updated_at":"2021-04-12T22:18:17.000Z","dependencies_parsed_at":"2022-10-04T16:16:39.045Z","dependency_job_id":null,"html_url":"https://github.com/jonschlinkert/expand-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%2Fexpand-pkg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fexpand-pkg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fexpand-pkg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonschlinkert%2Fexpand-pkg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonschlinkert","download_url":"https://codeload.github.com/jonschlinkert/expand-pkg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253877509,"owners_count":21977643,"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":["expand","jonschlinkert","json","normalize","object","package","package-json","packagejson","parse","pkg","schema"],"created_at":"2024-10-04T00:20:32.705Z","updated_at":"2025-05-13T05:00:20.070Z","avatar_url":"https://github.com/jonschlinkert.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expand-pkg [![NPM version](https://img.shields.io/npm/v/expand-pkg.svg?style=flat)](https://www.npmjs.com/package/expand-pkg) [![NPM downloads](https://img.shields.io/npm/dm/expand-pkg.svg?style=flat)](https://npmjs.org/package/expand-pkg) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/expand-pkg.svg?style=flat\u0026label=Travis)](https://travis-ci.org/jonschlinkert/expand-pkg)\n\n\u003e Parse string values in package.json into objects.\n\nYou might also be interested in [normalize-pkg](https://github.com/jonschlinkert/normalize-pkg).\n\n## Install\n\nInstall with [npm](https://www.npmjs.com/):\n\n```sh\n$ npm install --save expand-pkg\n```\n\n## Usage\n\n```js\nvar Config = require('./');\nvar config = new Config();\nconsole.log(config.expand(require('./package')));\n```\n\n## Schema\n\nValues are parsed using a [schema](lib/schema.js) that is passed to [map-schema](https://github.com/jonschlinkert/map-schema) (builds on the schema from [normalize-pkg](https://github.com/jonschlinkert/normalize-pkg) as a starting point):\n\n* only properties that have a corresponding field on the schema will be parsed.\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 `.expand` is run and a property that is required or recommended by npm is missing, `expand-pkg` attempts to create the field if valid data can be found in the repository.\n\nThe following fields are the only built-in fields with default values:\n\n* `version`: `'0.1.0'`\n* `license`: `'MIT'`\n* `engines`: `{node: '\u003e= 0.10.0'}`\n\n## API\n\n### [Config](index.js#L24)\n\nCreate an instance of `Config` with the given `options`.\n\n**Example**\n\n```js\nvar config = new Config();\nvar pkg = config.expand({\n  author: 'Jon Schlinkert (https://github.com/jonschlinkert)'\n});\nconsole.log(pkg);\n//=\u003e {name: 'Jon Schlinkert', url: 'https://github.com/jonschlinkert'}\n```\n\n**Params**\n\n* `options` **{Object}**\n\n### [.field](index.js#L70)\n\nAdd a field to the schema, or overwrite or extend an existing field. The last argument is an `options` object that supports the following properties:\n\n* `normalize` **{Function}**: function to be called on the given package.json value when the `.expand` 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**Example**\n\n```js\nvar config = new Config();\n\nconfig.field('foo', 'string', {\n  default: 'bar'\n});\n\nvar pkg = config.expand({});\nconsole.log(pkg);\n//=\u003e {foo:  'bar'}\n```\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### [.expand](index.js#L96)\n\nIterate over `pkg` properties and expand values that have corresponding [fields](#field) registered on the schema.\n\n**Example**\n\n```js\nvar config = new Config();\nvar pkg = config.expand(require('./package.json'));\n```\n\n**Params**\n\n* `pkg` **{Object}**: The `package.json` object to expand\n* `options` **{Object}**\n* `returns` **{Object}**: Returns an expanded package.json object.\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('expand-pkg');\nvar config = new Config({knownOnly: true});\n\nconsole.log(config.expand({author: 'Brian Woodward', foo: 'bar'}));\n//=\u003e {author: {name: 'Brian Woodward'}}\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.expand(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.expand(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### Related projects\n\n* [normalize-pkg](https://www.npmjs.com/package/normalize-pkg): Normalize values in package.json using the map-schema library. | [homepage](https://github.com/jonschlinkert/normalize-pkg \"Normalize values in package.json using the map-schema library.\")\n* [repo-utils](https://www.npmjs.com/package/repo-utils): Utils for normalizing and formatting repo data. | [homepage](https://github.com/jonschlinkert/repo-utils \"Utils for normalizing and formatting repo data.\")\n* [sync-pkg](https://www.npmjs.com/package/sync-pkg): CLI to sync only basic properties from package.json to bower.json. | [homepage](https://github.com/jonschlinkert/sync-pkg \"CLI to sync only basic properties from package.json to bower.json.\")\n\n### Contributing\n\nPull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).\n\n### Contributors\n\n| **Commits** | **Contributor** | \n| --- | --- |\n| 27 | [jonschlinkert](https://github.com/jonschlinkert) |\n| 4 | [doowb](https://github.com/doowb) |\n\n### Building docs\n\n_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_\n\nTo generate the readme and API documentation with [verb](https://github.com/verbose/verb):\n\n```sh\n$ npm install -g verb verb-generate-readme \u0026\u0026 verb\n```\n\n### Running tests\n\nInstall dev dependencies:\n\n```sh\n$ npm install -d \u0026\u0026 npm test\n```\n\n### Author\n\n**Jon Schlinkert**\n\n* [github/jonschlinkert](https://github.com/jonschlinkert)\n* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)\n\n### License\n\nCopyright © 2016, [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.2.0, on December 02, 2016._","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fexpand-pkg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonschlinkert%2Fexpand-pkg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonschlinkert%2Fexpand-pkg/lists"}