From b049f5b708eeaa0e9a66100b53be2ea373896f2d Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 3 Jun 2020 21:38:57 +0100 Subject: [PATCH] format prettier --- README.md | 2 +- example/app.js | 2 +- lib/deeplink.js | 15 ++++++-------- lib/public/index.html | 2 +- lib/public/script.js | 16 +++++++-------- test/lib/browser.js | 2 +- test/lib/device.js | 2 +- test/test.js | 48 +++++++++++++++++++++---------------------- 8 files changed, 43 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 4338e86..993e851 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ app.get( fallback: 'https://cupsapp.com', android_package_name: 'com.citylifeapps.cups', ios_store_link: - 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4' + 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4', }) ); ``` diff --git a/example/app.js b/example/app.js index 7f4acce..c68272c 100644 --- a/example/app.js +++ b/example/app.js @@ -9,7 +9,7 @@ app.get( fallback: 'http://cupsapp.com', android_package_name: 'com.citylifeapps.cups', ios_store_link: - 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4' + 'https://itunes.apple.com/us/app/cups-unlimited-coffee/id556462755?mt=8&uo=4', }) ); diff --git a/lib/deeplink.js b/lib/deeplink.js index a2597eb..980a67e 100644 --- a/lib/deeplink.js +++ b/lib/deeplink.js @@ -3,7 +3,7 @@ const inliner = require('html-inline'); const stream = require('stream'); const path = require('path'); -module.exports = function(options) { +module.exports = function (options) { options = options || {}; if (!options.fallback) { throw new Error('Error (deeplink): options.fallback cannot be null'); @@ -12,9 +12,9 @@ module.exports = function(options) { options.ios_store_link = options.ios_store_link || ''; options.title = options.title || ''; - const deeplink = function(req, res, next) { + const deeplink = function (req, res, next) { const opts = {}; - Object.keys(options).forEach(function(k) { + Object.keys(options).forEach(function (k) { opts[k] = options[k]; }); @@ -38,9 +38,9 @@ module.exports = function(options) { // replace all template tokens with values from options const detoken = new stream.Transform({ objectMode: true }); - detoken._transform = function(chunk, encoding, done) { + detoken._transform = function (chunk, encoding, done) { let data = chunk.toString(); - Object.keys(opts).forEach(function(key) { + Object.keys(opts).forEach(function (key) { data = data.replace('{{' + key + '}}', opts[key]); }); @@ -55,10 +55,7 @@ module.exports = function(options) { res.set('Content-Type', 'text/html;charset=utf-8'); // read file --> detokenize --> inline js --> send out - file - .pipe(detoken) - .pipe(inline) - .pipe(res); + file.pipe(detoken).pipe(inline).pipe(res); }; return deeplink; diff --git a/lib/public/index.html b/lib/public/index.html index 316770e..0faa931 100644 --- a/lib/public/index.html +++ b/lib/public/index.html @@ -12,7 +12,7 @@ fallback: '{{fallback}}', url: '{{url}}', ios_store_link: '{{ios_store_link}}', - android_package_name: '{{android_package_name}}' + android_package_name: '{{android_package_name}}', }; deepLink(options); diff --git a/lib/public/script.js b/lib/public/script.js index ac75f4f..80dcaa3 100644 --- a/lib/public/script.js +++ b/lib/public/script.js @@ -24,16 +24,16 @@ function deepLink(options) { androidPackageName + ';end;', playStoreLink: playStoreLink, - fallback: fallback + fallback: fallback, }; var isMobile = { - android: function() { + android: function () { return /Android/i.test(ua); }, - ios: function() { + ios: function () { return /iPhone|iPad|iPod/i.test(ua); - } + }, }; // fallback to the application store on mobile devices @@ -47,7 +47,7 @@ function deepLink(options) { function launchWekitApproach(url, fallback) { document.location = url; - setTimeout(function() { + setTimeout(function () { document.location = fallback; }, 250); } @@ -57,15 +57,15 @@ function deepLink(options) { iframe.style.border = 'none'; iframe.style.width = '1px'; iframe.style.height = '1px'; - iframe.onload = function() { + iframe.onload = function () { document.location = url; }; iframe.src = url; - window.onload = function() { + window.onload = function () { document.body.appendChild(iframe); - setTimeout(function() { + setTimeout(function () { window.location = fallback; }, 25); }; diff --git a/test/lib/browser.js b/test/lib/browser.js index 0851410..eef8c8f 100644 --- a/test/lib/browser.js +++ b/test/lib/browser.js @@ -4,7 +4,7 @@ const deeplink = require('../..'); const noop = () => {}; -module.exports = function(ua) { +module.exports = function (ua) { const obj = {}; Browser.localhost('localhost', 3000); const browser = new Browser(); diff --git a/test/lib/device.js b/test/lib/device.js index 32f86e7..913844b 100644 --- a/test/lib/device.js +++ b/test/lib/device.js @@ -2,5 +2,5 @@ module.exports = { android: 'Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36', ios: - 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3' + 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3', }; diff --git a/test/test.js b/test/test.js index 5ea6440..de844f7 100644 --- a/test/test.js +++ b/test/test.js @@ -19,14 +19,14 @@ describe('android', () => { browser.close(); }); - it('should return intent on android device', done => { + it('should return intent on android device', (done) => { browser.go( url, { fallback: fallback, - android_package_name: androidPackageName + android_package_name: androidPackageName, }, - res => { + (res) => { assert.equal( res, 'intent://test/#Intent;scheme=app;package=ind.vandelay.art;end;' @@ -36,15 +36,15 @@ describe('android', () => { ); }); - it('should return intent on android device based on configured url', done => { + it('should return intent on android device based on configured url', (done) => { browser.go( null, { fallback: fallback, android_package_name: androidPackageName, - url: url + url: url, }, - res => { + (res) => { assert.equal( res, 'intent://test/#Intent;scheme=app;package=ind.vandelay.art;end;' @@ -54,13 +54,13 @@ describe('android', () => { ); }); - it('should return the fallback url when no package name defined in android', done => { + it('should return the fallback url when no package name defined in android', (done) => { browser.go( url, { - fallback: fallback + fallback: fallback, }, - res => { + (res) => { assert.equal(res, fallback); done(); } @@ -79,42 +79,42 @@ describe('ios', () => { browser.close(); }); - it('should return deeplink url on ios device', done => { + it('should return deeplink url on ios device', (done) => { browser.go( url, { fallback: fallback, - ios_store_link: iosStoreLink + ios_store_link: iosStoreLink, }, - res => { + (res) => { assert.equal(res, url); done(); } ); }); - it('should return deeplink url on ios device based on configured url', done => { + it('should return deeplink url on ios device based on configured url', (done) => { browser.go( null, { fallback: fallback, ios_store_link: iosStoreLink, - url: url + url: url, }, - res => { + (res) => { assert.equal(res, url); done(); } ); }); - it('should return the fallback url when no ios store link defined in ios', done => { + it('should return the fallback url when no ios store link defined in ios', (done) => { browser.go( url, { - fallback: fallback + fallback: fallback, }, - res => { + (res) => { assert.equal(res, fallback); done(); } @@ -133,31 +133,31 @@ describe('general', () => { browser.close(); }); - it('should go to fallback url on an unsupported device', done => { + it('should go to fallback url on an unsupported device', (done) => { browser.go( url, { fallback: fallback, ios_store_link: iosStoreLink, - android_package_name: androidPackageName + android_package_name: androidPackageName, }, - res => { + (res) => { assert.equal(res, fallback); done(); } ); }); - it('should use the configured url if none was provided in the query params', done => { + it('should use the configured url if none was provided in the query params', (done) => { browser.go( null, { fallback: fallback, ios_store_link: iosStoreLink, android_package_name: androidPackageName, - url: url + url: url, }, - res => { + (res) => { assert.equal(res, fallback); done(); }