add some augmented functions
This commit is contained in:
parent
d5ded3615f
commit
45dc0f0f11
@ -1,4 +1,4 @@
|
|||||||
@use "../../../assets/styles/common-mixins";
|
@use '../../../assets/styles/common-mixins';
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import { UntypedFormGroup } from '@angular/forms';
|
|||||||
import { forOwn, has, isEqual, isPlainObject, transform } from 'lodash-es';
|
import { forOwn, has, isEqual, isPlainObject, transform } from 'lodash-es';
|
||||||
import dayjs, { Dayjs } from 'dayjs';
|
import dayjs, { Dayjs } from 'dayjs';
|
||||||
|
|
||||||
export function capitalize(value: string): string {
|
export function capitalize(value: string | String): string {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
@ -20,7 +20,7 @@ export function humanize(value: string, lowercase = true): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function _log(value: unknown, message = '') {
|
export function _log(value: unknown, message = '') {
|
||||||
console.log(`%c[${dayjs().format('HH:mm:ss.SSS')}] ${message}`, 'color: yellow;', value);
|
console.log(`%c[${dayjs().format('mm:ss.SSS')}] ${message}`, 'color: yellow;', value);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toNumber(str: string): number {
|
export function toNumber(str: string): number {
|
||||||
@ -130,3 +130,38 @@ export function bool(value: unknown): boolean {
|
|||||||
|
|
||||||
return Boolean(_value);
|
return Boolean(_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface String {
|
||||||
|
capitalize(): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Array<T> {
|
||||||
|
/**
|
||||||
|
* Returns a new array with all falsy values removed.
|
||||||
|
* The values false, null, 0, "", undefined, and NaN are considered falsy.
|
||||||
|
* @param and - Additional function that is called for each truthy element in the array.
|
||||||
|
* The value returned from the function determines whether the element is kept or removed.
|
||||||
|
*/
|
||||||
|
filterTruthy(and?: (value: T) => boolean): T[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Console {
|
||||||
|
/**
|
||||||
|
* Logs a beautifully formatted message to the console.
|
||||||
|
* @param value - The object to log.
|
||||||
|
* @param message - Additional message.
|
||||||
|
*/
|
||||||
|
write(value: unknown, message?: string): void;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.write = _log;
|
||||||
|
|
||||||
|
String.prototype.capitalize = function _capitalize(this: string): string {
|
||||||
|
return capitalize(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
Array.prototype.filterTruthy = function <T>(this: T[], predicate: (value: T) => boolean = () => true): T[] {
|
||||||
|
return this.filter(value => !!value && predicate(value));
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user