[Pkg-javascript-commits] [node-read-pkg] 01/03: Import Upstream version 2.0.0

Sruthi Chandran srud-guest at moszumanska.debian.org
Wed Nov 2 05:57:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

srud-guest pushed a commit to branch master
in repository node-read-pkg.

commit 879a01b976a120f7a8896984f1cd7428a68bff97
Author: Sruthi <srud at disroot.org>
Date:   Tue Nov 1 19:56:47 2016 +0530

    Import Upstream version 2.0.0
---
 .editorconfig  | 12 +++++++++
 .gitattributes |  2 ++
 .gitignore     |  1 +
 .travis.yml    |  4 +++
 index.js       | 47 ++++++++++++++++++++++++++++++++++
 license        | 21 ++++++++++++++++
 package.json   | 45 +++++++++++++++++++++++++++++++++
 readme.md      | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/pkg.json  |  4 +++
 test/test.js   | 49 ++++++++++++++++++++++++++++++++++++
 10 files changed, 264 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..391f0a4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..97519af
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - '6'
+  - '4'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..dff948b
--- /dev/null
+++ b/index.js
@@ -0,0 +1,47 @@
+'use strict';
+const path = require('path');
+const loadJsonFile = require('load-json-file');
+const pathType = require('path-type');
+
+module.exports = (fp, opts) => {
+	if (typeof fp !== 'string') {
+		opts = fp;
+		fp = '.';
+	}
+
+	opts = opts || {};
+
+	return pathType.dir(fp)
+		.then(isDir => {
+			if (isDir) {
+				fp = path.join(fp, 'package.json');
+			}
+
+			return loadJsonFile(fp);
+		})
+		.then(x => {
+			if (opts.normalize !== false) {
+				require('normalize-package-data')(x);
+			}
+
+			return x;
+		});
+};
+
+module.exports.sync = (fp, opts) => {
+	if (typeof fp !== 'string') {
+		opts = fp;
+		fp = '.';
+	}
+
+	opts = opts || {};
+	fp = pathType.dirSync(fp) ? path.join(fp, 'package.json') : fp;
+
+	const x = loadJsonFile.sync(fp);
+
+	if (opts.normalize !== false) {
+		require('normalize-package-data')(x);
+	}
+
+	return x;
+};
diff --git a/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
+
+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.
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..b232219
--- /dev/null
+++ b/package.json
@@ -0,0 +1,45 @@
+{
+  "name": "read-pkg",
+  "version": "2.0.0",
+  "description": "Read a package.json file",
+  "license": "MIT",
+  "repository": "sindresorhus/read-pkg",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=4"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "json",
+    "read",
+    "parse",
+    "file",
+    "fs",
+    "graceful",
+    "load",
+    "pkg",
+    "package",
+    "normalize"
+  ],
+  "dependencies": {
+    "load-json-file": "^2.0.0",
+    "normalize-package-data": "^2.3.2",
+    "path-type": "^2.0.0"
+  },
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  },
+  "xo": {
+    "esnext": true
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..5796008
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,79 @@
+# read-pkg [![Build Status](https://travis-ci.org/sindresorhus/read-pkg.svg?branch=master)](https://travis-ci.org/sindresorhus/read-pkg)
+
+> Read a package.json file
+
+
+## Why
+
+- [Gracefully handles filesystem issues](https://github.com/isaacs/node-graceful-fs)
+- [Strips UTF-8 BOM](https://github.com/sindresorhus/strip-bom)
+- [Throws more helpful JSON errors](https://github.com/sindresorhus/parse-json)
+- [Normalizes the data](https://github.com/npm/normalize-package-data#what-normalization-currently-entails)
+
+
+## Install
+
+```
+$ npm install --save read-pkg
+```
+
+
+## Usage
+
+```js
+const readPkg = require('read-pkg');
+
+readPkg().then(pkg => {
+	console.log(pkg);
+	//=> {name: 'read-pkg', ...}
+});
+
+readPkg(__dirname).then(pkg => {
+	console.log(pkg);
+	//=> {name: 'read-pkg', ...}
+});
+
+readPkg(path.join('unicorn', 'package.json')).then(pkg => {
+	console.log(pkg);
+	//=> {name: 'read-pkg', ...}
+});
+```
+
+
+## API
+
+### readPkg([path], [options])
+
+Returns a `Promise` for the parsed JSON.
+
+### readPkg.sync([path], [options])
+
+Returns the parsed JSON.
+
+#### path
+
+Type: `string`<br>
+Default: `.`
+
+Path to a `package.json` file or its directory.
+
+#### options
+
+##### normalize
+
+Type: `boolean`<br>
+Default: `true`
+
+[Normalize](https://github.com/npm/normalize-package-data#what-normalization-currently-entails) the package data.
+
+
+## Related
+
+- [read-pkg-up](https://github.com/sindresorhus/read-pkg-up) - Read the closest package.json file
+- [write-pkg](https://github.com/sindresorhus/write-pkg) - Write a `package.json` file
+- [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test/pkg.json b/test/pkg.json
new file mode 100644
index 0000000..d580b22
--- /dev/null
+++ b/test/pkg.json
@@ -0,0 +1,4 @@
+{
+	"name": "unicorn",
+	"version": "1.0.0"
+}
diff --git a/test/test.js b/test/test.js
new file mode 100644
index 0000000..40869e8
--- /dev/null
+++ b/test/test.js
@@ -0,0 +1,49 @@
+'use strict';
+import path from 'path';
+import test from 'ava';
+import m from '../';
+
+const pkg = path.join(__dirname, '..');
+const otherName = path.join(__dirname, 'pkg.json');
+
+test('async', async t => {
+	const x = await m(otherName);
+	t.is(x.name, 'unicorn');
+	t.truthy(x._id);
+});
+
+test('async - directory', async t => {
+	const x = await m(pkg);
+	t.is(x.name, 'read-pkg');
+	t.truthy(x._id);
+});
+
+test.serial('async - default filepath', async t => {
+	process.chdir('..');
+
+	const x = await m();
+	t.is(x.name, 'read-pkg');
+
+	process.chdir('test');
+});
+
+test('sync', t => {
+	const x = m.sync(otherName);
+	t.is(x.name, 'unicorn');
+	t.truthy(x._id);
+});
+
+test('sync - directory', t => {
+	const x = m.sync(pkg);
+	t.is(x.name, 'read-pkg');
+	t.truthy(x._id);
+});
+
+test.serial('sync - default filepath', t => {
+	process.chdir('..');
+
+	const x = m.sync();
+	t.is(x.name, 'read-pkg');
+
+	process.chdir('test');
+});

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-read-pkg.git



More information about the Pkg-javascript-commits mailing list