import { tap } from 'rxjs/operators'; import { ITrackable } from '../listing/models/trackable'; import { MonoTypeOperatorFunction } from 'rxjs'; import moment from 'moment'; export function capitalize(value: string): string { if (!value) { return ''; } return value.charAt(0).toUpperCase() + value.slice(1); } export function humanize(value: string, lowercase = true): string { if (!value) { return ''; } const words = (lowercase ? value.toLowerCase() : value).split(/[ \-_]+/); return words.map(capitalize).join(' '); } export function log(): MonoTypeOperatorFunction { return tap(res => console.log(`%c[${moment().format('HH:mm:ss.SSS')}]`, 'color: yellow;', res)); } export function toNumber(str: string): number { try { return parseInt(`${str}`.replace(/\D/g, ''), 10); } catch (e) { return 0; } } export function trackByFactory() { return (index: number, item: T): string => item.id; }