UNPKG

@alauda-fe/common

Version:

Alauda frontend team common codes.

67 lines (66 loc) 4.01 kB
/** * @packageDocumentation * @module utils */ import { Sort } from '@alauda/ui'; import { UnionToIntersection } from 'ts-essentials'; import { Terminal } from 'xterm'; import { Callback, Keys, KubernetesResource, Nullable, Readonlyable } from '../types/public-api'; /** * 保证任何语言环境下将数字转换为非科学计数法且不带千位分隔符并保留三位有效小数的数字字符串 * * @example * numToStr(123123.3456) // "123123.346" * numToStr(123.12) // "123.12" */ export declare const numToStr: (num?: number) => string; export declare const shortNum: (num?: number | string, digits?: number) => string; export declare const isBlank: (str?: unknown) => boolean; export declare const getBaseHref: () => string; export declare const ifExist: <T>(toCheck: boolean | Nullable<T>, truthyValue: T, fallback?: T) => T; export declare const isAbsoluteUrl: (url: string) => boolean; export declare const noop: Callback; export declare const toKeys: <T extends object>(source: T) => Keys<T>; export declare const wrapText: (text?: string, wrapper?: Readonlyable<[string, string]>, fallback?: string) => string; export declare function parseJSONStream<T>(text: string): T[]; export declare const trackByUid: <T extends KubernetesResource>(_: number, resource: T) => string; export declare const isK8sResource: <T extends KubernetesResource = KubernetesResource>(value: object) => value is T; export declare const arrayify: <T, R = T extends (infer S)[] ? NonNullable<S> : NonNullable<T>>(...args: Array<R | R[]>) => R[]; export declare function sleep(ms?: number): Promise<unknown>; export declare const delay: typeof sleep; export declare function scrollIntoView(container: HTMLElement, selected: HTMLElement): void; export declare const isEqual: <T, V = T>(a: T, b: V) => boolean; export declare const parseJson: <T>(str: string, defaultValue?: T) => any; export declare function isJsonObjectString(str: string): boolean; export declare const parseValidImageName: (image: string) => string; export declare const atobWithFallback: (str: string, fallbackValue?: string) => string; export interface SafeAssignOptions { notice: (duplicates: string[]) => any; } /** * 带重复检查的assign,只做一级key的重复检查 * 如果有重复项默认会throw error,如果你明确这不是一个关键性错误,则可以通过指定notice函数修改该默认行为 * @param sources * @param optionsOrNotice * @return object 一个全新的对象 */ export declare const safeAssign: <T extends Record<string, any>>(sources: T[], optionsOrNotice?: SafeAssignOptions["notice"] | SafeAssignOptions) => UnionToIntersection<T>; export declare const toLowerFirstLetter: (text: string) => string; export declare const loadEnv: (envText: string) => Array<[string, string]>; export declare function filterEmptyValue<T extends Record<string, unknown>>(obj: T): Partial<T>; export declare function parseBase64Type(base64Str: string): string; export declare function appendImageHeader(value: string, prefix?: string): string; export declare const getRelativePath: (from: string, to: string) => string; export declare const getToPath: (from: string, relative: string) => string; export declare const trackByName: <T extends KubernetesResource>(_: number, resource: T) => string; export declare function tableSort<T>(list: T[], sort: Sort, sortActiveValueFn: (item: T, name: string) => string | number): T[]; export declare function tableSortAdvance<T>(list: T[], sort: Sort, sortActiveValueFn: (item: T, name: string) => string | number): T[]; export declare const buildImageAddress: (url: string, tagOrDigest: string) => string; export declare const parseImageAddress: (addr: string) => { digest?: string; tag?: string; url: string; }; export declare const setWindowsXtermTools: (xterm: Terminal) => void; export declare const clearWindowsXtermTools: () => void; export declare const buildUrl: (baseUri: string, params?: Record<string, string | boolean>) => string;