Force lineendings on more file types

This commit is contained in:
Nathaniel van Diepen
2017-04-18 12:12:54 -06:00
parent fc454a555b
commit 84f30cc918
55 changed files with 4569 additions and 4563 deletions

View File

@@ -1,67 +1,67 @@
/* global browser */
//jshint esnext:true
var config = {
// Extension name
name: 'WakaTime',
// Extension version
version: browser.runtime.getManifest().version,
// Time for idle state of the browser
// The user is considered idle if there was
// no activity in the browser for x seconds
detectionIntervalInSeconds: 60,
// Default logging style
// Log all except blacklisted sites
// or log only the white listed sites.
loggingStyle: 'blacklist',
// Default logging type
loggingType: 'domain',
// By default logging is enabled
loggingEnabled: true,
// Url to which to send the heartbeat
heartbeatApiUrl: 'https://wakatime.com/api/v1/users/current/heartbeats',
// Url from which to detect if the user is logged in
currentUserApiUrl: 'https://wakatime.com/api/v1/users/current',
// The url to logout the user from wakatime
logoutUserUrl: 'https://wakatime.com/logout',
// Gets stats from the WakaTime API
summariesApiUrl: 'https://wakatime.com/api/v1/users/current/summaries',
// Different colors for different states of the extension
colors: {
allGood: '',
notLogging: 'gray',
notSignedIn: 'red',
lightTheme: 'white'
},
// Tooltips for each of the extension states
tooltips: {
allGood: '',
notLogging: 'Not logging',
notSignedIn: 'Not signed In',
blacklisted: 'This URL is blacklisted',
whitelisted: 'This URL is not on your whitelist'
},
// Default theme
theme: 'light',
// Valid extension states
states: [
'allGood',
'notLogging',
'notSignedIn',
'blacklisted',
'whitelisted'
],
// Predefined alert type and text for success and failure.
alert: {
success: {
type: 'success',
text: 'Options have been saved!'
},
failure: {
type: 'danger',
text: 'There was an error while saving the options!'
}
}
};
module.exports = config;
/* global browser */
//jshint esnext:true
var config = {
// Extension name
name: 'WakaTime',
// Extension version
version: browser.runtime.getManifest().version,
// Time for idle state of the browser
// The user is considered idle if there was
// no activity in the browser for x seconds
detectionIntervalInSeconds: 60,
// Default logging style
// Log all except blacklisted sites
// or log only the white listed sites.
loggingStyle: 'blacklist',
// Default logging type
loggingType: 'domain',
// By default logging is enabled
loggingEnabled: true,
// Url to which to send the heartbeat
heartbeatApiUrl: 'https://wakatime.com/api/v1/users/current/heartbeats',
// Url from which to detect if the user is logged in
currentUserApiUrl: 'https://wakatime.com/api/v1/users/current',
// The url to logout the user from wakatime
logoutUserUrl: 'https://wakatime.com/logout',
// Gets stats from the WakaTime API
summariesApiUrl: 'https://wakatime.com/api/v1/users/current/summaries',
// Different colors for different states of the extension
colors: {
allGood: '',
notLogging: 'gray',
notSignedIn: 'red',
lightTheme: 'white'
},
// Tooltips for each of the extension states
tooltips: {
allGood: '',
notLogging: 'Not logging',
notSignedIn: 'Not signed In',
blacklisted: 'This URL is blacklisted',
whitelisted: 'This URL is not on your whitelist'
},
// Default theme
theme: 'light',
// Valid extension states
states: [
'allGood',
'notLogging',
'notSignedIn',
'blacklisted',
'whitelisted'
],
// Predefined alert type and text for success and failure.
alert: {
success: {
type: 'success',
text: 'Options have been saved!'
},
failure: {
type: 'danger',
text: 'There was an error while saving the options!'
}
}
};
module.exports = config;

View File

