From ddfb01ad1615468281f231277bc30e29a82f6dbf Mon Sep 17 00:00:00 2001 From: Robin Hos Date: Sun, 14 Jun 2020 14:53:35 +0200 Subject: [PATCH] Fix this is undefined for arrow functions --- lib/utils.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 3dcc774..64707fb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -124,24 +124,28 @@ exports.generateEtag = data => // Check if valid S3 path -exports.isS3 = path => /^s3:\/\/.+\/.+/i.test(path) +const isS3 = path => /^s3:\/\/.+\/.+/i.test(path) + +exports.isS3 = isS3 // Parse S3 path exports.parseS3 = path => { - if (!this.isS3(path)) throw new FileError('Invalid S3 path',{path}) + if (!isS3(path)) throw new FileError('Invalid S3 path',{path}) let s3object = path.replace(/^s3:\/\//i,'').split('/') return { Bucket: s3object.shift(), Key: s3object.join('/') } } // Deep Merge -exports.deepMerge = (a,b) => { +const deepMerge = (a,b) => { Object.keys(b).forEach(key => (key in a) ? - this.deepMerge(a[key],b[key]) : Object.assign(a,b) ) + deepMerge(a[key],b[key]) : Object.assign(a,b) ) return a } +exports.deepMerge = deepMerge + exports.mergeObjects = (obj1,obj2) => Object.keys(Object.assign({},obj1,obj2)).reduce((acc,key) => { if (obj1[key] && obj2[key] && obj1[key].every(e => obj2[key].includes(e))) {