[Pkg-javascript-commits] [node-locate-path] 01/03: Import Upstream version 2.0.0
Paolo Greppi
paolog-guest at moszumanska.debian.org
Wed Dec 6 09:07:31 UTC 2017
This is an automated email from the git hooks/post-receive script.
paolog-guest pushed a commit to branch master
in repository node-locate-path.
commit e9f8074052e826f308cc10a59bf4f08787d14ea7
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date: Wed Dec 6 09:15:29 2017 +0100
Import Upstream version 2.0.0
---
.editorconfig | 12 +++++++
.gitattributes | 2 ++
.gitignore | 1 +
.travis.yml | 4 +++
fixture/unicorn | 0
index.js | 24 ++++++++++++++
license | 21 ++++++++++++
package.json | 47 +++++++++++++++++++++++++++
readme.md | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
test.js | 21 ++++++++++++
10 files changed, 231 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/fixture/unicorn b/fixture/unicorn
new file mode 100644
index 0000000..e69de29
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..32b108d
--- /dev/null
+++ b/index.js
@@ -0,0 +1,24 @@
+'use strict';
+const path = require('path');
+const pathExists = require('path-exists');
+const pLocate = require('p-locate');
+
+module.exports = (iterable, opts) => {
+ opts = Object.assign({
+ cwd: process.cwd()
+ }, opts);
+
+ return pLocate(iterable, el => pathExists(path.resolve(opts.cwd, el)), opts);
+};
+
+module.exports.sync = (iterable, opts) => {
+ opts = Object.assign({
+ cwd: process.cwd()
+ }, opts);
+
+ for (const el of iterable) {
+ if (pathExists.sync(path.resolve(opts.cwd, el))) {
+ return el;
+ }
+ }
+};
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..17bcd7f
--- /dev/null
+++ b/package.json
@@ -0,0 +1,47 @@
+{
+ "name": "locate-path",
+ "version": "2.0.0",
+ "description": "Get the first path that exists on disk of multiple paths",
+ "license": "MIT",
+ "repository": "sindresorhus/locate-path",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus at gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "locate",
+ "path",
+ "paths",
+ "file",
+ "files",
+ "exists",
+ "find",
+ "finder",
+ "search",
+ "searcher",
+ "array",
+ "iterable",
+ "iterator"
+ ],
+ "dependencies": {
+ "p-locate": "^2.0.0",
+ "path-exists": "^3.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..f7b337b
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,99 @@
+# locate-path [![Build Status](https://travis-ci.org/sindresorhus/locate-path.svg?branch=master)](https://travis-ci.org/sindresorhus/locate-path)
+
+> Get the first path that exists on disk of multiple paths
+
+
+## Install
+
+```
+$ npm install --save locate-path
+```
+
+
+## Usage
+
+Here we find the first file that exists on disk, in array order.
+
+```js
+const locatePath = require('locate-path');
+
+const files = [
+ 'unicorn.png',
+ 'rainbow.png', // only this one actually exists on disk
+ 'pony.png'
+];
+
+locatePath(files).then(foundPath => {
+ console.log(foundPath);
+ //=> 'rainbow'
+});
+```
+
+
+## API
+
+### locatePath(input, [options])
+
+Returns a `Promise` for the first path that exists or `undefined` if none exists.
+
+#### input
+
+Type: `Iterable<string>`
+
+Paths to check.
+
+#### options
+
+Type: `Object`
+
+##### concurrency
+
+Type: `number`<br>
+Default: `Infinity`<br>
+Minimum: `1`
+
+Number of concurrently pending promises.
+
+##### preserveOrder
+
+Type: `boolean`<br>
+Default: `true`
+
+Preserve `input` order when searching.
+
+Disable this to improve performance if you don't care about the order.
+
+##### cwd
+
+Type: `string`<br>
+Default: `process.cwd()`
+
+Current working directory.
+
+### locatePath.sync(input, [options])
+
+Returns the first path that exists or `undefined` if none exists.
+
+#### input
+
+Type: `Iterable<string>`
+
+Paths to check.
+
+#### options
+
+Type: `Object`
+
+##### cwd
+
+Same as above.
+
+
+## Related
+
+- [path-exists](https://github.com/sindresorhus/path-exists) - Check if a path exists
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..bd9d3d4
--- /dev/null
+++ b/test.js
@@ -0,0 +1,21 @@
+import test from 'ava';
+import m from './';
+
+const input = [
+ 'noop.foo',
+ 'unicorn.png',
+ 'index.js',
+ 'test.js'
+];
+
+test('async', async t => {
+ t.is(await m(input), 'index.js');
+ t.is(await m(['nonexistant']), undefined);
+ t.is(await m(['noop', 'unicorn'], {cwd: 'fixture'}), 'unicorn');
+});
+
+test('sync', t => {
+ t.is(m.sync(input), 'index.js');
+ t.is(m.sync(['nonexistant']), undefined);
+ t.is(m.sync(['noop', 'unicorn'], {cwd: 'fixture'}), 'unicorn');
+});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-locate-path.git
More information about the Pkg-javascript-commits
mailing list