Skip to content

Commit

Permalink
Use arrows in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex-stripe committed May 8, 2019
1 parent 579060e commit 6f2dcb6
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/Webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Webhook = {
const signature = {
EXPECTED_SCHEME: 'v1',

_computeSignature(payload, secret) {
_computeSignature: (payload, secret) => {
return crypto
.createHmac('sha256', secret)
.update(payload, 'utf8')
Expand Down
12 changes: 6 additions & 6 deletions lib/autoPagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) {
}

function asyncIteratorNext() {
return memoizedPromise(promiseCache, (resolve, reject) =>
listPromise
return memoizedPromise(promiseCache, (resolve, reject) => {
return listPromise
.then(iterate)
.then(resolve)
.catch(reject)
);
.catch(reject);
});
}

const autoPagingEach = makeAutoPagingEach(asyncIteratorNext);
Expand All @@ -55,11 +55,11 @@ function makeAutoPaginationMethods(self, requestArgs, spec, firstPagePromise) {

// Async iterator functions:
next: asyncIteratorNext,
return() {
return: () => {
// This is required for `break`.
return {};
},
[getAsyncIteratorSymbol()]: function() {
[getAsyncIteratorSymbol()]: () => {
return autoPaginationMethods;
},
};
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/EphemeralKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const stripeMethod = StripeResource.method;
module.exports = StripeResource.extend({
create: stripeMethod({
method: 'POST',
validator(data, options) {
validator: (data, options) => {
if (!options.headers || !options.headers['Stripe-Version']) {
throw new Error(
'stripe_version must be specified to create an ephemeral key'
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Stripe.prototype = {
return this._clientId;
},

getConstant(c) {
getConstant: (c) => {
return Stripe[c];
},

Expand Down
41 changes: 20 additions & 21 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,23 @@ const OPTIONS_KEYS = [
];

const utils = (module.exports = {
isAuthKey(key) {
isAuthKey: (key) => {
return typeof key == 'string' && /^(?:[a-z]{2}_)?[A-z0-9]{32}$/.test(key);
},

isOptionsHash(o) {
isOptionsHash: (o) => {
return isPlainObject(o) && OPTIONS_KEYS.some((key) => hasOwn.call(o, key));
},

/**
* Stringifies an Object, accommodating nested objects
* (forming the conventional key 'parent[child]=value')
*/
stringifyRequestData(data) {
stringifyRequestData: (data) => {
return (
qs
.stringify(data, {
serializeDate(d) {
return Math.floor(d.getTime() / 1000);
},
serializeDate: (d) => Math.floor(d.getTime() / 1000),
})
// Don't use strict form encoding by changing the square bracket control
// characters back to their literals. This is fine by the server, and
Expand All @@ -58,19 +56,20 @@ const utils = (module.exports = {
'\u2028': '\\u2028',
'\u2029': '\\u2029',
};
return function makeURLInterpolator(str) {
return (str) => {
const cleanString = str.replace(/["\n\r\u2028\u2029]/g, ($0) => rc[$0]);
return (outputs) =>
cleanString.replace(/\{([\s\S]+?)\}/g, ($0, $1) =>
return (outputs) => {
return cleanString.replace(/\{([\s\S]+?)\}/g, ($0, $1) =>
encodeURIComponent(outputs[$1] || '')
);
};
};
})(),

/**
* Return the data argument from a list of arguments
*/
getDataFromArgs(args) {
getDataFromArgs: (args) => {
if (args.length < 1 || !isPlainObject(args[0])) {
return {};
}
Expand Down Expand Up @@ -106,7 +105,7 @@ const utils = (module.exports = {
/**
* Return the options hash from a list of arguments
*/
getOptionsFromArgs(args) {
getOptionsFromArgs: (args) => {
const opts = {
auth: null,
headers: {},
Expand Down Expand Up @@ -171,7 +170,7 @@ const utils = (module.exports = {
/**
* Secure compare, from https://github.com/freewil/scmp
*/
secureCompare(a, b) {
secureCompare: (a, b) => {
a = Buffer.from(a);
b = Buffer.from(b);

Expand Down Expand Up @@ -199,7 +198,7 @@ const utils = (module.exports = {
/**
* Remove empty values from an object
*/
removeEmpty(obj) {
removeEmpty: (obj) => {
if (typeof obj !== 'object') {
throw new Error('Argument must be an object');
}
Expand All @@ -217,14 +216,14 @@ const utils = (module.exports = {
* Determine if file data is a derivative of EventEmitter class.
* https://nodejs.org/api/events.html#events_events
*/
checkForStream(obj) {
checkForStream: (obj) => {
if (obj.file && obj.file.data) {
return obj.file.data instanceof EventEmitter;
}
return false;
},

callbackifyPromiseWithTimeout(promise, callback) {
callbackifyPromiseWithTimeout: (promise, callback) => {
if (callback) {
// Ensure callback is called outside of promise stack.
return promise.then(
Expand All @@ -247,7 +246,7 @@ const utils = (module.exports = {
/**
* Allow for special capitalization cases (such as OAuth)
*/
pascalToCamelCase(name) {
pascalToCamelCase: (name) => {
if (name === 'OAuth') {
return 'oauth';
} else {
Expand All @@ -264,7 +263,7 @@ const utils = (module.exports = {
*
* This unifies that interface.
*/
safeExec: function safeExec(cmd, cb) {
safeExec: (cmd, cb) => {
try {
utils._exec(cmd, cb);
} catch (e) {
Expand All @@ -275,16 +274,16 @@ const utils = (module.exports = {
// For mocking in tests.
_exec: exec,

isObject: function isObject(obj) {
isObject: (obj) => {
const type = typeof obj;
return (type === 'function' || type === 'object') && !!obj;
},

// For use in multipart requests
flattenAndStringify: function flattenAndStringify(data) {
flattenAndStringify: (data) => {
const result = {};

function step(obj, prevKey) {
const step = (obj, prevKey) => {
Object.keys(obj).forEach((key) => {
const value = obj[key];

Expand All @@ -303,7 +302,7 @@ const utils = (module.exports = {
result[newKey] = String(value);
}
});
}
};

step(data);

Expand Down
10 changes: 5 additions & 5 deletions testUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ require('chai').use(require('chai-as-promised'));
const ResourceNamespace = require('../lib/ResourceNamespace').ResourceNamespace;

const utils = (module.exports = {
getUserStripeKey() {
getUserStripeKey: () => {
const key =
process.env.STRIPE_TEST_API_KEY || 'tGN0bIwXnHdwOa85VABjPdSn8nWY7G7I';

return key;
},

getSpyableStripe() {
getSpyableStripe: () => {
// Provide a testable stripe instance
// That is, with mock-requests built in and hookable

Expand Down Expand Up @@ -146,17 +146,17 @@ const utils = (module.exports = {
/**
* Get a random string for test Object creation
*/
getRandomString() {
getRandomString: () => {
return Math.random()
.toString(36)
.slice(2);
},

envSupportsForAwait() {
envSupportsForAwait: () => {
return typeof Symbol !== 'undefined' && Symbol.asyncIterator;
},

envSupportsAwait() {
envSupportsAwait: () => {
try {
eval('(async function() {})'); // eslint-disable-line no-eval
return true;
Expand Down

0 comments on commit 6f2dcb6

Please sign in to comment.