array-map
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -0,5 +1,7 @@ | ||
'use strict'; | ||
var map = require('../'); | ||
var letters = map([97,98,99], function (c) { | ||
return String.fromCharCode(c); | ||
var letters = map([97, 98, 99], function (c) { | ||
return String.fromCharCode(c); | ||
}); | ||
console.log(letters.join('')); |
24
index.js
@@ -0,11 +1,17 @@ | ||
'use strict'; | ||
var hasOwn = Object.prototype.hasOwnProperty; | ||
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; | ||
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; |
123
package.json
{ | ||
"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@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" | ||
] | ||
} | ||
"name": "array-map", | ||
"version": "0.0.1", | ||
"description": "`[].map(f)` for older browsers", | ||
"main": "index.js", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^21.0.0", | ||
"aud": "^2.0.1", | ||
"auto-changelog": "^2.4.0", | ||
"eslint": "=8.8.0", | ||
"in-publish": "^2.0.1", | ||
"npmignore": "^0.3.0", | ||
"safe-publish-latest": "^2.0.0", | ||
"tape": "^5.6.1" | ||
}, | ||
"scripts": { | ||
"prepack": "npmignore --auto --commentLines=autogenerated", | ||
"prepublish": "not-in-publish || npm run prepublishOnly", | ||
"prepublishOnly": "safe-publish-latest", | ||
"lint": "eslint --ext=js,mjs .", | ||
"pretest": "npm run lint", | ||
"tests-only": "tape 'test/**/*.js'", | ||
"test": "npm run tests-only", | ||
"posttest": "aud --production", | ||
"version": "auto-changelog && git add CHANGELOG.md", | ||
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/ljharb/array-map.git" | ||
}, | ||
"homepage": "https://github.com/ljharb/array-map", | ||
"keywords": [ | ||
"array", | ||
"map", | ||
"browser", | ||
"es5", | ||
"shim", | ||
"ie6", | ||
"ie7", | ||
"ie8" | ||
], | ||
"author": { | ||
"name": "James Halliday", | ||
"email": "mail@substack.net", | ||
"url": "http://substack.net" | ||
}, | ||
"funding": { | ||
"url": "https://github.com/sponsors/ljharb" | ||
}, | ||
"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" | ||
] | ||
}, | ||
"auto-changelog": { | ||
"output": "CHANGELOG.md", | ||
"template": "keepachangelog", | ||
"unreleased": false, | ||
"commitLimit": false, | ||
"backfillLimit": false, | ||
"hideCredit": true | ||
}, | ||
"publishConfig": { | ||
"ignore": [ | ||
".github/workflows" | ||
] | ||
} | ||
} |
126
test/map.js
@@ -0,77 +1,77 @@ | ||
'use strict'; | ||
var map = require('../'); | ||
var test = require('tape'); | ||
function cripple(xs) { | ||
xs.map = undefined; // eslint-disable-line no-param-reassign | ||
return xs; | ||
} | ||
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'); | ||
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]'); | ||
}); | ||
t.plan(8); | ||
var x = { q: 5 }; | ||
var y = 3; | ||
var 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 }), | ||
[] | ||
); | ||
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(); | ||
t.plan(2); | ||
var xs = [,, 'a',, 'b']; // eslint-disable-line no-sparse-arrays | ||
t.equal( | ||
map(xs, function (x, i) { return x + i; }).join(''), | ||
'a2b4' | ||
); | ||
var ys = [,, 'a',, 'b']; // eslint-disable-line no-sparse-arrays | ||
t.equal( | ||
map(cripple(ys), function (x, i) { return x + i; }).join(''), | ||
'a2b4' | ||
); | ||
t.end(); | ||
}); | ||
function cripple (xs) { | ||
xs.map = undefined; | ||
return xs; | ||
} |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
10716
9
88
0
1
66
8
1