Compare commits

..
4 Commits
3 changed files with 120 additions and 33 deletions
@@ -156,6 +156,20 @@ export enum XResourceIDs {
//
submit,
//
print,
export_png,
export_svg,
export_csv,
zoom_in,
zoom_out,
zoom_selection,
x_axis,
y_axis,
xy_axis,
pan,
full_screen,
//
//#region Pagination ...
first,
@@ -104,8 +104,8 @@ export function parseXColor(color: XColorIdentifier): XColorDescribtor {
const brightnessLevel: XColorBrightnessLevel = strColor.includes('tint')
? XColorBrightnessLevel.Tint
: strColor.includes('shade')
? XColorBrightnessLevel.Shade
: XColorBrightnessLevel.Regular;
? XColorBrightnessLevel.Shade
: XColorBrightnessLevel.Regular;
const name = strColor
.replace('-', '')
.replace('contrast', '')
@@ -409,8 +409,8 @@ export function stringToRGBA(value: string): XRGBAColor {
value = value.includes('rgba')
? value.replace('rgba', '')
: value.includes('rgb')
? value.replace('rgb', '')
: value;
? value.replace('rgb', '')
: value;
//
// Replace paranteses ...
@@ -890,14 +890,14 @@ export function stringToHsva(colorString: string = ''): XHSVAColor {
const type = isHEX(colorString)
? 'hex'
: isRGBA(colorString)
? 'rgba'
: isRGB(colorString)
? 'rgb'
: isHSVA(colorString)
? 'hsva'
: isHSLA(colorString)
? 'hsla'
: 'unknown';
? 'rgba'
: isRGB(colorString)
? 'rgb'
: isHSVA(colorString)
? 'hsva'
: isHSLA(colorString)
? 'hsla'
: 'unknown';
//
// get result value based on input type ...
@@ -1179,3 +1179,37 @@ export function formatColor(
}
}
}
/**
* Retrieve Specified Color Identifier Value ...
*
* @param color Color Identifier ...
*
* @returns an string value which represent color ...
*/
export function getXColorValue(color: XColorIdentifier) {
//
let result = '';
//
if (!isNullOrUndefined(color)) {
//
const descriptor = parseXColor(color);
if (!isNullOrUndefined(descriptor)) {
//
var colorCssVarName = getXColorCssVariableName(
descriptor.name,
descriptor.isContrast,
descriptor.brightnessLevel,
);
if (!isNullOrEmptyString(colorCssVarName)) {
//
const computedStyle = getComputedStyle(document.documentElement);
result = computedStyle.getPropertyValue(colorCssVarName.trim()).trim();
}
}
}
//
return result;
}
@@ -16,6 +16,7 @@ import {
import { Type } from '@angular/core';
import { isSameDate } from './x-date-time.tools';
import { countChild, hasChild, lastItem, onlyUniques } from './x-array.tools';
import { toXString } from './x-type-convert.tools';
//
//#region Object Tools ...
@@ -260,7 +261,7 @@ export function mergeAll<T>(
*/
export function toPartialObject<T>(
source: T,
modelKeys: Array<Partial<keyof T>>
modelKeys: Array<Partial<keyof T>>,
) {
//
if (!source || !hasChild(modelKeys)) {
@@ -313,7 +314,7 @@ export function getFieldNames<T>(object: T): XModelFieldTypeIndex<T> {
{},
...(Object.keys(object).map((k) => {
return assign({}, { key: k, value: k });
}) as XModelFieldTypeIndex<T>[])
}) as XModelFieldTypeIndex<T>[]),
);
}
@@ -366,7 +367,7 @@ export function setPropertyValue<T>(
object: T,
propertyPath: string,
value?: any,
forceCreate?: boolean
forceCreate?: boolean,
) {
//
if (!object || isNullOrEmptyString(propertyPath)) {
@@ -410,7 +411,7 @@ export function getPropertyPaths<T = any>(
object: T,
prefix?: string,
extractSchema: boolean = false,
containsChildsObjectHeaders: boolean = false
containsChildsObjectHeaders: boolean = false,
) {
//
// Create empty result Array ...
@@ -483,7 +484,7 @@ export function getPropertyPaths<T = any>(
(value as any[])[0],
`${keyPath}.0`,
extractSchema,
containsChildsObjectHeaders
containsChildsObjectHeaders,
)
: //
// for Object Values retrieve all including keys ...
@@ -491,7 +492,7 @@ export function getPropertyPaths<T = any>(
value,
keyPath,
extractSchema,
containsChildsObjectHeaders
containsChildsObjectHeaders,
);
} else {
//
@@ -501,7 +502,7 @@ export function getPropertyPaths<T = any>(
value,
keyPath,
extractSchema,
containsChildsObjectHeaders
containsChildsObjectHeaders,
);
}
@@ -544,7 +545,7 @@ export function getSchemaPaths<T = any>(object: T) {
export function generateObjectFromPaths<T = any>(
paths: string[],
assginPropertyName: boolean = false,
defaultValue: any = null
defaultValue: any = null,
): XDeep<T> {
//
// Check paths contains childs ...
@@ -605,7 +606,7 @@ export function generateObjectFromPaths<T = any>(
export function generatePartialObjectFromPaths<T = any>(
paths: string[],
assginPropertyName: boolean = false,
defaultValue: any = null
defaultValue: any = null,
): XDeepPartial<T> {
//
// Check paths contains childs ...
@@ -665,7 +666,7 @@ export function generatePartialObjectFromPaths<T = any>(
*/
export function getSchema<T = any>(
object: T,
defaultValue: any = null
defaultValue: any = null,
): XDeep<T> {
//
const paths = getSchemaPaths(object);
@@ -684,7 +685,7 @@ export function getSchema<T = any>(
*/
export function getPartialSchema<T = any>(
object: T,
defaultValue: any = null
defaultValue: any = null,
): XDeepPartial<T> {
//
const paths = getSchemaPaths(object);
@@ -773,10 +774,10 @@ export function isSameType(source: any, dest: any, forceMemberTypes = false) {
//
const isAllSourceKeyExistsInDestKeys = sourceKeys.every((k) =>
destKeys.includes(k)
destKeys.includes(k),
);
const isAllDestKeyExistsInSourceKeys = destKeys.every((k) =>
sourceKeys.includes(k)
sourceKeys.includes(k),
);
//
@@ -819,7 +820,7 @@ export function isSameType(source: any, dest: any, forceMemberTypes = false) {
export function isSameArray(
source: any[],
dest: any[],
forceCheckType?: boolean
forceCheckType?: boolean,
): boolean {
//
if (!source || !dest) {
@@ -877,7 +878,7 @@ export function isSameArray(
export function isSameObject(
source: object,
dest: object,
forceCheckType?: boolean
forceCheckType?: boolean,
): boolean {
//
if (!source || !dest) {
@@ -935,9 +936,7 @@ export function isSameObject(
*/
export function isOfType<T>(value: any, keys: (keyof T)[]): value is T {
return (
typeof value === "object" &&
value !== null &&
keys.every(k => k in value)
typeof value === 'object' && value !== null && keys.every((k) => k in value)
);
}
@@ -949,9 +948,9 @@ export function isOfType<T>(value: any, keys: (keyof T)[]): value is T {
*/
export function typeGuard<T>(keys: (keyof T)[]) {
return (value: any): value is T =>
typeof value === "object" &&
typeof value === 'object' &&
value !== null &&
keys.every(k => k in value);
keys.every((k) => k in value);
}
//#endregion
@@ -1004,6 +1003,46 @@ export function getVal(T: Object, value: number | string) {
export function toObject(T: Object) {
return Object.assign({}, T);
}
/**
* Generic Tools Function to Check A Value inside enum Values or not ...
*
* @param value
* @param values
* @param forceExact
*/
export function isValueInEnum<TValue>(
value: TValue,
values: Object,
forceExact: boolean = true,
) {
//
let result = false;
//
if (
!isNullOrUndefined(value) &&
!isNullOrUndefined(values) &&
!isNullOrEmptyString(toXString(value))
) {
//
const tVals = Object.values(values).map((tv) => tv as TValue);
//
result = tVals.includes(value);
//
// Check Includes ...
if (!forceExact && !result) {
//
result =
tVals.findIndex((t) => toXString(value).includes(toXString(t))) >= 0;
}
}
//
return result;
}
//#endregion
//
@@ -1037,7 +1076,7 @@ export function getComponentName<T>(component: Type<T>): string | null {
*/
export function isXKeyOf<T extends object>(
obj: T,
key: PropertyKey
key: PropertyKey,
): key is keyof T {
return key in obj;
}