package/.npmignore000644 000765 000024 0000000241 11744321424012525 0ustar00000000 000000 tmp node_modules *._ *.tmp .monitor *.diff *.err *.orig *.log *.rej *.swo *.swp *.vi *~ .DS_Store Thumbs.db .cache .project .settings .tmproj *.esproj nbproject package/.travis.yml000644 000765 000024 0000000042 11744321424012636 0ustar00000000 000000 language: node_js node_js: - 0.6package/examples/000755 000765 000024 0000000000 11744322165012352 5ustar00000000 000000 package/examples/custom_path.js000644 000765 000024 0000000436 11744321424015236 0ustar00000000 000000 /** * package - Easy package.json exports. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var package = require('../')(__dirname + '/..'); // parent dir. console.log(package); // This will contain the package.json data.package/examples/module.js000644 000765 000024 0000000404 11744321424014170 0ustar00000000 000000 /** * package - Easy package.json exports. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var package = require('../')(module); console.log(package); // This will contain the package.json data.package/History.md000644 000765 000024 0000000000 11744322063012502 0ustar00000000 000000 package/lib/000755 000765 000024 0000000000 11744322165011302 5ustar00000000 000000 package/lib/package.js000644 000765 000024 0000002421 11744321775013240 0ustar00000000 000000 /** * package - Easy package.json exports. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var fs = require('fs'); var path = require('path'); var exists = fs.existsSync || path.existsSync; /** * Package. * * @param {String|null} location * @returns {Object} package.json data */ var package = function(location) { if (location === Object(location)) { location = package.discover(location); } return package.read(path.normalize(location + '/package.json')); }; /** * Reads and parses a package.json file. * * @param {String} file * @returns {Object} package.json data */ package.read = function(file) { var data = fs.readFileSync(file, 'utf8'); return JSON.parse(data); }; /** * Makes an atempt to find package.json file. * * @returns {Object} package.json data */ package.discover = function(module) { var location = path.dirname(module.filename); var found = null; while (!found) { if (exists(location + '/package.json')) { found = location; } else if (location !== '/') { location = path.dirname(location); } else { throw new Error('package.json can not be located'); } } return found; }; /** * Exporting the lib. */ module.exports = package; package/Makefile000644 000765 000024 0000000302 11744321424012164 0ustar00000000 000000 TESTS = $(shell find test -iname \*.test.js) test: @NODE_ENV=test ./node_modules/.bin/mocha \ --require should \ --reporter spec \ $(TESTS) clean: rm -f examples/tmp/* .PHONY: test cleanpackage/package.json000644 000765 000024 0000001003 11744322116013010 0ustar00000000 000000 { "name": "package" , "version": "1.0.1" , "description": "Easy package.json exports." , "keywords": ["package.json"] , "author": "Veselin Todorov " , "devDependencies": { "mocha": "0.3.3" , "should": "0.3.2" } , "repository" : { "type" : "git", "url" : "http://github.com/vesln/package.git" } , "homepage": "http://github.com/vesln/package" , "scripts": { "test": "make test" } , "main": "./lib/package" , "engines": { "node": ">= 0.6.0" } } package/Readme.md000644 000765 000024 0000003260 11744321424012251 0ustar00000000 000000 [![Build Status](https://secure.travis-ci.org/vesln/package.png)](http://travis-ci.org/vesln/package) # package - Easy package.json exports. ## Intro This module provides an easy and simple way to export package.json data. ## Installation $ npm install package ## Usage var package = require('package')(module); // contains package.json data. var yourAwesomeModule = {}; yourAwesomeModule.version = package.version; ## Tests $ make test ## Contribution Bug fixes and features are welcomed. ## Other similar modules - pkginfo (https://github.com/indexzero/node-pkginfo) by indexzero. - JSON.parse + fs.readFile ## License MIT License Copyright (C) 2012 Veselin Todorov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.package/test/000755 000765 000024 0000000000 11744322165011513 5ustar00000000 000000 package/test/index.test.js000644 000765 000024 0000001726 11744321424014141 0ustar00000000 000000 /** * package - Easy package.json exports. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var package = require('../'); describe('package', function() { describe('read', function() { it('should read and parse .json file', function() { var result = package.read(__dirname + '/support/package.json'); result.should.eql({ name: 'test-package-json-file', version: '0.0.1', private: true }); }); }); it('should read and parse given .json file', function() { var result = package(__dirname + '/support'); result.should.eql({ name: 'test-package-json-file', version: '0.0.1', private: true }); }); it('should autodiscover, read and parse package.json', function() { var result = package(module); result.should.eql({ name: 'test-package-json-file', version: '0.0.1', private: true }); }); });package/test/nested/000755 000765 000024 0000000000 11744322165012775 5ustar00000000 000000 package/test/nested/two/000755 000765 000024 0000000000 11744322165013606 5ustar00000000 000000 package/test/nested/two/nested.test.js000644 000765 000024 0000000723 11744321424016403 0ustar00000000 000000 /** * package - Easy package.json exports. * * Author: Veselin Todorov * Licensed under the MIT License. */ /** * Dependencies. */ var package = require('../../../'); describe('nested package json', function() { it('should autodiscover, read and parse package.json', function() { var result = package(module); result.should.eql({ name: 'test-package-json-file', version: '0.0.1', private: true }); }); });package/test/package.json000644 000765 000024 0000000123 11744321424013772 0ustar00000000 000000 { "name": "test-package-json-file" , "version": "0.0.1" , "private": true }package/test/support/000755 000765 000024 0000000000 11744322165013227 5ustar00000000 000000 package/test/support/package.json000644 000765 000024 0000000123 11744321424015506 0ustar00000000 000000 { "name": "test-package-json-file" , "version": "0.0.1" , "private": true }