UNPKG

@knxcloud/lowcode-utils

Version:
127 lines (115 loc) 6.23 kB
import { IPublicTypeNpmInfo, IPublicTypeComponentSchema, IPublicApiProject, AssetItem, AssetBundle, Asset, IPublicTypeJSFunction, IPublicTypeJSSlot, IPublicTypeJSExpression, IPublicTypeI18nData, IPublicTypeNodeSchema, IPublicTypeSlotSchema, IPublicTypeContainerSchema } from '@alilc/lowcode-types'; import { AssetType, AssetLevel } from '@alilc/lowcode-types/es/assets'; export { AssetLevel, AssetLevels, AssetType } from '@alilc/lowcode-types/es/assets'; interface UtilsNpmMetadata { name: string; type: 'npm'; content: IPublicTypeNpmInfo; } interface UtilsFunctionMetadata { name: string; type: 'function'; content: IPublicTypeNpmInfo | CallableFunction; } type UtilsMetadata = UtilsNpmMetadata | UtilsFunctionMetadata; declare function buildUtils(libraryMap: Record<string, string>, utilsMetadata: UtilsMetadata[]): Record<string, unknown>; declare function accessLibrary(library: string | Record<string, unknown>): any; declare function getSubComponent(library: any, paths: string[]): any; declare function findComponent(libraryMap: Record<string, string>, componentName: string, npm?: IPublicTypeNpmInfo): any; declare function buildComponents(libraryMap: Record<string, string>, componentsMap: Record<string, IPublicTypeNpmInfo | IPublicTypeComponentSchema | unknown>, createComponent?: (schema: IPublicTypeComponentSchema) => any): any; declare function setupHostEnvironment(project: IPublicApiProject, vueRuntimeUrl: string): void; /** * copy from https://github.com/alibaba/lowcode-engine/blob/main/packages/utils/src/asset.ts */ declare function isAssetItem(obj: any): obj is AssetItem; declare function isAssetBundle(obj: any): obj is AssetBundle; declare function assetItem(type: AssetType, content?: string | null, level?: AssetLevel, id?: string): AssetItem | null; declare class StylePoint { readonly level: number; readonly id?: string | undefined; private lastContent; private lastUrl; private placeholder; constructor(level: number, id?: string | undefined); applyText(content: string): void; applyUrl(url: string): Promise<unknown> | undefined; } declare class AssetLoader { load(asset: Asset): Promise<void>; private stylePoints; private loadStyle; private loadScript; loadAsyncLibrary(asyncLibraryMap: Record<string, any>): Promise<void>; } type ESModule = { __esModule: true; default: any; }; declare function isNil<T>(val: T | null | undefined): val is null | undefined; declare function isUndefined(val: unknown): val is undefined; declare function isString(val: unknown): val is string; declare function isObject(val: unknown): val is Record<string, unknown>; declare function isBoolean(value: unknown): value is boolean; declare function isArray(val: any): val is any[]; declare function isFunction(val: unknown): val is (...args: any[]) => any; declare function isPromise(val: unknown): val is Promise<unknown>; declare function isPlainObject(val: unknown): val is Record<string, unknown>; declare function isESModule<T>(obj: T | { default: T; }): obj is ESModule; declare function isCSSUrl(url: string): boolean; declare function isElement(node: unknown): node is Element; declare function isJSFunction(val: unknown): val is IPublicTypeJSFunction; declare function isJSSlot(val: unknown): val is IPublicTypeJSSlot; declare function isJSExpression(val: unknown): val is IPublicTypeJSExpression; declare function isI18nData(val: unknown): val is IPublicTypeI18nData; declare function isDOMText(val: unknown): val is string; declare function isNodeSchema(data: any): data is IPublicTypeNodeSchema; declare function isSlotSchema(data: any): data is IPublicTypeSlotSchema; declare function isComponentSchema(val: unknown): val is IPublicTypeComponentSchema; declare function isContainerSchema(val: unknown): val is IPublicTypeContainerSchema; interface Defer<T = unknown> { resolve(value?: T | PromiseLike<T>): void; reject(reason?: any): void; promise(): Promise<T>; } declare function createDefer<T = unknown>(): Defer<T>; /** * 将驼峰命名法的字符串转化为中划线连接的字符串 * * @example * * const res = kebabCase('userName'); // user-name * * @param str - 被转换的字符串 */ declare function kebabCase(str: string): string; /** * 将中划线连接的字符串转化为小驼峰命名法 * * @example * * const res = camelCase('user-name'); // userName * * @param str - 被转换的字符串 */ declare function camelCase(str: string): string; /** * 将中划线连接的字符串转化为大驼峰命名法 * * @example * * const res = pascalCase('user-name'); // UserName * * @param str - 被转换的字符串 */ declare function pascalCase(str: string): string; declare function exportSchema<T extends IPublicTypeNodeSchema>(node: unknown): T; declare const noop: (...args: any[]) => any; declare function fromPairs<E extends Iterable<unknown>>(entries: E): E extends Iterable<infer T> ? T extends [infer K, infer V] ? K extends string ? Record<K, V> : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>; declare function debounce<T extends () => unknown>(fn: T, ms?: number): () => void; declare const toString: (o: unknown) => string; declare function sleep(ms?: number): Promise<void>; declare const createObjectSplitter: (specialProps: string | string[] | ((prop: string) => boolean)) => <T>(o: Record<string, T>) => [Record<string, T>, Record<string, T>, number]; declare const cached: <R>(fn: (param: string) => R) => (param: string) => R; export { AssetLoader, type Defer, type ESModule, StylePoint, type UtilsFunctionMetadata, type UtilsMetadata, type UtilsNpmMetadata, accessLibrary, assetItem, buildComponents, buildUtils, cached, camelCase, createDefer, createObjectSplitter, debounce, exportSchema, findComponent, fromPairs, getSubComponent, isArray, isAssetBundle, isAssetItem, isBoolean, isCSSUrl, isComponentSchema, isContainerSchema, isDOMText, isESModule, isElement, isFunction, isI18nData, isJSExpression, isJSFunction, isJSSlot, isNil, isNodeSchema, isObject, isPlainObject, isPromise, isSlotSchema, isString, isUndefined, kebabCase, noop, pascalCase, setupHostEnvironment, sleep, toString };