viki-web-utils
Web utilities used by the Viki web app
Installation
npm install -S viki-web-utils
For full documentation, see it the docs page or in /docs
directory.
ScrollTracker
Keeps track of the furthest point on page that user has scrolled to (in percentage). Returns most updated value everytime percentageSeen()
is called.
Usage
import Viki from 'viki-web-utils';
const tracker = new Viki.ScrollTracker();
tracker.init();
console.log('percentage of page seen', tracker.percentageSeen())
console.log('percentage of page seen rounded to granularity of 10', tracker.percentageSeenRounded(10))
LocalStorageTabCounter
Keeps track of number of tabs user has open in current session. Saves current count to user's localStorage.
Usage
import Viki from 'viki-web-utils';
const counter = new Viki.LocalStorageTabCounter();
console.log(counter.getCount())
ResizeCounter
Tracks number of times user has resized the window. Debounced at 300ms to prevent too many function calls.
Usage
import Viki from 'viki-web-utils';
const counter = new Viki.ResizeCounter(function() {
});
console.log(counter.getCount())
BlockedResourceChecker
Tests if a resource is blocked on client side. Returns a Promise on test that is passed in blocked
and resource
values.
Usage
const checker = new BlockedResourceChecker('https://badresource.blah');
checker
.test()
.then((res) => {
console.log(res.resource, res.blocked)
});
PerformanceTimingTracker
Pulls information from the client's performance timing API, and allows for augmentation on the information along with retrieving all the stats as a JSON object.
If the target browser does not support the performance timing API, an empty JSON object is returned instead.
Usage
import Viki from 'viki-web-utils';
let performanceTracker = new Viki.PerformanceTimingTracker();
performanceTracker.set('customDeferFullyLoaded', Date.now());
console.log(performanceTracker.get('redirectStart'));
performanceTracker.setDifferenceAsValue('customDeferFullyLoaded', 'redirectStart');
console.log(performanceTracker.extractMetrics());
Development
Install dependencies
npm install
Run tests
npm run test
Karma wil prompt you to open browser on Google Chrome. To trigger tests, modify and save any src file.
Build and publishing
npm run build
npm run build-docs // generates JSDoc documentation to /docs dir
npm publish //script automatically builds before publish