@stripe/stripe-js
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -1,40 +0,53 @@ | ||
const V3_URL = 'https://js.stripe.com/v3'; | ||
const injectScript = () => { | ||
const script = document.createElement('script'); | ||
script.src = V3_URL; | ||
const headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
return script; | ||
}; | ||
// Execute our own script injection after a tick to give users time to | ||
var V3_URL = 'https://js.stripe.com/v3'; | ||
var injectScript = function injectScript() { | ||
var script = document.createElement('script'); | ||
script.src = V3_URL; | ||
var headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
return script; | ||
}; // Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
const stripePromise = Promise.resolve().then(() => { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
const script = document.querySelector(`script[src="${V3_URL}"]`) || injectScript(); | ||
return new Promise((resolve, reject) => { | ||
script.addEventListener('load', () => { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} | ||
else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', () => { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
var stripePromise = Promise.resolve().then(function () { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")) || injectScript(); | ||
return new Promise(function (resolve, reject) { | ||
script.addEventListener('load', function () { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', function () { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
}); | ||
const loadStripe = (...args) => stripePromise.then((maybeStripe) => maybeStripe ? maybeStripe(...args) : null); | ||
var loadStripe = function loadStripe() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
}; | ||
export { loadStripe }; |
@@ -5,41 +5,54 @@ 'use strict'; | ||
const V3_URL = 'https://js.stripe.com/v3'; | ||
const injectScript = () => { | ||
const script = document.createElement('script'); | ||
script.src = V3_URL; | ||
const headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
return script; | ||
}; | ||
// Execute our own script injection after a tick to give users time to | ||
var V3_URL = 'https://js.stripe.com/v3'; | ||
var injectScript = function injectScript() { | ||
var script = document.createElement('script'); | ||
script.src = V3_URL; | ||
var headOrBody = document.head || document.body; | ||
if (!headOrBody) { | ||
throw new Error('Expected document.body not to be null. Stripe.js requires a <body> element.'); | ||
} | ||
headOrBody.appendChild(script); | ||
return script; | ||
}; // Execute our own script injection after a tick to give users time to | ||
// do their own script injection. | ||
const stripePromise = Promise.resolve().then(() => { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
const script = document.querySelector(`script[src="${V3_URL}"]`) || injectScript(); | ||
return new Promise((resolve, reject) => { | ||
script.addEventListener('load', () => { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} | ||
else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', () => { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
var stripePromise = Promise.resolve().then(function () { | ||
if (typeof window === 'undefined') { | ||
// Resolve to null when imported server side. This makes the module | ||
// safe to import in an isomorphic code base. | ||
return null; | ||
} | ||
if (window.Stripe) { | ||
return window.Stripe; | ||
} | ||
var script = document.querySelector("script[src=\"".concat(V3_URL, "\"]")) || injectScript(); | ||
return new Promise(function (resolve, reject) { | ||
script.addEventListener('load', function () { | ||
if (window.Stripe) { | ||
resolve(window.Stripe); | ||
} else { | ||
reject(new Error('Failed to load Stripe.js')); | ||
} | ||
}); | ||
script.addEventListener('error', function () { | ||
reject(new Error('Failed to load Stripe.js')); | ||
}); | ||
}); | ||
}); | ||
const loadStripe = (...args) => stripePromise.then((maybeStripe) => maybeStripe ? maybeStripe(...args) : null); | ||
var loadStripe = function loadStripe() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return stripePromise.then(function (maybeStripe) { | ||
return maybeStripe ? maybeStripe.apply(void 0, args) : null; | ||
}); | ||
}; | ||
exports.loadStripe = loadStripe; |
{ | ||
"name": "@stripe/stripe-js", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Stripe.js loading utility", | ||
@@ -5,0 +5,0 @@ "main": "dist/stripe.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168457
4191