Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 41e698e

Browse files
author
Eric Koleda
committed
Remove Underscore.js dependency.
1 parent d804872 commit 41e698e

File tree

7 files changed

+32
-36
lines changed

7 files changed

+32
-36
lines changed

gulpfile.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ gulp.task('dist', ['clean'], function() {
1515
.pipe(concat('OAuth1.gs'))
1616
.pipe(expose('this', 'OAuth1'))
1717
.pipe(gulp.dest('dist'));
18-
gulp.src('node_modules/underscore/underscore.js')
19-
.pipe(rename('Underscore.gs'))
20-
.pipe(gulp.dest('dist'));
2118
});
2219

2320
gulp.task('clean', function() {

package-lock.json

Lines changed: 6 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
"gulp-strip-line": "0.0.1",
2626
"jshint-stylish": "^2.0.1"
2727
},
28-
"dependencies": {
29-
"underscore": "^1.8.3"
30-
},
3128
"scripts": {
3229
"postversion": "gulp dist",
3330
"dist": "gulp dist",

src/MemoryProperties.gs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ MemoryProperties.prototype.getKeys = function() {
3232
* @see {@link https://developers.google.com/apps-script/reference/properties/properties#getproperties}
3333
*/
3434
MemoryProperties.prototype.getProperties = function() {
35-
return _.clone(this.properties);
35+
return extend_({}, this.properties);
3636
};
3737

3838
/**

src/OAuth1.gs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
* required setup.
1818
*/
1919

20-
// Load the Underscore.js library. This library was added using the script ID
21-
// "1I21uLOwDKdyF3_W_hvh6WXiIKWJWno8yG9lB8lf1VBnZFQ6jAAhyNTRG".
22-
var _ = Underscore.load();
23-
2420
/**
2521
* Creates a new OAuth1 service with the name specified. It's usually best to
2622
* create and configure your service once at the start of your script, and then

src/Service.gs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,14 +430,15 @@ Service_.prototype.fetchInternal_ = function(url, params, opt_token,
430430
}
431431
switch (this.paramLocation_) {
432432
case 'auth-header':
433-
params.headers = _.extend({}, params.headers,
434-
signer.toHeader(oauthParams));
433+
params.headers =
434+
extend_(params.headers || {}, signer.toHeader(oauthParams));
435435
break;
436436
case 'uri-query':
437437
url = buildUrl_(url, oauthParams);
438438
break;
439439
case 'post-body':
440-
params.payload = _.extend({}, params.payload, oauthParams);
440+
params.payload =
441+
extend_(params.payload || {}, oauthParams);
441442
break;
442443
default:
443444
throw 'Unknown param location: ' + this.paramLocation_;

src/Utilities.gs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,40 @@ function buildUrl_(url, params) {
3232

3333
/**
3434
* Validates that all of the values in the object are non-empty. If an empty
35-
* value is found, an error is thrown using the key as the name.
35+
* value is found, and error is thrown using the key as the name.
3636
* @param {Object.<string, string>} params The values to validate.
3737
* @private
3838
*/
3939
function validate_(params) {
4040
Object.keys(params).forEach(function(name) {
4141
var value = params[name];
42-
if (isEmpty_(value)) {
43-
throw Utilities.formatString('%s is required.', name);
42+
if (!value) {
43+
throw new Error(name + ' is required.');
4444
}
4545
});
4646
}
4747

4848
/**
49-
* Returns true if the given value is empty, false otherwise. An empty value
50-
* is one of null, undefined, a zero-length string, a zero-length array or an
51-
* object with no keys.
52-
* @param {?} value The value to test.
53-
* @returns {boolean} True if the value is empty, false otherwise.
49+
* Copy all of the properties in the source objects over to the
50+
* destination object, and return the destination object.
51+
* @param {Object} destination The combined object.
52+
* @param {Object} source The object who's properties are copied to the
53+
* destination.
54+
* @returns {Object} A combined object with the desination and source
55+
* properties.
5456
* @private
57+
* @see http://underscorejs.org/#extend
5558
*/
56-
function isEmpty_(value) {
57-
return value === null || value === undefined ||
58-
((_.isObject(value) || _.isString(value)) && _.isEmpty(value));
59+
function extend_(destination, source) {
60+
// Use Object.assign from the v8 engine, if available.
61+
if (Object.assign) {
62+
return Object.assign(destination, source);
63+
}
64+
var keys = Object.keys(source);
65+
for (var i = 0; i < keys.length; ++i) {
66+
destination[keys[i]] = source[keys[i]];
67+
}
68+
return destination;
5969
}
6070

6171
/**

0 commit comments

Comments
 (0)