@@ -1,256 +1,256 @@
/* global browser */
//jshint esnext:true
var $ = require('jquery');
var moment = require('moment');
var config = require('./../config');
// Helpers
var getDomainFromUrl = require('./../helpers/getDomainFromUrl');
var changeExtensionState = require('../helpers/changeExtensionState');
var in_array = require('./../helpers/in_array');
var contains = require('./../helpers/contains');
class WakaTimeCore {
constructor() {
this.tabsWithDevtoolsOpen = [];
}
/**
* Settter for tabsWithDevtoolsOpen
*
* @param tabs
*/
setTabsWithDevtoolsOpen(tabs) {
this.tabsWithDevtoolsOpen = tabs;
}
getTotalTimeLoggedToday() {
var deferredObject = $.Deferred();
var today = moment().format('YYYY-MM-DD');
$.ajax({
url: config.summariesApiUrl + '?start=' + today + '&end=' + today,
dataType: 'json',
success: (data) => {
deferredObject.resolve(data.data[0].grand_total);
},
error: (xhr, status, err) => {
console.error(config.summariesApiUrl, status, err.toString());
deferredObject.resolve(false);
}
});
return deferredObject.promise();
}
/**
* Checks if the user is logged in.
*
* @returns {*}
*/
checkAuth() {
var deferredObject = $.Deferred();
$.ajax({
url: config.currentUserApiUrl,
dataType: 'json',
success: (data) => {
deferredObject.resolve(data.data);
},
error: (xhr, status, err) => {
console.error(config.currentUserApiUrl, status, err.toString());
deferredObject.resolve(false);
}
});
return deferredObject.promise();
}
/**
* Depending on various factors detects the current active tab URL or domain,
* and sends it to WakaTime for logging.
*/
recordHeartbeat() {
browser.storage.sync.get({
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
blacklist: '',
whitelist: ''
}).then((items) => {
if (items.loggingEnabled === true) {
changeExtensionState('allGood');
browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => {
if (newState === 'active') {
// Get current tab URL.
browser.tabs.query({active: true}).then((tabs) => {
var currentActiveTab = tabs[0];
var debug = false;
// If the current active tab has devtools open
if (in_array(currentActiveTab.id, this.tabsWithDevtoolsOpen)) debug = true;
if (items.loggingStyle == 'blacklist') {
if (! contains(currentActiveTab.url, items.blacklist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('blacklisted');
console.log(currentActiveTab.url + ' is on a blacklist.');
}
}
if (items.loggingStyle == 'whitelist') {
if (contains(currentActiveTab.url, items.whitelist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('whitelisted');
console.log(currentActiveTab.url + ' is not on a whitelist.');
}
}
});
}
});
}
else {
changeExtensionState('notLogging');
}
});
}
/**
* Creates payload for the heartbeat and returns it as JSON.
*
* @param entity
* @param type
* @param debug
* @returns {*}
* @private
*/
_preparePayload(entity, type, debug = false) {
return JSON.stringify({
entity: entity,
type: type,
time: moment().format('X'),
project: '<<LAST_PROJECT>>',
is_debugging: debug,
plugin: 'browser-wakatime/' + config.version
});
}
/**
* Returns a promise with logging type variable.
*
* @returns {*}
* @private
*/
_getLoggingType() {
var deferredObject = $.Deferred();
browser.storage.sync.get({
loggingType: config.loggingType
}).then(function (items) {
deferredObject.resolve(items.loggingType);
});
return deferredObject.promise();
}
/**
* Given the entity and logging type it creates a payload and
* sends an ajax post request to the API.
*
* @param entity
* @param debug
*/
sendHeartbeat(entity, debug) {
var payload = null;
this._getLoggingType().done((loggingType) => {
// Get only the domain from the entity.
// And send that in heartbeat
if (loggingType == 'domain') {
var domain = getDomainFromUrl(entity);
payload = this._preparePayload(domain, 'domain', debug);
console.log(payload);
this.sendAjaxRequestToApi(payload);
}
// Send entity in heartbeat
else if (loggingType == 'url') {
payload = this._preparePayload(entity, 'url', debug);
console.log(payload);
this.sendAjaxRequestToApi(payload);
}
});
}
/**
* Sends AJAX request with payload to the heartbeat API as JSON.
*
* @param payload
* @param method
* @returns {*}
*/
sendAjaxRequestToApi(payload, method = 'POST') {
var deferredObject = $.Deferred();
$.ajax({
url: config.heartbeatApiUrl,
dataType: 'json',
contentType: 'application/json',
method: method,
data: payload,
statusCode: {
401: function () {
changeExtensionState('notSignedIn');
},
201: function () {
// nothing to do here
}
},
success: (response) => {
deferredObject.resolve(this);
},
error: (xhr, status, err) => {
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(this);
}
});
return deferredObject.promise();
}
}
//export default WakaTimeCore;
/* global browser */
//jshint esnext:true
var $ = require('jquery');
var moment = require('moment');
var config = require('./../config');
// Helpers
var getDomainFromUrl = require('./../helpers/getDomainFromUrl');
var changeExtensionState = require('../helpers/changeExtensionState');
var in_array = require('./../helpers/in_array');
var contains = require('./../helpers/contains');
class WakaTimeCore {
constructor() {
this.tabsWithDevtoolsOpen = [];
}
/**
* Settter for tabsWithDevtoolsOpen
*
* @param tabs
*/
setTabsWithDevtoolsOpen(tabs) {
this.tabsWithDevtoolsOpen = tabs;
}
getTotalTimeLoggedToday() {
var deferredObject = $.Deferred();
var today = moment().format('YYYY-MM-DD');
$.ajax({
url: config.summariesApiUrl + '?start=' + today + '&end=' + today,
dataType: 'json',
success: (data) => {
deferredObject.resolve(data.data[0].grand_total);
},
error: (xhr, status, err) => {
console.error(config.summariesApiUrl, status, err.toString());
deferredObject.resolve(false);
}
});
return deferredObject.promise();
}
/**
* Checks if the user is logged in.
*
* @returns {*}
*/
checkAuth() {
var deferredObject = $.Deferred();
$.ajax({
url: config.currentUserApiUrl,
dataType: 'json',
success: (data) => {
deferredObject.resolve(data.data);
},
error: (xhr, status, err) => {
console.error(config.currentUserApiUrl, status, err.toString());
deferredObject.resolve(false);
}
});
return deferredObject.promise();
}
/**
* Depending on various factors detects the current active tab URL or domain,
* and sends it to WakaTime for logging.
*/
recordHeartbeat() {
browser.storage.sync.get({
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
blacklist: '',
whitelist: ''
}).then((items) => {
if (items.loggingEnabled === true) {
changeExtensionState('allGood');
browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => {
if (newState === 'active') {
// Get current tab URL.
browser.tabs.query({active: true}).then((tabs) => {
var currentActiveTab = tabs[0];
var debug = false;
// If the current active tab has devtools open
if (in_array(currentActiveTab.id, this.tabsWithDevtoolsOpen)) debug = true;
if (items.loggingStyle == 'blacklist') {
if (! contains(currentActiveTab.url, items.blacklist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('blacklisted');
console.log(currentActiveTab.url + ' is on a blacklist.');
}
}
if (items.loggingStyle == 'whitelist') {
if (contains(currentActiveTab.url, items.whitelist)) {
this.sendHeartbeat(currentActiveTab.url, debug);
}
else {
changeExtensionState('whitelisted');
console.log(currentActiveTab.url + ' is not on a whitelist.');
}
}
});
}
});
}
else {
changeExtensionState('notLogging');
}
});
}
/**
* Creates payload for the heartbeat and returns it as JSON.
*
* @param entity
* @param type
* @param debug
* @returns {*}
* @private
*/
_preparePayload(entity, type, debug = false) {
return JSON.stringify({
entity: entity,
type: type,
time: moment().format('X'),
project: '<<LAST_PROJECT>>',
is_debugging: debug,
plugin: 'browser-wakatime/' + config.version
});
}
/**
* Returns a promise with logging type variable.
*
* @returns {*}
* @private
*/
_getLoggingType() {
var deferredObject = $.Deferred();
browser.storage.sync.get({
loggingType: config.loggingType
}).then(function (items) {
deferredObject.resolve(items.loggingType);
});
return deferredObject.promise();
}
/**
* Given the entity and logging type it creates a payload and
* sends an ajax post request to the API.
*
* @param entity
* @param debug
*/
sendHeartbeat(entity, debug) {
var payload = null;
this._getLoggingType().done((loggingType) => {
// Get only the domain from the entity.
// And send that in heartbeat
if (loggingType == 'domain') {
var domain = getDomainFromUrl(entity);
payload = this._preparePayload(domain, 'domain', debug);
console.log(payload);
this.sendAjaxRequestToApi(payload);
}
// Send entity in heartbeat
else if (loggingType == 'url') {
payload = this._preparePayload(entity, 'url', debug);
console.log(payload);
this.sendAjaxRequestToApi(payload);
}
});
}
/**
* Sends AJAX request with payload to the heartbeat API as JSON.
*
* @param payload
* @param method
* @returns {*}
*/
sendAjaxRequestToApi(payload, method = 'POST') {
var deferredObject = $.Deferred();
$.ajax({
url: config.heartbeatApiUrl,
dataType: 'json',
contentType: 'application/json',
method: method,
data: payload,
statusCode: {
401: function () {
changeExtensionState('notSignedIn');
},
201: function () {
// nothing to do here
}
},
success: (response) => {
deferredObject.resolve(this);
},
error: (xhr, status, err) => {
console.error(config.heartbeatApiUrl, status, err.toString());
deferredObject.resolve(this);
}
});
return deferredObject.promise();
}
}
//export default WakaTimeCore;

View File

@@ -1,12 +1,12 @@
/* global browser */
// Create a connection to the background page
var backgroundPageConnection = browser.runtime.connect({
name: "devtools-page"
});
// Send a message to background page with the current active tabId
backgroundPageConnection.postMessage({
name: 'init',
tabId: browser.devtools.inspectedWindow.tabId
});
/* global browser */
// Create a connection to the background page
var backgroundPageConnection = browser.runtime.connect({
name: "devtools-page"
});
// Send a message to background page with the current active tabId
backgroundPageConnection.postMessage({
name: 'init',
tabId: browser.devtools.inspectedWindow.tabId
});

View File

@@ -1,100 +1,100 @@
/* global browser */
// Core
var WakaTimeCore = require("./core/WakaTimeCore").default;
// initialize class
var wakatime = new WakaTimeCore();
// Holds currently open connections (ports) with devtools
// Uses tabId as index key.
var connections = {};
// Add a listener to resolve alarms
browser.alarms.onAlarm.addListener(function (alarm) {
// |alarm| can be undefined because onAlarm also gets called from
// window.setTimeout on old chrome versions.
if (alarm && alarm.name == 'heartbeatAlarm') {
console.log('recording a heartbeat - alarm triggered');
wakatime.recordHeartbeat();
}
});
// Create a new alarm for heartbeats.
browser.alarms.create('heartbeatAlarm', {periodInMinutes: 2});
/**
* Whenever a active tab is changed it records a heartbeat with that tab url.
*/
browser.tabs.onActivated.addListener(function (activeInfo) {
browser.tabs.get(activeInfo.tabId).then(function (tab) {
console.log('recording a heartbeat - active tab changed');
wakatime.recordHeartbeat();
});
});
/**
* Whenever any tab is updated it checks if the updated tab is the tab that is
* currently active and if it is, then it records a heartbeat.
*/
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status === 'complete') {
// Get current tab URL.
browser.tabs.query({active: true}).then(function(tabs) {
// If tab updated is the same as active tab
if (tabId == tabs[0].id) {
console.log('recording a heartbeat - tab updated');
wakatime.recordHeartbeat();
}
});
}
});
/**
* This is in charge of detecting if devtools are opened or closed
* and sending a heartbeat depending on that.
*/
browser.runtime.onConnect.addListener(function (port) {
if (port.name == "devtools-page") {
// Listen to messages sent from the DevTools page
port.onMessage.addListener(function (message, sender, sendResponse) {
if (message.name == "init") {
connections[message.tabId] = port;
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
wakatime.recordHeartbeat();
}
});
port.onDisconnect.addListener(function (port) {
var tabs = Object.keys(connections);
for (var i = 0, len = tabs.length; i < len; i ++) {
if (connections[tabs[i]] == port) {
delete connections[tabs[i]];
break;
}
}
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
wakatime.recordHeartbeat();
});
}
});
/* global browser */
// Core
var WakaTimeCore = require("./core/WakaTimeCore").default;
// initialize class
var wakatime = new WakaTimeCore();
// Holds currently open connections (ports) with devtools
// Uses tabId as index key.
var connections = {};
// Add a listener to resolve alarms
browser.alarms.onAlarm.addListener(function (alarm) {
// |alarm| can be undefined because onAlarm also gets called from
// window.setTimeout on old chrome versions.
if (alarm && alarm.name == 'heartbeatAlarm') {
console.log('recording a heartbeat - alarm triggered');
wakatime.recordHeartbeat();
}
});
// Create a new alarm for heartbeats.
browser.alarms.create('heartbeatAlarm', {periodInMinutes: 2});
/**
* Whenever a active tab is changed it records a heartbeat with that tab url.
*/
browser.tabs.onActivated.addListener(function (activeInfo) {
browser.tabs.get(activeInfo.tabId).then(function (tab) {
console.log('recording a heartbeat - active tab changed');
wakatime.recordHeartbeat();
});
});
/**
* Whenever any tab is updated it checks if the updated tab is the tab that is
* currently active and if it is, then it records a heartbeat.
*/
browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (changeInfo.status === 'complete') {
// Get current tab URL.
browser.tabs.query({active: true}).then(function(tabs) {
// If tab updated is the same as active tab
if (tabId == tabs[0].id) {
console.log('recording a heartbeat - tab updated');
wakatime.recordHeartbeat();
}
});
}
});
/**
* This is in charge of detecting if devtools are opened or closed
* and sending a heartbeat depending on that.
*/
browser.runtime.onConnect.addListener(function (port) {
if (port.name == "devtools-page") {
// Listen to messages sent from the DevTools page
port.onMessage.addListener(function (message, sender, sendResponse) {
if (message.name == "init") {
connections[message.tabId] = port;
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
wakatime.recordHeartbeat();
}
});
port.onDisconnect.addListener(function (port) {
var tabs = Object.keys(connections);
for (var i = 0, len = tabs.length; i < len; i ++) {
if (connections[tabs[i]] == port) {
delete connections[tabs[i]];
break;
}
}
wakatime.setTabsWithDevtoolsOpen(Object.keys(connections));
wakatime.recordHeartbeat();
});
}
});

