[Pkg-javascript-commits] [node-array-map] 01/04: Import Upstream version 0.0.0
Shirish Togarla
shirish12-guest at moszumanska.debian.org
Tue Feb 7 17:51:02 UTC 2017
This is an automated email from the git hooks/post-receive script.
shirish12-guest pushed a commit to branch master
in repository node-array-map.
commit f709c327516eca3e6165c935a8d9b5e32d72e67f
Author: Shirish Togarla <shirishtogarla533 at gmail.com>
Date: Mon Feb 6 11:37:35 2017 +0000
Import Upstream version 0.0.0
---
.travis.yml | 4 +++
LICENSE | 18 ++++++++++++++
example/map.js | 5 ++++
index.js | 11 +++++++++
package.json | 46 ++++++++++++++++++++++++++++++++++
readme.markdown | 46 ++++++++++++++++++++++++++++++++++
test/map.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 207 insertions(+)
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..cc4dba2
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+ - "0.8"
+ - "0.10"
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ee27ba4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,18 @@
+This software is released under the MIT license:
+
+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/example/map.js b/example/map.js
new file mode 100644
index 0000000..64d9ead
--- /dev/null
+++ b/example/map.js
@@ -0,0 +1,5 @@
+var map = require('../');
+var letters = map([97,98,99], function (c) {
+ return String.fromCharCode(c);
+});
+console.log(letters.join(''));
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..d36c48d
--- /dev/null
+++ b/index.js
@@ -0,0 +1,11 @@
+module.exports = function (xs, f) {
+ if (xs.map) return xs.map(f);
+ var res = [];
+ for (var i = 0; i < xs.length; i++) {
+ var x = xs[i];
+ if (hasOwn.call(xs, i)) res.push(f(x, i, xs));
+ }
+ return res;
+};
+
+var hasOwn = Object.prototype.hasOwnProperty;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..178867e
--- /dev/null
+++ b/package.json
@@ -0,0 +1,46 @@
+{
+ "name": "array-map",
+ "version": "0.0.0",
+ "description": "`[].map(f)` for older browsers",
+ "main": "index.js",
+ "devDependencies": {
+ "tape": "~2.3.2"
+ },
+ "scripts": {
+ "test": "tape test/*.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/substack/array-map.git"
+ },
+ "homepage": "https://github.com/substack/array-map",
+ "keywords": [
+ "array",
+ "map",
+ "browser",
+ "es5",
+ "shim",
+ "ie6",
+ "ie7",
+ "ie8"
+ ],
+ "author": {
+ "name": "James Halliday",
+ "email": "mail at substack.net",
+ "url": "http://substack.net"
+ },
+ "license": "MIT",
+ "testling": {
+ "files": "test/*.js",
+ "browsers": [
+ "ie/6..latest",
+ "firefox/3.5","firefox/latest",
+ "chrome/5","chrome/latest",
+ "opera/12..latest", "opera/next",
+ "safari/5.1..latest",
+ "ipad/6.0..latest",
+ "iphone/6.0..latest",
+ "android-browser/4.2..latest"
+ ]
+ }
+}
diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..7612274
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,46 @@
+# array-map
+
+`[].map(f)` for older browsers
+
+[![testling badge](https://ci.testling.com/substack/array-map.png)](https://ci.testling.com/substack/array-map)
+
+[![build status](https://secure.travis-ci.org/substack/array-map.png)](http://travis-ci.org/substack/array-map)
+
+# example
+
+``` js
+var map = require('array-map');
+var letters = map([97,98,99], function (c) {
+ return String.fromCharCode(c);
+});
+console.log(letters.join(''));
+```
+
+output:
+
+```
+abc
+```
+
+# methods
+
+``` js
+var map = require('array-map')
+```
+
+## var ys = map(xs, f)
+
+Create a new array `ys` by applying `f(xs[i], i, xs)` to each element in `xs` at
+index `i`.
+
+# install
+
+With [npm](https://npmjs.org) do:
+
+```
+npm install array-map
+```
+
+# license
+
+MIT
diff --git a/test/map.js b/test/map.js
new file mode 100644
index 0000000..8f50228
--- /dev/null
+++ b/test/map.js
@@ -0,0 +1,77 @@
+var map = require('../');
+var test = require('tape');
+
+test('numbers -> letters', function (t) {
+ t.plan(2);
+ var a = map([97,98,99], function (c) {
+ return String.fromCharCode(c);
+ });
+ t.equal(a.join(''), 'abc');
+
+ var b = map(cripple([97,98,99]), function (c) {
+ return String.fromCharCode(c);
+ });
+ t.equal(b.join(''), 'abc');
+});
+
+test('elements and indexes', function (t) {
+ t.plan(8);
+ var x = { q: 5 }, y = 3, z = null;
+
+ t.deepEqual(
+ map([x,y,z], function (c, i) { return i }),
+ [ 0, 1, 2 ],
+ 'index check'
+ );
+ t.deepEqual(
+ map([x,y,z], function (c, i) { return i }),
+ [ 0, 1, 2 ],
+ 'crippled index check'
+ );
+
+ var xs0 = [ x, y, z ];
+ map(xs0, function (c, i, xs) {
+ t.strictEqual(xs, xs0, 'argument[2]');
+ });
+ var xs1 = [ x, y, z ];
+ map(xs1, function (c, i, xs) {
+ t.strictEqual(xs, xs1, 'crippled argument[2]');
+ });
+});
+
+test('ignore holes', function (t) {
+ t.plan(2);
+ t.deepEqual(
+ map(new Array(5), function (x) { return x }),
+ []
+ );
+ t.deepEqual(
+ map(cripple(new Array(5)), function (x) { return x }),
+ []
+ );
+});
+
+test('sparse map', function (t) {
+ t.plan(2);
+ var xs = new Array(5);
+ xs[2] = 'a';
+ xs[4] = 'b';
+ t.equal(
+ map(xs, function (x, i) { return x + i }).join(''),
+ 'a2b4'
+ );
+
+ var ys = new Array(5);
+ ys[2] = 'a';
+ ys[4] = 'b';
+ t.equal(
+ map(cripple(xs), function (x, i) { return x + i }).join(''),
+ 'a2b4'
+ );
+ t.end();
+});
+
+function cripple (xs) {
+ xs.map = undefined;
+ return xs;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-array-map.git
More information about the Pkg-javascript-commits
mailing list