@sellout/utils 0.0.383 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/CSV.ts → CSV.ts} +1 -1
- package/{src/GoogleTimezoneAPI.ts → GoogleTimezoneAPI.ts} +1 -1
- package/{src/IPStack.ts → IPStack.ts} +1 -2
- package/MongoConnectionManager.ts +49 -0
- package/package.json +4 -17
- package/price.ts +5 -0
- package/query.ts +31 -0
- package/time.ts +33 -0
- package/wait.ts +5 -0
- package/.dist/CSV.d.ts +0 -1
- package/.dist/CSV.js +0 -24
- package/.dist/CSV.js.map +0 -1
- package/.dist/ClientTrackingUtil.d.ts +0 -9
- package/.dist/ClientTrackingUtil.js +0 -37
- package/.dist/ClientTrackingUtil.js.map +0 -1
- package/.dist/FacebookUtil.d.ts +0 -8
- package/.dist/FacebookUtil.js +0 -77
- package/.dist/FacebookUtil.js.map +0 -1
- package/.dist/GoogleTimezoneAPI.d.ts +0 -1
- package/.dist/GoogleTimezoneAPI.js +0 -27
- package/.dist/GoogleTimezoneAPI.js.map +0 -1
- package/.dist/GoogleUtil.d.ts +0 -8
- package/.dist/GoogleUtil.js +0 -91
- package/.dist/GoogleUtil.js.map +0 -1
- package/.dist/IPStack.d.ts +0 -1
- package/.dist/IPStack.js +0 -36
- package/.dist/IPStack.js.map +0 -1
- package/.dist/ImageUtil.d.ts +0 -15
- package/.dist/ImageUtil.js +0 -26
- package/.dist/ImageUtil.js.map +0 -1
- package/.dist/ReduxUtil.d.ts +0 -1
- package/.dist/ReduxUtil.js +0 -11
- package/.dist/ReduxUtil.js.map +0 -1
- package/.dist/UrlUtil.d.ts +0 -4
- package/.dist/UrlUtil.js +0 -33
- package/.dist/UrlUtil.js.map +0 -1
- package/.dist/env.d.ts +0 -5
- package/.dist/env.js +0 -9
- package/.dist/env.js.map +0 -1
- package/.dist/formatPhoneNumber.d.ts +0 -1
- package/.dist/formatPhoneNumber.js +0 -23
- package/.dist/formatPhoneNumber.js.map +0 -1
- package/.dist/percentage.d.ts +0 -1
- package/.dist/percentage.js +0 -23
- package/.dist/percentage.js.map +0 -1
- package/.dist/price.d.ts +0 -3
- package/.dist/price.js +0 -58
- package/.dist/price.js.map +0 -1
- package/.dist/random.d.ts +0 -1
- package/.dist/random.js +0 -8
- package/.dist/random.js.map +0 -1
- package/.dist/time.d.ts +0 -38
- package/.dist/time.js +0 -175
- package/.dist/time.js.map +0 -1
- package/.dist/url.d.ts +0 -4
- package/.dist/url.js +0 -65
- package/.dist/url.js.map +0 -1
- package/.dist/wait.d.ts +0 -2
- package/.dist/wait.js +0 -40
- package/.dist/wait.js.map +0 -1
- package/src/ClientTrackingUtil.ts +0 -44
- package/src/FacebookUtil.ts +0 -63
- package/src/GoogleUtil.ts +0 -81
- package/src/ImageUtil.ts +0 -27
- package/src/ReduxUtil.ts +0 -9
- package/src/UrlUtil.ts +0 -38
- package/src/env.ts +0 -5
- package/src/percentage.ts +0 -21
- package/src/price.ts +0 -64
- package/src/time.ts +0 -168
- package/src/url.ts +0 -73
- package/src/wait.ts +0 -24
- package/tsconfig.json +0 -27
- package/tslint.json +0 -21
- /package/{src/formatPhoneNumber.ts → formatPhoneNumber.ts} +0 -0
- /package/{src/random.ts → random.ts} +0 -0
package/src/FacebookUtil.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as Wait from './wait';
|
|
2
|
-
|
|
3
|
-
const SELLOUT_FACEBOOK_PIXEL_ID = '205397967210775';
|
|
4
|
-
|
|
5
|
-
async function waitForPixel() {
|
|
6
|
-
return await Wait.forTrue(() => Boolean((window as any).fbq));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/****************************************************************************************
|
|
10
|
-
Initialization
|
|
11
|
-
****************************************************************************************/
|
|
12
|
-
|
|
13
|
-
export function initialize(facebookPixelId?: string | null): void {
|
|
14
|
-
try {
|
|
15
|
-
injectPixel(SELLOUT_FACEBOOK_PIXEL_ID);
|
|
16
|
-
if (facebookPixelId) {
|
|
17
|
-
injectPixel(facebookPixelId);
|
|
18
|
-
} else {
|
|
19
|
-
console.log('Facebook Pixel not configured');
|
|
20
|
-
}
|
|
21
|
-
} catch (e) {
|
|
22
|
-
console.error('Failed to inject Facebook Pixel');
|
|
23
|
-
console.error(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function injectPixel(facebookPixelId: string): void {
|
|
28
|
-
const headCode = `
|
|
29
|
-
< !--Facebook Pixel Code-- >
|
|
30
|
-
<script>
|
|
31
|
-
!function(f,b,e,v,n,t,s)
|
|
32
|
-
{if(f.fbq)return;n=f.fbq=function(){n.callMethod ?
|
|
33
|
-
n.callMethod.apply(n, arguments) : n.queue.push(arguments)};
|
|
34
|
-
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
|
|
35
|
-
n.queue=[];t=b.createElement(e);t.async=!0;
|
|
36
|
-
t.src=v;s=b.getElementsByTagName(e)[0];
|
|
37
|
-
s.parentNode.insertBefore(t,s)}(window, document,'script',
|
|
38
|
-
'https://connect.facebook.net/en_US/fbevents.js');
|
|
39
|
-
fbq('init', '${facebookPixelId}');
|
|
40
|
-
fbq('track', 'PageView');
|
|
41
|
-
</script>
|
|
42
|
-
<noscript><img height="1" width="1" style="display:none"
|
|
43
|
-
src="https://www.facebook.com/tr?id=${facebookPixelId}&ev=PageView&noscript=1"
|
|
44
|
-
/></noscript>
|
|
45
|
-
<!--End Facebook Pixel Code-- >
|
|
46
|
-
`;
|
|
47
|
-
|
|
48
|
-
const headScript = document.createRange().createContextualFragment(headCode);
|
|
49
|
-
document.head.prepend(headScript);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/****************************************************************************************
|
|
53
|
-
Tracking
|
|
54
|
-
****************************************************************************************/
|
|
55
|
-
|
|
56
|
-
export async function track(type: string, action: string, params: object): Promise<void> {
|
|
57
|
-
try {
|
|
58
|
-
await waitForPixel();
|
|
59
|
-
(window as any).fbq(type, action, params);
|
|
60
|
-
} catch (e) {
|
|
61
|
-
console.error('Facebook Pixel failed to track event');
|
|
62
|
-
}
|
|
63
|
-
}
|
package/src/GoogleUtil.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as Wait from './wait';
|
|
2
|
-
import {SELLOUT_GOOGLE_TAG_ID} from './env';
|
|
3
|
-
|
|
4
|
-
const SELLOUT_GOOGLE_ANALYTICS_ID = 'UA-112750612-5';
|
|
5
|
-
|
|
6
|
-
async function waitForGTag() {
|
|
7
|
-
return await Wait.forTrue(() => Boolean((window as any).gtag));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/****************************************************************************************
|
|
11
|
-
Initialization
|
|
12
|
-
****************************************************************************************/
|
|
13
|
-
|
|
14
|
-
export function initialize(googleAnalyticsId?: string | null): void {
|
|
15
|
-
try {
|
|
16
|
-
injectGoogleAnalytics(SELLOUT_GOOGLE_ANALYTICS_ID);
|
|
17
|
-
injectGoogleTagManager(SELLOUT_GOOGLE_TAG_ID);
|
|
18
|
-
if (googleAnalyticsId) {
|
|
19
|
-
injectGoogleAnalytics(googleAnalyticsId);
|
|
20
|
-
} else {
|
|
21
|
-
console.log('Google Analytics not configured');
|
|
22
|
-
}
|
|
23
|
-
} catch (e) {
|
|
24
|
-
console.error('Failed to inject Google Analaytics');
|
|
25
|
-
console.error(e);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function injectGoogleAnalytics(googleAnalyticsId: string): void {
|
|
30
|
-
const headCode = `
|
|
31
|
-
< !--Global site tag(gtag.js) - Google Analytics-- >
|
|
32
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=${googleAnalyticsId}"></script>
|
|
33
|
-
<script>
|
|
34
|
-
window.dataLayer = window.dataLayer || [];
|
|
35
|
-
function gtag(){dataLayer.push(arguments);}
|
|
36
|
-
gtag('js', new Date());
|
|
37
|
-
gtag('config', '${googleAnalyticsId}');
|
|
38
|
-
</script>
|
|
39
|
-
`;
|
|
40
|
-
|
|
41
|
-
const headScript = document.createRange().createContextualFragment(headCode);
|
|
42
|
-
document.head.prepend(headScript);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function injectGoogleTagManager(googleTagManagerAccountId: string): void {
|
|
46
|
-
const headCode = `
|
|
47
|
-
<!-- Google Tag Manager -->
|
|
48
|
-
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
|
|
49
|
-
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
|
|
50
|
-
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
|
|
51
|
-
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
|
|
52
|
-
})(window,document,'script','dataLayer','${googleTagManagerAccountId}');</script>
|
|
53
|
-
<!-- End Google Tag Manager -->
|
|
54
|
-
`;
|
|
55
|
-
|
|
56
|
-
const headScript = document.createRange().createContextualFragment(headCode);
|
|
57
|
-
document.head.prepend(headScript);
|
|
58
|
-
|
|
59
|
-
const bodyCode = `
|
|
60
|
-
<!-- Google Tag Manager (noscript) -->
|
|
61
|
-
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=${googleTagManagerAccountId}"
|
|
62
|
-
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
|
63
|
-
<!-- End Google Tag Manager (noscript) -->
|
|
64
|
-
`;
|
|
65
|
-
|
|
66
|
-
const bodyScript = document.createRange().createContextualFragment(bodyCode);
|
|
67
|
-
document.body.prepend(bodyScript);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/****************************************************************************************
|
|
71
|
-
Tracking
|
|
72
|
-
****************************************************************************************/
|
|
73
|
-
|
|
74
|
-
export async function track(type: string, action: string, params: object): Promise<void> {
|
|
75
|
-
try {
|
|
76
|
-
await waitForGTag();
|
|
77
|
-
(window as any).gtag(type, action, params);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
console.error('Google Analytics failed to track event');
|
|
80
|
-
}
|
|
81
|
-
}
|
package/src/ImageUtil.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export enum ImageSize {
|
|
2
|
-
Small = 'small',
|
|
3
|
-
Medium = 'medium',
|
|
4
|
-
Original = 'original'
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const getImageUrl = (
|
|
8
|
-
posterImageUrl: string | { original: string; medium: string; small: string } | undefined,
|
|
9
|
-
size: ImageSize = ImageSize.Original
|
|
10
|
-
): string => {
|
|
11
|
-
if (!posterImageUrl) return '';
|
|
12
|
-
|
|
13
|
-
// Backward compatibility - if it's a string, return it
|
|
14
|
-
if (typeof posterImageUrl === 'string') {
|
|
15
|
-
return posterImageUrl;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// New object structure - return requested size
|
|
19
|
-
return posterImageUrl[size] || posterImageUrl.original || '';
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Helper function for direct usage safety
|
|
23
|
-
export const getPosterImageUrl = (
|
|
24
|
-
posterImageUrl: string | { original: string; medium: string; small: string } | undefined
|
|
25
|
-
): string => {
|
|
26
|
-
return getImageUrl(posterImageUrl, ImageSize.Original);
|
|
27
|
-
};
|
package/src/ReduxUtil.ts
DELETED
package/src/UrlUtil.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as url from 'url';
|
|
2
|
-
|
|
3
|
-
export function parse(inputUrl: string) {
|
|
4
|
-
return url.parse(inputUrl, true)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function setQueryString(paramObj: any, replaceState = false, clearExisting = false) {
|
|
8
|
-
const { query } = url.parse(window.location.href, true);
|
|
9
|
-
|
|
10
|
-
let newParams = {
|
|
11
|
-
...query,
|
|
12
|
-
...paramObj,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
if (clearExisting) {
|
|
16
|
-
newParams = {
|
|
17
|
-
...paramObj,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let queryString = Object.keys(newParams)
|
|
22
|
-
.map((key) => {
|
|
23
|
-
return (newParams[key]) ? `${key}=${newParams[key]}` : null;
|
|
24
|
-
})
|
|
25
|
-
.filter(item => !!item)
|
|
26
|
-
.join('&');
|
|
27
|
-
|
|
28
|
-
if(queryString) queryString = '?' + queryString;
|
|
29
|
-
|
|
30
|
-
const newUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}${queryString}`;
|
|
31
|
-
|
|
32
|
-
if (replaceState && window.history.replaceState) {
|
|
33
|
-
window.history.replaceState({ path: newUrl }, '', newUrl);
|
|
34
|
-
} else if (window.history.pushState) {
|
|
35
|
-
window.history.pushState({ path: newUrl }, '', newUrl);
|
|
36
|
-
}
|
|
37
|
-
return newUrl;
|
|
38
|
-
}
|
package/src/env.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export const GOOGLE_TIMEZONE_API_KEY = process.env.GOOGLE_TIMEZONE_API_KEY;
|
|
2
|
-
export const LOAD_TEST_ENABLED = process.env.LOAD_TEST_ENABLED === '1';
|
|
3
|
-
export const IP_STACK_API_KEY = process.env.IP_STACK_API_KEY;
|
|
4
|
-
export const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
5
|
-
export const SELLOUT_GOOGLE_TAG_ID = process.env.SELLOUT_GOOGLE_TAG_ID || 'GTM-PZZ88FWL'
|
package/src/percentage.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const lastChar = string => string.toString().charAt(string.length - 1);
|
|
2
|
-
|
|
3
|
-
export function input(percentage) {
|
|
4
|
-
percentage = percentage.toString().replace(/\s/g, '');
|
|
5
|
-
|
|
6
|
-
if (!percentage) percentage = 0;
|
|
7
|
-
|
|
8
|
-
if (Number.isNaN(percentage)) return 0;
|
|
9
|
-
|
|
10
|
-
if (percentage.toString().length > 1 && percentage.toString().charAt(0) === '0') {
|
|
11
|
-
const value = parseFloat(percentage.substring(1));
|
|
12
|
-
if (Number.isNaN(value)) return 0;
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (lastChar(percentage) === '.') {
|
|
17
|
-
return percentage;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return parseFloat(percentage);
|
|
21
|
-
}
|
package/src/price.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// I know this sucks, I'm sorry. You can re-write it, but
|
|
2
|
-
// make sure you test it thoroughly.
|
|
3
|
-
export const input = (price: any) => {
|
|
4
|
-
price = price.replace(/[^0-9.]/g, '');
|
|
5
|
-
|
|
6
|
-
if (price.indexOf('.') > -1) {
|
|
7
|
-
let [first, second] = price.toString().split('.');
|
|
8
|
-
|
|
9
|
-
second = second.replace(/[^0-9]/g, '');
|
|
10
|
-
|
|
11
|
-
price = `${first}.${second}`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (price.toString().split('')[price.length - 1] === '.') {
|
|
15
|
-
return price;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (Number.isNaN(price) || Number.isNaN(parseFloat(price))) return 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return Math.round(parseFloat(price) * 100);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// export const output = (price: any, withFixed = false) => {
|
|
25
|
-
// if (price && price.toString().split('')[price.length - 1] === '.') {
|
|
26
|
-
// return (price / 100).toLocaleString("en-US");
|
|
27
|
-
// }
|
|
28
|
-
|
|
29
|
-
// if (withFixed) {
|
|
30
|
-
// price /= 100;
|
|
31
|
-
// return price.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,').toLocaleString("en-US");
|
|
32
|
-
// }
|
|
33
|
-
|
|
34
|
-
// return price;
|
|
35
|
-
// };
|
|
36
|
-
|
|
37
|
-
export const output = (price, withFixed = false, currencyFormat = false) => {
|
|
38
|
-
if (price && price.toString().split("")[price.length - 1] === ".") {
|
|
39
|
-
// price = price.replace(".", "");
|
|
40
|
-
return price
|
|
41
|
-
}
|
|
42
|
-
price /= 100;
|
|
43
|
-
if (withFixed) {
|
|
44
|
-
if (currencyFormat) {
|
|
45
|
-
return price
|
|
46
|
-
.toFixed(2)
|
|
47
|
-
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,").toLocaleString("en-US")
|
|
48
|
-
}
|
|
49
|
-
return price
|
|
50
|
-
.toFixed(2)
|
|
51
|
-
.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return currencyFormat ? price.toLocaleString("en-US") : price;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const format = (price: string) => {
|
|
58
|
-
const value = parseFloat(price.replace(/,/g, ''))
|
|
59
|
-
.toFixed(2)
|
|
60
|
-
.toString()
|
|
61
|
-
.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
62
|
-
|
|
63
|
-
return parseFloat(value).toFixed(2);
|
|
64
|
-
};
|
package/src/time.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import * as moment from 'moment-timezone';
|
|
2
|
-
|
|
3
|
-
export const SECOND = 1;
|
|
4
|
-
export const MINUTE = 60 * SECOND;
|
|
5
|
-
export const HOUR = 60 * MINUTE;
|
|
6
|
-
export const DAY = 24 * HOUR;
|
|
7
|
-
|
|
8
|
-
// export const MILLISECONDS = {
|
|
9
|
-
// SECOND: 1000,
|
|
10
|
-
// MINUTE: this.SECOND * 60,
|
|
11
|
-
// HOUR: this.MINUTE * 60,
|
|
12
|
-
// DAY: this.HOUR * 24,
|
|
13
|
-
// };
|
|
14
|
-
export const MILLISECONDS = {
|
|
15
|
-
SECOND: 1000,
|
|
16
|
-
MINUTE: SECOND * 60,
|
|
17
|
-
HOUR: MINUTE * 60,
|
|
18
|
-
DAY: HOUR * 24,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export function now(): number {
|
|
22
|
-
return moment().unix();
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export function fromNow(seconds): number {
|
|
26
|
-
return now() + seconds;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function fromStartOfDay(seconds: number): number {
|
|
30
|
-
const startOfDay = moment().startOf("day").unix();
|
|
31
|
-
return Math.floor(startOfDay + seconds);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const date = function (seconds?: number): Date {
|
|
35
|
-
if (!seconds) return new Date();
|
|
36
|
-
const millis = seconds * 1000;
|
|
37
|
-
return new Date(millis);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const fromDate = function (millis: number | string): number {
|
|
41
|
-
return Math.floor(new Date(millis).getTime() / 1000);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// Use this one, it's better
|
|
46
|
-
export const format = function (secondsSinceEpoch, format = 'M/DD/YYYY h:mma', timezone: string = 'America/Denver') {
|
|
47
|
-
if (!timezone) timezone = 'America/Denver';
|
|
48
|
-
const millis = date(secondsSinceEpoch);
|
|
49
|
-
return moment(millis).tz(timezone).format(format);
|
|
50
|
-
}
|
|
51
|
-
export const formatToUTC = function (secondsSinceEpoch, format = 'M/DD/YYYY h:mma') {
|
|
52
|
-
const millis = date(secondsSinceEpoch);
|
|
53
|
-
return moment.utc(millis).format(format);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const formatTimeOfDay = function (secondsSinceEpoch, timezone?: string) {
|
|
57
|
-
return format(secondsSinceEpoch, 'h:mma', timezone);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const formattedCountDown = (startTime: number, endTime: number): string => {
|
|
61
|
-
const totalSeconds = endTime - startTime;
|
|
62
|
-
const days = Math.floor(totalSeconds / 86400);
|
|
63
|
-
const hours = Math.floor((totalSeconds % 86400) / 3600);
|
|
64
|
-
const minutes = Math.floor(((totalSeconds % 86400) % 3600) / 60);
|
|
65
|
-
const seconds = Math.floor((((totalSeconds % 86400) % 3600) % 60));
|
|
66
|
-
|
|
67
|
-
if (days === 0) return `${hours}h ${minutes}m ${seconds}s`;
|
|
68
|
-
if (hours === 0 && days === 0) return `${minutes}m ${seconds}s`;
|
|
69
|
-
if (minutes === 0 && hours === 0 && days === 0) return `${seconds}s`;
|
|
70
|
-
return `${days}d ${hours}h ${minutes}m ${seconds}s`;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const getStartOfHour = (seconds: number) => {
|
|
74
|
-
return moment(seconds * 1000).startOf("hour").unix();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const getStartOfDay = (seconds: number) => {
|
|
78
|
-
return moment(seconds * 1000).startOf("day").unix();
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const getStartOfWeek = (seconds: number) => {
|
|
82
|
-
return moment(seconds * 1000).startOf("week").unix();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const getStartOfMonth = (seconds: number) => {
|
|
86
|
-
return moment(seconds * 1000).startOf("month").unix();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const getStartOfYear = (seconds: number) => {
|
|
90
|
-
return moment(seconds * 1000).startOf("year").unix();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
export const getStartOfCurrentDay = () => {
|
|
95
|
-
return moment().startOf("day").unix();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export const getStartOfCurrentMonth = () => {
|
|
99
|
-
return moment().startOf("month").unix();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const getStartOfCurrentYear = () => {
|
|
103
|
-
return moment().startOf("year").unix();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const getEndOfCurrentDay = () => {
|
|
107
|
-
return moment().endOf("day").unix();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const getEndOfCurrentMonth = () => {
|
|
111
|
-
return moment().endOf("month").unix();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export const getEndOfCurrentYear = () => {
|
|
115
|
-
return moment().endOf("year").unix();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export const getTimezoneMindifference = (timezone = 'America/Denver') => {
|
|
119
|
-
var now = moment();
|
|
120
|
-
var localOffset = now.utcOffset();
|
|
121
|
-
now.tz(timezone);
|
|
122
|
-
var centralOffset = now.utcOffset();
|
|
123
|
-
return localOffset - centralOffset;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export const changeTimeZone = (date, timezone) => {
|
|
127
|
-
if (!timezone) {
|
|
128
|
-
timezone = getLocalTz()
|
|
129
|
-
}
|
|
130
|
-
return moment(date).tz(timezone, true).unix()
|
|
131
|
-
};
|
|
132
|
-
export const changeTimeZoneWithDate = (date: number | undefined, timezone) => {
|
|
133
|
-
if (!timezone) {
|
|
134
|
-
timezone = getLocalTz()
|
|
135
|
-
}
|
|
136
|
-
return moment(date).tz(timezone).unix()
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
export const formatWithoutTz = (millis, format = "YYYY-MM-DD HH:mm:ss a") => {
|
|
140
|
-
return moment(millis).format(format);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
export const formatWithTz = (millis, timezone, format = "MM/DD/YYYY hh:mm A") => {
|
|
144
|
-
if (!timezone) {
|
|
145
|
-
timezone = getLocalTz()
|
|
146
|
-
}
|
|
147
|
-
return moment(millis).tz(timezone).format(format);
|
|
148
|
-
}
|
|
149
|
-
// export const formatWithTz = (millis, timezone, format = "YYYY-MM-DD hh:mm:ss a") => {
|
|
150
|
-
// if (!timezone) {
|
|
151
|
-
// timezone = getLocalTz()
|
|
152
|
-
// }
|
|
153
|
-
// return moment(millis).tz(timezone).format(format);
|
|
154
|
-
// }
|
|
155
|
-
|
|
156
|
-
export const getLocalTz = () => {
|
|
157
|
-
return moment.tz.guess();
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export const convertToDate = (millis) => {
|
|
161
|
-
return moment(millis * 1000).toDate();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export const convertToLocal = (timestamp, timezone) => {
|
|
165
|
-
const formatConverted = timestamp && formatWithTz(timestamp * 1000, timezone)
|
|
166
|
-
const changedTzToActual = formatConverted && changeTimeZone(formatConverted, getLocalTz())
|
|
167
|
-
return changedTzToActual
|
|
168
|
-
}
|
package/src/url.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
export function parseUrl(url: string): any {
|
|
2
|
-
const parse_url = /^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/;
|
|
3
|
-
const result: string[] = parse_url.exec(url) as string[];
|
|
4
|
-
return {
|
|
5
|
-
url: result[0],
|
|
6
|
-
scheme: result[1],
|
|
7
|
-
slash: result[2],
|
|
8
|
-
host: result[3],
|
|
9
|
-
port: result[4],
|
|
10
|
-
path: result[5],
|
|
11
|
-
query: result[6],
|
|
12
|
-
hash: result[7],
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function parseQueryString(url: string = window.location.href) {
|
|
17
|
-
const currentQuery = parseUrl(url).query;
|
|
18
|
-
|
|
19
|
-
if (!currentQuery) {
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return currentQuery.split('&')
|
|
24
|
-
.reduce((cur, next) => {
|
|
25
|
-
const keyAndValue = next.split('=');
|
|
26
|
-
cur[keyAndValue[0]] = keyAndValue[1];
|
|
27
|
-
return cur;
|
|
28
|
-
}, {});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function setQueryString(paramObj, urlToParse, replaceState = false, clearExisting = false): string {
|
|
32
|
-
const workingUrl = (urlToParse) || window.location;
|
|
33
|
-
const currentParams = parseQueryString(workingUrl);
|
|
34
|
-
|
|
35
|
-
let newParams = {
|
|
36
|
-
...currentParams,
|
|
37
|
-
...paramObj,
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
if (clearExisting) {
|
|
41
|
-
newParams = {
|
|
42
|
-
...paramObj,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const queryString = Object.keys(newParams)
|
|
47
|
-
.map((key) => {
|
|
48
|
-
return (newParams[key]) ? `${key}=${newParams[key]}` : null;
|
|
49
|
-
})
|
|
50
|
-
.filter((item) => !!item)
|
|
51
|
-
.join('&');
|
|
52
|
-
|
|
53
|
-
const newUrl = `${window.location.protocol}//${window.location.host}${window.location.pathname}?${queryString}`;
|
|
54
|
-
|
|
55
|
-
if (replaceState && window.history.replaceState) {
|
|
56
|
-
window.history.replaceState({ path: newUrl }, '', newUrl);
|
|
57
|
-
} else if (window.history.pushState) {
|
|
58
|
-
window.history.pushState({ path: newUrl }, '', newUrl);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return newUrl;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
export function serializeUrlParams(object: any): string {
|
|
66
|
-
const holder: string[] = [];
|
|
67
|
-
for (const key in object) {
|
|
68
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
69
|
-
holder.push((`${encodeURIComponent(key)}=${encodeURIComponent(object[key])}`));
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return holder.join('&');
|
|
73
|
-
}
|
package/src/wait.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export default function wait(timeoutMs: number, value: any = null): Promise<any> {
|
|
2
|
-
return new Promise<any>((resolve) => {
|
|
3
|
-
setTimeout(() => resolve(value), timeoutMs);
|
|
4
|
-
});
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export async function forTrue(fn: () => boolean) {
|
|
8
|
-
const count = 0;
|
|
9
|
-
return new Promise<any>((resolve, reject) => {
|
|
10
|
-
if(fn()) {
|
|
11
|
-
resolve(true);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const interval = setInterval(async () => {
|
|
16
|
-
if (fn()) {
|
|
17
|
-
clearInterval(interval);
|
|
18
|
-
resolve(true);
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
if (count >= 100) reject();
|
|
22
|
-
}, 50);
|
|
23
|
-
});
|
|
24
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compileOnSave": true,
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": ".",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"target": "es6",
|
|
7
|
-
"module": "commonjs",
|
|
8
|
-
"outDir": "./.dist/",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"sourceMap": true,
|
|
11
|
-
"strictNullChecks": true,
|
|
12
|
-
"noUnusedLocals": true,
|
|
13
|
-
"paths": {},
|
|
14
|
-
"types": [
|
|
15
|
-
"node",
|
|
16
|
-
]
|
|
17
|
-
},
|
|
18
|
-
"typeRoots": [
|
|
19
|
-
"node_modules/@types"
|
|
20
|
-
],
|
|
21
|
-
"include": [
|
|
22
|
-
"./src/**/*.ts"
|
|
23
|
-
],
|
|
24
|
-
"exclude": [
|
|
25
|
-
"node_modules"
|
|
26
|
-
]
|
|
27
|
-
}
|
package/tslint.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "tslint-config-airbnb",
|
|
3
|
-
"rules": {
|
|
4
|
-
"max-line-length": {
|
|
5
|
-
"options": [120]
|
|
6
|
-
},
|
|
7
|
-
"no-console": false,
|
|
8
|
-
"ban": [
|
|
9
|
-
true,
|
|
10
|
-
{
|
|
11
|
-
"name": ["Math", "random"],
|
|
12
|
-
"message": "Use a better RNG, perhaps UUID?"
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
"jsRules": {
|
|
17
|
-
"max-line-length": {
|
|
18
|
-
"options": [120]
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
File without changes
|
|
File without changes
|