View File

@@ -1,50 +1,50 @@
/* global browser */
var config = require('../config');
/**
* It changes the extension icon color.
* Supported values are: 'red', 'white', 'gray' and ''.
*
* @param color
*/
function changeExtensionIcon(color) {
color = color ? color : '';
var path = null;
if (color !== '') {
color = '-' + color;
path = './graphics/wakatime-logo-38' + color + '.png';
browser.browserAction.setIcon({
path: path
});
}
if (color === '') {
browser.storage.sync.get({
theme: config.theme
}).then(function (items) {
if (items.theme == config.theme) {
path = './graphics/wakatime-logo-38.png';
browser.browserAction.setIcon({
path: path
});
}
else {
path = './graphics/wakatime-logo-38-white.png';
browser.browserAction.setIcon({
path: path
});
}
});
}
}
module.exports = changeExtensionIcon;
/* global browser */
var config = require('../config');
/**
* It changes the extension icon color.
* Supported values are: 'red', 'white', 'gray' and ''.
*
* @param color
*/
function changeExtensionIcon(color) {
color = color ? color : '';
var path = null;
if (color !== '') {
color = '-' + color;
path = './graphics/wakatime-logo-38' + color + '.png';
browser.browserAction.setIcon({
path: path
});
}
if (color === '') {
browser.storage.sync.get({
theme: config.theme
}).then(function (items) {
if (items.theme == config.theme) {
path = './graphics/wakatime-logo-38.png';
browser.browserAction.setIcon({
path: path
});
}
else {
path = './graphics/wakatime-logo-38-white.png';
browser.browserAction.setIcon({
path: path
});
}
});
}
}
module.exports = changeExtensionIcon;

