[Pkg-javascript-commits] [node-array-find-index] 01/02: Imported Upstream version 1.0.1

Thorsten Alteholz alteholz at moszumanska.debian.org
Sun Apr 3 14:44:44 UTC 2016


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

alteholz pushed a commit to branch master
in repository node-array-find-index.

commit b21cb94171fb35159dee4346015aac3cf3d499a9
Author: Thorsten Alteholz <debian at alteholz.de>
Date:   Sun Apr 3 16:44:41 2016 +0200

    Imported Upstream version 1.0.1
---
 .editorconfig  | 15 +++++++++++++++
 .gitattributes |  1 +
 .gitignore     |  1 +
 .travis.yml    |  5 +++++
 index.js       | 25 +++++++++++++++++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 36 ++++++++++++++++++++++++++++++++++++
 readme.md      | 32 ++++++++++++++++++++++++++++++++
 test.js        | 11 +++++++++++
 9 files changed, 147 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..8f9d77e
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,15 @@
+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
+
+[*.md]
+trim_trailing_whitespace = false
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
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..2a2f1c6
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: node_js
+node_js:
+  - 'stable'
+  - '0.12'
+  - '0.10'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..e2dcd9a
--- /dev/null
+++ b/index.js
@@ -0,0 +1,25 @@
+'use strict';
+module.exports = function (arr, predicate, ctx) {
+	if (typeof Array.prototype.findIndex === 'function') {
+		return arr.findIndex(predicate, ctx);
+	}
+
+	if (typeof predicate !== 'function') {
+		throw new TypeError('predicate must be a function');
+	}
+
+	var list = Object(arr);
+	var len = list.length;
+
+	if (len === 0) {
+		return -1;
+	}
+
+	for (var i = 0; i < len; i++) {
+		if (predicate.call(ctx, list[i], i, list)) {
+			return i;
+		}
+	}
+
+	return -1;
+};
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..01dddd0
--- /dev/null
+++ b/package.json
@@ -0,0 +1,36 @@
+{
+  "name": "array-find-index",
+  "version": "1.0.1",
+  "description": "ES2015 `Array#findIndex()` ponyfill",
+  "license": "MIT",
+  "repository": "sindresorhus/array-find-index",
+  "author": {
+    "name": "Sindre Sorhus",
+    "email": "sindresorhus at gmail.com",
+    "url": "sindresorhus.com"
+  },
+  "engines": {
+    "node": ">=0.10.0"
+  },
+  "scripts": {
+    "test": "xo && ava"
+  },
+  "files": [
+    "index.js"
+  ],
+  "keywords": [
+    "es6",
+    "es2015",
+    "ponyfill",
+    "polyfill",
+    "shim",
+    "find",
+    "index",
+    "findindex",
+    "array"
+  ],
+  "devDependencies": {
+    "ava": "*",
+    "xo": "*"
+  }
+}
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..cf06dd3
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,32 @@
+# array-find-index [![Build Status](https://travis-ci.org/sindresorhus/array-find-index.svg?branch=master)](https://travis-ci.org/sindresorhus/array-find-index)
+
+> ES2015 [`Array#findIndex()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex) ponyfill
+
+> Ponyfill: A polyfill that doesn't overwrite the native method
+
+
+## Install
+
+```
+$ npm install --save array-find-index
+```
+
+
+## Usage
+
+```js
+arrayFindIndex = require('array-find-index');
+
+arrayFindIndex(['rainbow', 'unicorn', 'pony'], x => x === 'unicorn');
+//=> 1
+```
+
+
+## API
+
+Same as `Array#findIndex()`, but with the input array as the first argument.
+
+
+## License
+
+MIT © [Sindre Sorhus](http://sindresorhus.com)
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..7945cb1
--- /dev/null
+++ b/test.js
@@ -0,0 +1,11 @@
+/* eslint-disable no-extend-native */
+Array.prototype.findIndex = undefined;
+import test from 'ava';
+import fn from './';
+
+const f = [10, 20, 30, 40];
+
+test(t => {
+	t.is(fn(f, x => x === 30), 2);
+	t.is(fn(f, x => x === 'noop'), -1);
+});

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



More information about the Pkg-javascript-commits mailing list