UNPKG

@mate-academy/sourcebuster

Version:

Get sources of your site's visitors (utm / organic / referral / typein).

37 lines (27 loc) 1.13 kB
"use strict"; module.exports = { escapeRegexp: function(string) { return string.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); }, setDate: function(date, offset) { var utc_offset = date.getTimezoneOffset() / 60, now_hours = date.getHours(), custom_offset = offset || offset === 0 ? offset : -utc_offset; date.setHours(now_hours + utc_offset + custom_offset); var year = date.getFullYear(), month = this.setLeadingZeroToInt(date.getMonth() + 1, 2), day = this.setLeadingZeroToInt(date.getDate(), 2), hour = this.setLeadingZeroToInt(date.getHours(), 2), minute = this.setLeadingZeroToInt(date.getMinutes(), 2), second = this.setLeadingZeroToInt(date.getSeconds(), 2); return (year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second); }, setLeadingZeroToInt: function(num, size) { var s = num + ''; while (s.length < size) { s = '0' + s; } return s; }, randomInt: function(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } };