iguazu
Version:
An asynchronous data flow solution for React/Redux applications
73 lines (61 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.handlePromiseRejection = handlePromiseRejection;
exports.isServer = isServer;
exports.mapValues = mapValues;
exports.pick = pick;
exports.zipObject = zipObject;
/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
function handlePromiseRejection(promise) {
return promise.then(null, function () {
/* swallow */
});
}
function pick(obj, keys) {
var index = keys.length - 1;
var nextObj = {};
while (index > -1) {
nextObj[keys[index]] = obj[keys[index]];
index -= 1;
}
return nextObj;
}
function mapValues(obj, callback) {
var keys = Object.keys(obj);
var index = keys.length - 1;
var nextObj = {};
while (index > -1) {
nextObj[keys[index]] = callback(obj[keys[index]]);
index -= 1;
}
return nextObj;
}
function zipObject(firstArray, secondArray) {
var len = firstArray.length;
var index = 0;
var nextObj = {};
while (index < len) {
nextObj[firstArray[index]] = secondArray[index];
index += 1;
}
return nextObj;
}
function isServer() {
return typeof window === 'undefined';
}