View File

@@ -1,42 +1,42 @@
var config = require('../config');
// Helpers
var changeExtensionIcon = require('./changeExtensionIcon');
var changeExtensionTooltip = require('./changeExtensionTooltip');
var in_array = require('./in_array');
/**
* Sets the current state of the extension.
*
* @param state
*/
function changeExtensionState(state) {
if (! in_array(state, config.states)) {
throw new Error('Not a valid state!');
}
switch (state) {
case 'allGood':
changeExtensionIcon(config.colors.allGood);
changeExtensionTooltip(config.tooltips.allGood);
break;
case 'notLogging':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.notLogging);
break;
case 'notSignedIn':
changeExtensionIcon(config.colors.notSignedIn);
changeExtensionTooltip(config.tooltips.notSignedIn);
break;
case 'blacklisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.blacklisted);
break;
case 'whitelisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.whitelisted);
break;
}
}
var config = require('../config');
// Helpers
var changeExtensionIcon = require('./changeExtensionIcon');
var changeExtensionTooltip = require('./changeExtensionTooltip');
var in_array = require('./in_array');
/**
* Sets the current state of the extension.
*
* @param state
*/
function changeExtensionState(state) {
if (! in_array(state, config.states)) {
throw new Error('Not a valid state!');
}
switch (state) {
case 'allGood':
changeExtensionIcon(config.colors.allGood);
changeExtensionTooltip(config.tooltips.allGood);
break;
case 'notLogging':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.notLogging);
break;
case 'notSignedIn':
changeExtensionIcon(config.colors.notSignedIn);
changeExtensionTooltip(config.tooltips.notSignedIn);
break;
case 'blacklisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.blacklisted);
break;
case 'whitelisted':
changeExtensionIcon(config.colors.notLogging);
changeExtensionTooltip(config.tooltips.whitelisted);
break;
}
}
module.exports = changeExtensionState;

