-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from BitClock/feature
beta v2
- Loading branch information
Showing
14 changed files
with
406 additions
and
259 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
parser: babel-eslint | ||
|
||
extends: | ||
- eslint:recommended | ||
- plugin:import/errors | ||
- plugin:import/warnings | ||
|
||
plugins: | ||
- import | ||
|
||
env: | ||
es6: true | ||
node: true | ||
mocha: true | ||
|
||
rules: | ||
semi: [error, always] | ||
no-unused-vars: [error] | ||
|
||
parserOptions: | ||
sourceType: module | ||
|
||
settings: | ||
import/resolver: | ||
webpack: { config: ./webpack.config.babel.js } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,31 @@ | ||
import { get } from './helpers'; | ||
|
||
export const MIN_INTERVAL = 500; | ||
|
||
export const CHUNK_SIZE_RANGE = [1, 1000]; | ||
|
||
export default { | ||
env: get(global, ['process', 'env', 'NODE_ENV']), | ||
debug: false, | ||
token: null, | ||
bucket: null, | ||
maxChunkSize: 200, | ||
reportingInterval: 5000, | ||
reportingEndpoint: 'https://hub.bitclock.io' | ||
}; | ||
|
||
export const MIN_INTERVAL = 500; | ||
export function validateChunkSize(value) { | ||
return Boolean( | ||
value >= CHUNK_SIZE_RANGE[0] | ||
&& value <= CHUNK_SIZE_RANGE[1] | ||
&& Math.round(value) === value | ||
); | ||
} | ||
|
||
export function validateReportingInterval(value) { | ||
return Boolean( | ||
value | ||
&& value >= MIN_INTERVAL | ||
&& value === Math.round(value) | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import CONFIG from './config'; | ||
import { isBrowser } from './helpers'; | ||
|
||
const { console } = global; | ||
|
||
/** | ||
* debug accepts a function to prevent unnecessary work when debug logging is not enabled | ||
*/ | ||
export function debug(fn) { | ||
/* eslint-disable no-console */ | ||
if (CONFIG.debug && typeof fn === 'function' && console && console.log) { | ||
const value = fn(); | ||
const args = Array.isArray(value) ? value : [value]; | ||
console.log(`${consoleLabel('34m', 'debug')}`, ...args); | ||
} | ||
/* eslint-enable no-console */ | ||
} | ||
|
||
/** | ||
* warn accepts a function to prevent unnecessary work when running in production | ||
*/ | ||
export function warn(fn) { | ||
/* eslint-disable no-console */ | ||
if (CONFIG.env !== 'production' && typeof fn === 'function' && console && console.warn) { | ||
const value = fn(); | ||
const args = Array.isArray(value) ? value : [value]; | ||
console.warn(`${consoleLabel('33m', 'warning')}`, ...args); | ||
} | ||
/* eslint-enable no-console */ | ||
} | ||
|
||
function padLeft(input, length = 0, chars = ' ') { | ||
let result = String(input); | ||
const diff = Math.max(length - result.length, 0); | ||
for (let i = 0; i < diff; i++) { | ||
result = `${chars}${result}`; | ||
} | ||
return result; | ||
} | ||
|
||
function consoleLabel(ansiColor, plainLabel) { | ||
const date = new Date(); | ||
const hours = padLeft(date.getUTCHours(), 2, '0'); | ||
const minutes = padLeft(date.getUTCMinutes(), 2, '0'); | ||
const seconds = padLeft(date.getUTCSeconds(), 2, '0'); | ||
const timestamp = `${hours}:${minutes}:${seconds}`; | ||
const label = isBrowser() ? plainLabel : `\x1B[${ansiColor}${plainLabel}\x1B[0m`; | ||
return `[${timestamp}] - ${label}: [bitclock]`; | ||
} |
Oops, something went wrong.