GithubHelp home page GithubHelp logo

mathieumg / pkginfo-json5 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from indexzero/node-pkginfo

0.0 2.0 0.0 123 KB

An easy way to expose properties on a module from a package.json5 or package.json

Home Page: http://github.com/mathieumg/pkginfo-json5

License: MIT License

JavaScript 100.00%

pkginfo-json5's Introduction

node-pkginfo

An easy way to expose properties on a module from a package.json

Installation

Installing npm (node package manager)

  curl http://npmjs.org/install.sh | sh

Installing pkginfo

  [sudo] npm install pkginfo

Motivation

How often when writing node.js modules have you written the following line(s) of code?

  • Hard code your version string into your code
  exports.version = '0.1.0';
  • Programmatically expose the version from the package.json
  exports.version = JSON.parse(fs.readFileSync('/path/to/package.json', 'utf8')).version;

In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? WELL NOW YOU CAN!

Usage

Using pkginfo is idiot-proof, just require and invoke it.

  var pkginfo = require('pkginfo')(module);
  
  console.dir(module.exports);

By invoking the pkginfo module all of the properties in your package.json file will be automatically exposed on the callee module (i.e. the parent module of pkginfo).

Here's a sample of the output:

  { name: 'simple-app',
    description: 'A test fixture for pkginfo',
    version: '0.1.0',
    author: 'Charlie Robbins <[email protected]>',
    keywords: [ 'test', 'fixture' ],
    main: './index.js',
    scripts: { test: 'vows test/*-test.js --spec' },
    engines: { node: '>= 0.4.0' } }

Expose specific properties

If you don't want to expose all properties on from your package.json on your module then simple pass those properties to the pkginfo function:

  var pkginfo = require('pkginfo')(module, 'version', 'author');
  
  console.dir(module.exports);
  { version: '0.1.0',
    author: 'Charlie Robbins <[email protected]>' }

If you're looking for further usage see the examples included in this repository.

Run Tests

Tests are written in vows and give complete coverage of all APIs.

  vows test/*-test.js --spec

License: MIT

pkginfo-json5's People

Contributors

indexzero avatar mathieumg avatar kapouer avatar raoulmillais avatar trentm avatar

Watchers

James Cloos avatar  avatar

pkginfo-json5's Issues

Publish Npm

How do you feel about publishing this to npm. One of my project depends on this and I would prefer using npm rather than a github repo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.