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

Commit 49754de

Browse files
author
Eric Koleda
authored
Merge pull request #49 from gsuitedevs/underscore
Remove Underscore.js dependency
2 parents d804872 + 5357dd6 commit 49754de

File tree

7 files changed

+45
-37
lines changed

7 files changed

+45
-37
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+
assign_({}, 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+
// Clone the payload.
441+
params.payload = assign_({}, params.payload, oauthParams);
441442
break;
442443
default:
443444
throw 'Unknown param location: ' + this.paramLocation_;

src/Utilities.gs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,52 @@ 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.
54-
* @private
49+
* Polyfill for Object.assign, which isn't available on the legacy runtime.
50+
* Not assigning to Object to avoid overwriting behavior in the parent
51+
* script(s).
52+
* @param {Object} target The target object to apply the sources’ properties to,
53+
* which is returned after it is modified.
54+
* @param {...Object} sources The source object(s) containing the properties you
55+
* want to apply.
56+
* @returns {Object} The target object.
57+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill}
58+
* @license Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
5559
*/
56-
function isEmpty_(value) {
57-
return value === null || value === undefined ||
58-
((_.isObject(value) || _.isString(value)) && _.isEmpty(value));
60+
function assign_(target, varArgs) {
61+
if (typeof Object.assign === 'function') {
62+
return Object.assign.apply(null, arguments);
63+
}
64+
if (target === null || target === undefined) {
65+
throw new TypeError('Cannot convert undefined or null to object');
66+
}
67+
var to = Object(target);
68+
for (var index = 1; index < arguments.length; index++) {
69+
var nextSource = arguments[index];
70+
71+
if (nextSource !== null && nextSource !== undefined) {
72+
for (var nextKey in nextSource) {
73+
// Avoid bugs when hasOwnProperty is shadowed
74+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
75+
to[nextKey] = nextSource[nextKey];
76+
}
77+
}
78+
}
79+
}
80+
return to;
5981
}
6082

6183
/**

0 commit comments

Comments
 (0)