View File

@@ -1,22 +1,22 @@
/* global browser */
var config = require('../config');
/**
* It changes the extension title
*
* @param text
*/
function changeExtensionTooltip(text) {
if (text === '') {
text = config.name;
}
else {
text = config.name + ' - ' + text;
}
browser.browserAction.setTitle({title: text});
}
/* global browser */
var config = require('../config');
/**
* It changes the extension title
*
* @param text
*/
function changeExtensionTooltip(text) {
if (text === '') {
text = config.name;
}
else {
text = config.name + ' - ' + text;
}
browser.browserAction.setTitle({title: text});
}
module.exports = changeExtensionTooltip;

View File

@@ -1,29 +1,29 @@
/**
* Creates an array from list using \n as delimiter
* and checks if any element in list is contained in the url.
*
* @param url
* @param list
* @returns {boolean}
*/
function contains(url, list) {
var lines = list.split('\n');
for (var i = 0; i < lines.length; i ++) {
// Trim all lines from the list one by one
var cleanLine = lines[i].trim();
// If by any chance one line in the list is empty, ignore it
if(cleanLine === '') continue;
// If url contains the current line return true
if (url.indexOf(cleanLine) > -1) {
return true;
}
}
return false;
}
module.exports = contains;
/**
* Creates an array from list using \n as delimiter
* and checks if any element in list is contained in the url.
*
* @param url
* @param list
* @returns {boolean}
*/
function contains(url, list) {
var lines = list.split('\n');
for (var i = 0; i < lines.length; i ++) {
// Trim all lines from the list one by one
var cleanLine = lines[i].trim();
// If by any chance one line in the list is empty, ignore it
if(cleanLine === '') continue;
// If url contains the current line return true
if (url.indexOf(cleanLine) > -1) {
return true;
}
}
return false;
}
module.exports = contains;

View File

@@ -1,13 +1,13 @@
/**
* Returns domain from given URL.
*
* @param url
* @returns {string}
*/
function getDomainFromUrl(url) {
var parts = url.split('/');
return parts[0] + "//" + parts[2];
}
/**
* Returns domain from given URL.
*
* @param url
* @returns {string}
*/
function getDomainFromUrl(url) {
var parts = url.split('/');
return parts[0] + "//" + parts[2];
}
module.exports = getDomainFromUrl;

View File

@@ -1,18 +1,18 @@
/**
* Returns boolean if needle is found in haystack or not.
*
* @param needle
* @param haystack
* @returns {boolean}
*/
function in_array(needle, haystack) {
for (var i = 0; i < haystack.length; i ++) {
if (needle == haystack[i]) {
return true;
}
}
return false;
}
/**
* Returns boolean if needle is found in haystack or not.
*
* @param needle
* @param haystack
* @returns {boolean}
*/
function in_array(needle, haystack) {
for (var i = 0; i < haystack.length; i ++) {
if (needle == haystack[i]) {
return true;
}
}
return false;
}
module.exports = in_array;