├── .gitignore ├── .travis.yml ├── History.md ├── License.md ├── Makefile ├── Readme.md ├── examples ├── custom_path.js └── module.js ├── lib └── package.js ├── package.json └── test ├── index.test.js ├── nested └── two │ └── nested.test.js ├── package.json └── support └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | node_modules 3 | *._ 4 | *.tmp 5 | .monitor 6 | *.diff 7 | *.err 8 | *.orig 9 | *.log 10 | *.rej 11 | *.swo 12 | *.swp 13 | *.vi 14 | *~ 15 | .DS_Store 16 | Thumbs.db 17 | .cache 18 | .project 19 | .settings 20 | .tmproj 21 | *.esproj 22 | nbproject 23 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 0.6 -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vesln/package/446c9a8b49ac532caa671103cc2cbaee7ca9c1b5/History.md -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (C) 2012 Veselin Todorov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = $(shell find test -iname \*.test.js) 2 | 3 | test: 4 | @NODE_ENV=test ./node_modules/.bin/mocha \ 5 | --require should \ 6 | --reporter spec \ 7 | $(TESTS) 8 | 9 | clean: 10 | rm -f examples/tmp/* 11 | 12 | .PHONY: test clean -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Project deprecated in favor of [read-package-json](https://github.com/isaacs/read-package-json) 2 | 3 | This project is not supported anymore. Please check the following alternatives: 4 | 5 | - read-package-json (https://github.com/isaacs/read-package-json) by Isaac Z. Schlueter 6 | - pkginfo (https://github.com/indexzero/node-pkginfo) by Charlie Robbins 7 | - require('path-to-package-json').version // etc 8 | -------------------------------------------------------------------------------- /examples/custom_path.js: -------------------------------------------------------------------------------- 1 | /** 2 | * package - Easy package.json exports. 3 | * 4 | * Author: Veselin Todorov 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | /** 9 | * Dependencies. 10 | */ 11 | 12 | var package = require('../')(__dirname + '/..'); // parent dir. 13 | 14 | console.log(package); // This will contain the package.json data. -------------------------------------------------------------------------------- /examples/module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * package - Easy package.json exports. 3 | * 4 | * Author: Veselin Todorov 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | /** 9 | * Dependencies. 10 | */ 11 | 12 | var package = require('../')(module); 13 | 14 | console.log(package); // This will contain the package.json data. -------------------------------------------------------------------------------- /lib/package.js: -------------------------------------------------------------------------------- 1 | /** 2 | * package - Easy package.json exports. 3 | * 4 | * Author: Veselin Todorov 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | /** 9 | * Dependencies. 10 | */ 11 | var fs = require('fs'); 12 | var path = require('path'); 13 | var exists = fs.existsSync || path.existsSync; 14 | 15 | /** 16 | * Package. 17 | * 18 | * @param {String|null} location 19 | * @returns {Object} package.json data 20 | */ 21 | var package = function(location) { 22 | if (location === Object(location)) { 23 | location = package.discover(location); 24 | } 25 | return package.read(path.normalize(location + '/package.json')); 26 | }; 27 | 28 | /** 29 | * Reads and parses a package.json file. 30 | * 31 | * @param {String} file 32 | * @returns {Object} package.json data 33 | */ 34 | package.read = function(file) { 35 | var data = fs.readFileSync(file, 'utf8'); 36 | return JSON.parse(data); 37 | }; 38 | 39 | /** 40 | * Makes an atempt to find package.json file. 41 | * 42 | * @returns {Object} package.json data 43 | */ 44 | package.discover = function(module) { 45 | var location = path.dirname(module.filename); 46 | var found = null; 47 | 48 | while (!found) { 49 | if (exists(location + '/package.json')) { 50 | found = location; 51 | } else if (location !== '/') { 52 | location = path.dirname(location); 53 | } else { 54 | throw new Error('package.json can not be located'); 55 | } 56 | } 57 | 58 | return found; 59 | }; 60 | 61 | /** 62 | * Exporting the lib. 63 | */ 64 | module.exports = package; 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "package" 3 | , "version": "1.0.1" 4 | , "description": "Easy package.json exports." 5 | , "keywords": ["package.json"] 6 | , "author": "Veselin Todorov " 7 | , "devDependencies": { 8 | "mocha": "0.3.3" 9 | , "should": "0.3.2" 10 | } 11 | , "repository" : { 12 | "type" : "git", 13 | "url" : "http://github.com/vesln/package.git" 14 | } 15 | , "homepage": "http://github.com/vesln/package" 16 | , "scripts": { 17 | "test": "make test" 18 | } 19 | , "main": "./lib/package" 20 | , "engines": { "node": ">= 0.6.0" } 21 | } 22 | -------------------------------------------------------------------------------- /test/index.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * package - Easy package.json exports. 3 | * 4 | * Author: Veselin Todorov 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | /** 9 | * Dependencies. 10 | */ 11 | var package = require('../'); 12 | 13 | describe('package', function() { 14 | describe('read', function() { 15 | it('should read and parse .json file', function() { 16 | var result = package.read(__dirname + '/support/package.json'); 17 | result.should.eql({ 18 | name: 'test-package-json-file', 19 | version: '0.0.1', 20 | private: true 21 | }); 22 | }); 23 | }); 24 | 25 | it('should read and parse given .json file', function() { 26 | var result = package(__dirname + '/support'); 27 | result.should.eql({ 28 | name: 'test-package-json-file', 29 | version: '0.0.1', 30 | private: true 31 | }); 32 | }); 33 | 34 | it('should autodiscover, read and parse package.json', function() { 35 | var result = package(module); 36 | result.should.eql({ 37 | name: 'test-package-json-file', 38 | version: '0.0.1', 39 | private: true 40 | }); 41 | }); 42 | }); -------------------------------------------------------------------------------- /test/nested/two/nested.test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * package - Easy package.json exports. 3 | * 4 | * Author: Veselin Todorov 5 | * Licensed under the MIT License. 6 | */ 7 | 8 | /** 9 | * Dependencies. 10 | */ 11 | var package = require('../../../'); 12 | 13 | describe('nested package json', function() { 14 | it('should autodiscover, read and parse package.json', function() { 15 | var result = package(module); 16 | result.should.eql({ 17 | name: 'test-package-json-file', 18 | version: '0.0.1', 19 | private: true 20 | }); 21 | }); 22 | }); -------------------------------------------------------------------------------- /test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-package-json-file" 3 | , "version": "0.0.1" 4 | , "private": true 5 | } -------------------------------------------------------------------------------- /test/support/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-package-json-file" 3 | , "version": "0.0.1" 4 | , "private": true 5 | } --------------------------------------------------------------------------------