New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

normalize-pkg

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

normalize-pkg

Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.

  • 0.2.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

normalize-pkg NPM version

Normalize values in package.json to improve compatibility, programmatic readability and usefulness with third party libs.

Install

Install with npm

$ npm i normalize-pkg --save

Install with bower

$ bower install normalize-pkg --save

Usage

var normalize = require('normalize-pkg');
var pkg = require('./package');
normalize(pkg);

Schema

normalize-pkg takes a schema, where each key on the schema represents a property name on package.json. A default schema is used but it can easily be overridden.

Keys

Schema property keys represent the properties you want on your package.json. For example, here is are a couple of properties from the default schema:

{
  name: {
    // ensure it's a string
    type: 'string',
    value: function (key, val, config) {
      // if you're initializing a new project, the `projectName`
      // function tries to intelligently guess that name
      return val || utils.projectName(process.cwd());
    }
  },
  // ensure it's a string, use the default if undefined
  description: {
    type: 'string',
    default: ''
  },
  // ensure it's a string, use the default if undefined
  version: {
    type: 'string',
    default: '0.1.0'
  }
}

Schema properties

The foll

  • type: native javascript type. If the property is defined and it's type does not match this value an error is thrown
  • value: This can be any type of value. If it's a function, it will be called and passed the key and value currently defined for the property, and the entire config as the last argument. If it's any other value, that value will be used and will overwrite any existing value. If you only want to use a value if it's undefined, use default instead or a value function if conditional logic is required.
  • default: Set the default value to use when the property is undefined. Only necessary if value is not defined.

Options

When an options object is passed as the second argument it will be used to extend or override properties on the existing schema.

normalize(pkg, {
  name: {
    value: 'foo' // always use 'foo' as the project name
  },
  version: {
    value: function(key, val) {
      // validate version with semver or something. 
      // be creative :) just remember to return the value!
      return value;
    }
  }
});

update: Update the year in all files in a project using glob patterns. | homepage

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Author

Jon Schlinkert

License

Copyright © 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on November 08, 2015.

Keywords

FAQs

Package last updated on 09 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc