loop54-js-lib
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -7,5 +7,11 @@ 'use strict'; | ||
var _promisePolyfill = require('promise-polyfill'); | ||
var _promisePolyfill2 = _interopRequireDefault(_promisePolyfill); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// vanilla JS compabillity | ||
global.Loop54 = _index2.default; | ||
global.Loop54 = _index2.default; | ||
global.Promise = _promisePolyfill2.default; |
@@ -1033,3 +1033,7 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
process.emit = noop; | ||
process.prependListener = noop; | ||
process.prependOnceListener = noop; | ||
process.listeners = function (name) { return [] } | ||
process.binding = function (name) { | ||
@@ -1046,2 +1050,237 @@ throw new Error('process.binding is not supported'); | ||
},{}],15:[function(require,module,exports){ | ||
(function (root) { | ||
// Store setTimeout reference so promise-polyfill will be unaffected by | ||
// other code modifying setTimeout (like sinon.useFakeTimers()) | ||
var setTimeoutFunc = setTimeout; | ||
function noop() {} | ||
// Polyfill for Function.prototype.bind | ||
function bind(fn, thisArg) { | ||
return function () { | ||
fn.apply(thisArg, arguments); | ||
}; | ||
} | ||
function Promise(fn) { | ||
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new'); | ||
if (typeof fn !== 'function') throw new TypeError('not a function'); | ||
this._state = 0; | ||
this._handled = false; | ||
this._value = undefined; | ||
this._deferreds = []; | ||
doResolve(fn, this); | ||
} | ||
function handle(self, deferred) { | ||
while (self._state === 3) { | ||
self = self._value; | ||
} | ||
if (self._state === 0) { | ||
self._deferreds.push(deferred); | ||
return; | ||
} | ||
self._handled = true; | ||
Promise._immediateFn(function () { | ||
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected; | ||
if (cb === null) { | ||
(self._state === 1 ? resolve : reject)(deferred.promise, self._value); | ||
return; | ||
} | ||
var ret; | ||
try { | ||
ret = cb(self._value); | ||
} catch (e) { | ||
reject(deferred.promise, e); | ||
return; | ||
} | ||
resolve(deferred.promise, ret); | ||
}); | ||
} | ||
function resolve(self, newValue) { | ||
try { | ||
// Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure | ||
if (newValue === self) throw new TypeError('A promise cannot be resolved with itself.'); | ||
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) { | ||
var then = newValue.then; | ||
if (newValue instanceof Promise) { | ||
self._state = 3; | ||
self._value = newValue; | ||
finale(self); | ||
return; | ||
} else if (typeof then === 'function') { | ||
doResolve(bind(then, newValue), self); | ||
return; | ||
} | ||
} | ||
self._state = 1; | ||
self._value = newValue; | ||
finale(self); | ||
} catch (e) { | ||
reject(self, e); | ||
} | ||
} | ||
function reject(self, newValue) { | ||
self._state = 2; | ||
self._value = newValue; | ||
finale(self); | ||
} | ||
function finale(self) { | ||
if (self._state === 2 && self._deferreds.length === 0) { | ||
Promise._immediateFn(function() { | ||
if (!self._handled) { | ||
Promise._unhandledRejectionFn(self._value); | ||
} | ||
}); | ||
} | ||
for (var i = 0, len = self._deferreds.length; i < len; i++) { | ||
handle(self, self._deferreds[i]); | ||
} | ||
self._deferreds = null; | ||
} | ||
function Handler(onFulfilled, onRejected, promise) { | ||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null; | ||
this.onRejected = typeof onRejected === 'function' ? onRejected : null; | ||
this.promise = promise; | ||
} | ||
/** | ||
* Take a potentially misbehaving resolver function and make sure | ||
* onFulfilled and onRejected are only called once. | ||
* | ||
* Makes no guarantees about asynchrony. | ||
*/ | ||
function doResolve(fn, self) { | ||
var done = false; | ||
try { | ||
fn(function (value) { | ||
if (done) return; | ||
done = true; | ||
resolve(self, value); | ||
}, function (reason) { | ||
if (done) return; | ||
done = true; | ||
reject(self, reason); | ||
}); | ||
} catch (ex) { | ||
if (done) return; | ||
done = true; | ||
reject(self, ex); | ||
} | ||
} | ||
Promise.prototype['catch'] = function (onRejected) { | ||
return this.then(null, onRejected); | ||
}; | ||
Promise.prototype.then = function (onFulfilled, onRejected) { | ||
var prom = new (this.constructor)(noop); | ||
handle(this, new Handler(onFulfilled, onRejected, prom)); | ||
return prom; | ||
}; | ||
Promise.all = function (arr) { | ||
var args = Array.prototype.slice.call(arr); | ||
return new Promise(function (resolve, reject) { | ||
if (args.length === 0) return resolve([]); | ||
var remaining = args.length; | ||
function res(i, val) { | ||
try { | ||
if (val && (typeof val === 'object' || typeof val === 'function')) { | ||
var then = val.then; | ||
if (typeof then === 'function') { | ||
then.call(val, function (val) { | ||
res(i, val); | ||
}, reject); | ||
return; | ||
} | ||
} | ||
args[i] = val; | ||
if (--remaining === 0) { | ||
resolve(args); | ||
} | ||
} catch (ex) { | ||
reject(ex); | ||
} | ||
} | ||
for (var i = 0; i < args.length; i++) { | ||
res(i, args[i]); | ||
} | ||
}); | ||
}; | ||
Promise.resolve = function (value) { | ||
if (value && typeof value === 'object' && value.constructor === Promise) { | ||
return value; | ||
} | ||
return new Promise(function (resolve) { | ||
resolve(value); | ||
}); | ||
}; | ||
Promise.reject = function (value) { | ||
return new Promise(function (resolve, reject) { | ||
reject(value); | ||
}); | ||
}; | ||
Promise.race = function (values) { | ||
return new Promise(function (resolve, reject) { | ||
for (var i = 0, len = values.length; i < len; i++) { | ||
values[i].then(resolve, reject); | ||
} | ||
}); | ||
}; | ||
// Use polyfill for setImmediate for performance gains | ||
Promise._immediateFn = (typeof setImmediate === 'function' && function (fn) { setImmediate(fn); }) || | ||
function (fn) { | ||
setTimeoutFunc(fn, 0); | ||
}; | ||
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) { | ||
if (typeof console !== 'undefined' && console) { | ||
console.warn('Possible Unhandled Promise Rejection:', err); // eslint-disable-line no-console | ||
} | ||
}; | ||
/** | ||
* Set the immediate function to execute callbacks | ||
* @param fn {function} Function to execute | ||
* @deprecated | ||
*/ | ||
Promise._setImmediateFn = function _setImmediateFn(fn) { | ||
Promise._immediateFn = fn; | ||
}; | ||
/** | ||
* Change the function to execute on unhandled rejection | ||
* @param {function} fn Function to execute on unhandled rejection | ||
* @deprecated | ||
*/ | ||
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) { | ||
Promise._unhandledRejectionFn = fn; | ||
}; | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = Promise; | ||
} else if (!root.Promise) { | ||
root.Promise = Promise; | ||
} | ||
})(this); | ||
},{}],16:[function(require,module,exports){ | ||
(function (global){ | ||
@@ -1054,2 +1293,6 @@ 'use strict'; | ||
var _promisePolyfill = require('promise-polyfill'); | ||
var _promisePolyfill2 = _interopRequireDefault(_promisePolyfill); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -1060,4 +1303,6 @@ | ||
global.Promise = _promisePolyfill2.default; | ||
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) | ||
},{"./index.js":17}],16:[function(require,module,exports){ | ||
},{"./index.js":18,"promise-polyfill":15}],17:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -1110,3 +1355,3 @@ | ||
},{}],17:[function(require,module,exports){ | ||
},{}],18:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -1205,2 +1450,2 @@ | ||
},{"./cookies.js":16,"axios":1}]},{},[15]); | ||
},{"./cookies.js":17,"axios":1}]},{},[16]); |
{ | ||
"name": "loop54-js-lib", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "JS lib for Loop54 easy frontend implementation.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1388
0
46741
10