Skip to content

Commit

Permalink
format prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mderazon committed Jun 3, 2020
1 parent e1183e6 commit b049f5b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
);
```
Expand Down
2 changes: 1 addition & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
})
);

Expand Down
15 changes: 6 additions & 9 deletions lib/deeplink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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];
});

Expand All @@ -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]);
});

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
</script>
Expand Down
16 changes: 8 additions & 8 deletions lib/public/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,7 +47,7 @@ function deepLink(options) {

function launchWekitApproach(url, fallback) {
document.location = url;
setTimeout(function() {
setTimeout(function () {
document.location = fallback;
}, 250);
}
Expand All @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion test/lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion test/lib/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
48 changes: 24 additions & 24 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;'
Expand All @@ -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;'
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down

0 comments on commit b049f5b

Please sign in to comment.