UNPKG

@scena/react-folder

Version:

<p align="middle" ><img src="https://raw.githubusercontent.com/daybrush/react-folder/master/public/logo.png"/></p> <h2 align="middle">React Folder</h2> <p align="middle"> <a href="https://www.npmjs.com/package/@scena/react-folder" target="_blank"><img src

70 lines (63 loc) 1.85 kB
import { isString } from "@daybrush/utils"; import { prefixNames } from "framework-utils"; import { PREFIX } from "./consts"; import { FileInfo, FolderProps } from "./types"; export function prefix(...classNames: string[]) { return prefixNames(PREFIX, ...classNames); } export function getId<T>( idProperty: FolderProps<T>["idProperty"], info: T, index: number, scope: string[] ) { return (isString(idProperty) ? info[idProperty] : idProperty!(info, index, scope)) as string; } export function getName<T>( nameProperty: FolderProps<T>["nameProperty"], info: T, index: number, scope: string[] ) { return (isString(nameProperty) ? info[nameProperty] : nameProperty!(info, index, scope)) as string; } export function getChildren<T>( childrenProperty: FolderProps<T>["childrenProperty"], info: T, scope: string[] ) { return (isString(childrenProperty) ? info[childrenProperty] : childrenProperty!(info, scope)) as T[]; } export function getPath<T>( pathProperty: FolderProps<T>["pathProperty"], id: string, scope: string[], info: T, index: number, ): string[] { return (isString(pathProperty) ? info[pathProperty] : pathProperty!(id, scope, info, index)) as string[]; } export function isEqualArray<T>( a: T[], b: T[], ) { return a.length === b.length && a.every((v, i) => v === b[i]); } export function findParentFileInfo(fileInfo: FileInfo<any> | null | undefined, pathUrl: string): FileInfo<any> | null { if (!fileInfo) { return null; } if (fileInfo.pathUrl === pathUrl) { return fileInfo; } return findParentFileInfo(fileInfo.parentFileInfo, pathUrl); } export function isArrayContains(arr1: any[], arr2: any[]) { return arr1.every((el, i) => el === arr2[i]); }