Skip to content

Commit 9029554

Browse files
author
Ændrew Rininsland
committed
Merge pull request #207 from ctalau/no_underscore
Removed the underscore.js dependency
2 parents 3ab2732 + 0cc2474 commit 9029554

4 files changed

Lines changed: 14 additions & 23 deletions

File tree

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,17 +315,10 @@ issues.list(options, function(err, issues) {});
315315

316316
##Setup
317317

318-
Github.js has the following dependencies:
318+
Github.js has the following dependency:
319319

320-
- Underscore
321320
- btoa (included in modern browsers, an npm module is included in package.json for node)
322321

323-
Include these before github.js :
324-
325-
```
326-
<script src="lib/underscore-min.js">
327-
<script src="github.js">
328-
```
329322

330323
## Compatibility
331324

github.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
// Initial Setup
1717
// -------------
1818

19-
var XMLHttpRequest, _, btoa;
19+
var XMLHttpRequest, btoa;
2020
/* istanbul ignore else */
2121
if (typeof exports !== 'undefined') {
2222
XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
23-
_ = require('underscore');
2423
if (typeof btoa === 'undefined') {
2524
btoa = require('btoa'); //jshint ignore:line
2625
}
2726
} else {
28-
_ = window._;
2927
btoa = window.btoa;
3028
}
3129

@@ -50,9 +48,9 @@
5048
var url = path.indexOf('//') >= 0 ? path : API_URL + path;
5149
url += ((/\?/).test(url) ? '&' : '?');
5250
// Fix #195 about XMLHttpRequest.send method and GET/HEAD request
53-
if (_.isObject(data) && _.indexOf(['GET', 'HEAD'], method) > -1) {
54-
url += '&' + _.map(data, function (v, k) {
55-
return k + '=' + v;
51+
if (data && typeof data === "object" && ['GET', 'HEAD'].indexOf(method) > -1) {
52+
url += '&' + Object.keys(data).map(function (k) {
53+
return k + '=' + data[k];
5654
}).join('&');
5755
}
5856
return url + '&' + (new Date()).getTime();
@@ -107,7 +105,10 @@
107105
results.push.apply(results, res);
108106

109107
var links = (xhr.getResponseHeader('link') || '').split(/\s*,\s*/g),
110-
next = _.find(links, function(link) { return /rel="next"/.test(link); });
108+
next = null;
109+
links.forEach(function(link) {
110+
next = /rel="next"/.test(link) ? link : next;
111+
});
111112

112113
if (next) {
113114
next = (/<(.*)>/.exec(next) || [])[1];
@@ -364,7 +365,10 @@
364365
this.listBranches = function(cb) {
365366
_request("GET", repoPath + "/git/refs/heads", null, function(err, heads) {
366367
if (err) return cb(err);
367-
cb(null, _.map(heads, function(head) { return _.last(head.ref.split('/')); }));
368+
cb(null, heads.map(function(head) {
369+
var headParts = head.ref.split('/');
370+
return headParts[headParts.length - 1];
371+
}));
368372
});
369373
};
370374

@@ -651,7 +655,7 @@
651655
updateTree(branch, function(err, latestCommit) {
652656
that.getTree(latestCommit+"?recursive=true", function(err, tree) {
653657
// Update Tree
654-
_.each(tree, function(ref) {
658+
tree.forEach(function(ref) {
655659
if (ref.path === path) ref.path = newPath;
656660
if (ref.type === "tree") delete ref.sha;
657661
});

lib/underscore-min.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"dependencies": {
77
"atob": "^1.1.2",
88
"btoa": "^1.1.2",
9-
"underscore": "~1.8.3",
109
"xmlhttprequest": "~1.7.0"
1110
},
1211
"devDependencies": {

0 commit comments

Comments
 (0)