Skip to content

Commit

Permalink
remove __guard__ functions added by decaffeinate
Browse files Browse the repository at this point in the history
  • Loading branch information
philschatz committed Dec 9, 2016
1 parent ff15a45 commit 6f49a95
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 76 deletions.
59 changes: 20 additions & 39 deletions dist/octokat.js
Expand Up @@ -132,6 +132,17 @@ return /******/ (function(modules) { // webpackBootstrap
var Requester = __webpack_require__(15);
var applyHypermedia = __webpack_require__(17);

// Checks if a response is a Buffer or not
var isBuffer = function isBuffer(data) {
if (typeof global !== 'undefined') {
return global['Buffer'].isBuffer(data);
} else {
// If `global` is not defined then we are not running inside Node so
// the object could never be a Buffer.
return false;
}
};

var uncamelizeObj = function uncamelizeObj(obj) {
if (Array.isArray(obj)) {
return obj.map(function (i) {
Expand Down Expand Up @@ -176,11 +187,7 @@ return /******/ (function(modules) { // webpackBootstrap
// Use a slightly convoluted syntax so browserify does not include the
// NodeJS Buffer in the browser version.
// data is a Buffer when uploading a release asset file
if (data && !__guard__(__guard__(global, function (x1) {
return x1['Buffer'];
}), function (x) {
return x.isBuffer(data);
})) {
if (data && !isBuffer(data)) {
data = uncamelizeObj(data);
}

Expand Down Expand Up @@ -242,9 +249,9 @@ return /******/ (function(modules) { // webpackBootstrap
}
var data = context.data;

context.url = __guard__(data, function (x) {
return x.url;
}) || path;
if (data) {
context.url = data.url || path;
}

var responseMiddlewareAsyncs = plus.map(plus.filter(plugins, function (_ref2) {
var responseMiddlewareAsync = _ref2.responseMiddlewareAsync;
Expand Down Expand Up @@ -321,10 +328,6 @@ return /******/ (function(modules) { // webpackBootstrap
};

module.exports = OctokatBase;

function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
}
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ },
Expand Down Expand Up @@ -1722,11 +1725,9 @@ return /******/ (function(modules) { // webpackBootstrap

if (typeof window !== 'undefined' && window !== null && !newPromise) {
// Otherwise, show a warning (library can still be used with just callbacks)
__guardFunc__(__guard__(console, function (x) {
return x.warn;
}), function (f) {
return f('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise');
});
if (window.console && window.console.warn) {
window.console.warn('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise');
}
} else if ((typeof window === 'undefined' || window === null) && !newPromise) {
// Running in NodeJS
throw new Error('Could not find a promise lib for node. Seems like a bug');
Expand All @@ -1737,13 +1738,6 @@ return /******/ (function(modules) { // webpackBootstrap
promiseCreator: { newPromise: newPromise, allPromises: allPromises }
};

function __guardFunc__(func, transform) {
return typeof func === 'function' ? transform(func) : undefined;
}
function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
}

/***/ },
/* 22 */
/***/ function(module, exports) {
Expand Down Expand Up @@ -1805,9 +1799,7 @@ return /******/ (function(modules) { // webpackBootstrap
return $q.all(promises);
};
});
} else if (__guard__(window.jQuery, function (x) {
return x.Deferred;
})) {
} else if (window.jQuery && window.jQuery.Deferred) {
var newPromise = function newPromise(fn) {
var promise = window.jQuery.Deferred();
var resolve = function resolve(val) {
Expand Down Expand Up @@ -1841,11 +1833,6 @@ return /******/ (function(modules) { // webpackBootstrap
exports.newPromise = newPromise;
exports.allPromises = allPromises;


function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
}

/***/ },
/* 23 */
/***/ function(module, exports, __webpack_require__) {
Expand Down Expand Up @@ -1972,9 +1959,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (typeof window !== 'undefined' && window !== null) {
var base64encode = window.btoa;
// Use the `Buffer` if available (NodeJS)
} else if (__guard__(global, function (x) {
return x['Buffer'];
})) {
} else if (typeof global !== 'undefined' && global['Buffer']) {
var base64encode = function base64encode(str) {
var buffer = new global['Buffer'](str, 'binary');
return buffer.toString('base64');
Expand All @@ -1984,10 +1969,6 @@ return /******/ (function(modules) { // webpackBootstrap
}

module.exports = base64encode;

function __guard__(value, transform) {
return typeof value !== 'undefined' && value !== null ? transform(value) : undefined;
}
/* WEBPACK VAR INJECTION */}.call(exports, (function() { return this; }())))

/***/ },
Expand Down
21 changes: 15 additions & 6 deletions src/base.js
Expand Up @@ -11,6 +11,17 @@ const NativePromiseOnlyPlugin = require('./plugins/promise/native-only')
const Requester = require('./requester')
const applyHypermedia = require('./helpers/hypermedia')

// Checks if a response is a Buffer or not
const isBuffer = (data) => {
if (typeof global !== 'undefined') {
return global['Buffer'].isBuffer(data)
} else {
// If `global` is not defined then we are not running inside Node so
// the object could never be a Buffer.
return false
}
}

let uncamelizeObj = function (obj) {
if (Array.isArray(obj)) {
return (obj.map((i) => uncamelizeObj(i)))
Expand Down Expand Up @@ -45,7 +56,7 @@ let OctokatBase = function (clientOptions = {}) {
// Use a slightly convoluted syntax so browserify does not include the
// NodeJS Buffer in the browser version.
// data is a Buffer when uploading a release asset file
if (data && !__guard__(__guard__(global, x1 => x1['Buffer']), x => x.isBuffer(data))) {
if (data && !isBuffer(data)) {
data = uncamelizeObj(data)
}

Expand Down Expand Up @@ -96,7 +107,9 @@ let OctokatBase = function (clientOptions = {}) {
instance._parseWithContext = function (path, context, cb) {
if (typeof cb !== 'function') { throw new Error('Callback is required') }
let { data } = context
context.url = __guard__(data, x => x.url) || path
if (data) {
context.url = data.url || path
}

let responseMiddlewareAsyncs = plus.map(plus.filter(plugins, ({responseMiddlewareAsync}) => responseMiddlewareAsync), plugin => plugin.responseMiddlewareAsync.bind(plugin)
)
Expand Down Expand Up @@ -153,7 +166,3 @@ let OctokatBase = function (clientOptions = {}) {
}

module.exports = OctokatBase

function __guard__ (value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined
}
6 changes: 1 addition & 5 deletions src/helpers/base64.js
Expand Up @@ -6,7 +6,7 @@
if (typeof window !== 'undefined' && window !== null) {
var base64encode = window.btoa
// Use the `Buffer` if available (NodeJS)
} else if (__guard__(global, x => x['Buffer'])) {
} else if (typeof global !== 'undefined' && global['Buffer']) {
var base64encode = function (str) {
let buffer = new global['Buffer'](str, 'binary')
return buffer.toString('base64')
Expand All @@ -16,7 +16,3 @@ if (typeof window !== 'undefined' && window !== null) {
}

module.exports = base64encode

function __guard__ (value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined
}
6 changes: 1 addition & 5 deletions src/helpers/promise-find-library.js
Expand Up @@ -35,7 +35,7 @@ if (typeof window !== 'undefined' && window !== null) {
}
return allPromises = promises => $q.all(promises)
})
} else if (__guard__(window.jQuery, x => x.Deferred)) {
} else if (window.jQuery && window.jQuery.Deferred) {
var newPromise = fn => {
let promise = window.jQuery.Deferred()
let resolve = val => promise.resolve(val)
Expand All @@ -55,7 +55,3 @@ if (typeof window !== 'undefined' && window !== null) {
}

export { newPromise, allPromises }

function __guard__ (value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined
}
11 changes: 3 additions & 8 deletions src/plugins/promise/library-first.js
Expand Up @@ -9,7 +9,9 @@ if ((typeof window === 'undefined' || window === null) && !newPromise) {

if ((typeof window !== 'undefined' && window !== null) && !newPromise) {
// Otherwise, show a warning (library can still be used with just callbacks)
__guardFunc__(__guard__(console, x => x.warn), f => f('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise'))
if (window.console && window.console.warn) {
window.console.warn('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise')
}
} else if ((typeof window === 'undefined' || window === null) && !newPromise) {
// Running in NodeJS
throw new Error('Could not find a promise lib for node. Seems like a bug')
Expand All @@ -19,10 +21,3 @@ if ((typeof window !== 'undefined' && window !== null) && !newPromise) {
module.exports = {
promiseCreator: {newPromise, allPromises}
}

function __guardFunc__ (func, transform) {
return typeof func === 'function' ? transform(func) : undefined
}
function __guard__ (value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined
}
21 changes: 8 additions & 13 deletions src/plugins/promise/native-first.js
@@ -1,27 +1,22 @@
let { newPromise, allPromises } = require('../../helpers/promise-find-native');
let { newPromise, allPromises } = require('../../helpers/promise-find-native')
if (!newPromise || !allPromises) {
({newPromise, allPromises} = require('../../helpers/promise-find-library'));
({newPromise, allPromises} = require('../../helpers/promise-find-library'))
}
if ((typeof window === 'undefined' || window === null) && !newPromise) {
({newPromise, allPromises} = require('../../helpers/promise-node'));
({newPromise, allPromises} = require('../../helpers/promise-node'))
}

if ((typeof window !== 'undefined' && window !== null) && !newPromise) {
// Otherwise, show a warning (library can still be used with just callbacks)
__guardFunc__(__guard__(console, x => x.warn), f => f('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise'));
if (window.console && window.console.warn) {
window.console.warn('Octokat: A Promise API was not found. Supported libraries that have Promises are jQuery, angularjs, and es6-promise')
}

} else if ((typeof window === 'undefined' || window === null) && !newPromise) {
// Running in NodeJS
throw new Error('Could not find a promise lib for node. Seems like a bug');
throw new Error('Could not find a promise lib for node. Seems like a bug')
}

module.exports = new class PreferNativeOverLibraryPromises {
promiseCreator = {newPromise, allPromises};
};

function __guardFunc__(func, transform) {
return typeof func === 'function' ? transform(func) : undefined;
}
function __guard__(value, transform) {
return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined;
promiseCreator = {newPromise, allPromises}
}

0 comments on commit 6f49a95

Please sign in to comment.