repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
eslint-stylistic
github_2023
eslint-stylistic
typescript
FixTracker.remove
remove(nodeOrToken: ASTNode | ESToken | Token | ASTNode) { return this.replaceTextRange(nodeOrToken.range, '') }
/** * Create a fix command that removes the given node or token, accounting for * any retained ranges. * @param nodeOrToken The node or token to remove. * @returns The fix command. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/fix-tracker.ts#L105-L107
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
getParentSyntaxParen
function getParentSyntaxParen(node: ASTNode, sourceCode: SourceCode) { const parent = node.parent if (!parent) return null switch (parent.type) { case 'CallExpression': case 'NewExpression': if (parent.arguments.length === 1 && parent.arguments[0] === node) { return sourceCode.getTokenA...
/** * Get the left parenthesis of the parent node syntax if it exists. * E.g., `if (a) {}` then the `(`. */
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/packages/shared/utils/ast/general.ts#L863-L916
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
identity
function identity< T >(arg: T): T { return arg; }
// Define a generic function
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/tests/configs/fixtures/input/typescript.ts#L28-L30
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
identity
function identity<T> (arg: T): T { return arg; }
// Define a generic function
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/tests/configs/fixtures/output/all/typescript.ts#L32-L36
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
identity
function identity<T>(arg: T): T { return arg }
// Define a generic function
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/tests/configs/fixtures/output/default/typescript.ts#L27-L29
481d54b6521b8705570132424c78d320dec57610
eslint-stylistic
github_2023
eslint-stylistic
typescript
identity
function identity<T>(arg: T): T { return arg; }
// Define a generic function
https://github.com/eslint-stylistic/eslint-stylistic/blob/481d54b6521b8705570132424c78d320dec57610/tests/configs/fixtures/output/tab-quotes-semi/typescript.ts#L27-L29
481d54b6521b8705570132424c78d320dec57610
tsr
github_2023
line
typescript
MemoryFileService.getFileNames
getFileNames() { return this.#fileNames; }
// see also: lib/util/parseFile.ts
https://github.com/line/tsr/blob/06a0ef5e63739e78fa51aba49b63e898f5a6b7d3/lib/util/MemoryFileService.ts#L55-L57
06a0ef5e63739e78fa51aba49b63e898f5a6b7d3
tsr
github_2023
line
typescript
filterChanges
const filterChanges = ({ sourceFile, textChanges, }: { sourceFile: ts.SourceFile; textChanges: readonly ts.TextChange[]; }) => { const result: { start: number; end: number }[] = []; const visit = (node: ts.Node) => { if ( (ts.isArrowFunction(node) || ts.isMethodDeclaration(node) || ...
// we don't want to remove unused positional parameters from functions
https://github.com/line/tsr/blob/06a0ef5e63739e78fa51aba49b63e898f5a6b7d3/lib/util/applyCodeFix.ts#L10-L45
06a0ef5e63739e78fa51aba49b63e898f5a6b7d3
tsr
github_2023
line
typescript
deeplyGetExportNames
const deeplyGetExportNames = ({ item, files, fileNames, options, }: { item: WholeExportDeclarationWithFile; files: Map<string, string>; fileNames: Set<string>; options: ts.CompilerOptions; }): string[] => { const filesAlreadyVisited = new Set<string>(); return innerDeeplyGetExportNames({ item, ...
/** * Retrieves the names of the exports from a whole export declaration. * For each whole export declaration, it will recursively get the names of the exports from the file it points to. */
https://github.com/line/tsr/blob/06a0ef5e63739e78fa51aba49b63e898f5a6b7d3/lib/util/edit.ts#L194-L214
06a0ef5e63739e78fa51aba49b63e898f5a6b7d3
tsr
github_2023
line
typescript
isGlobalScopeAugmentation
const isGlobalScopeAugmentation = (module: ts.ModuleDeclaration) => !!(module.flags & ts.NodeFlags.GlobalAugmentation);
// ref. https://github.com/microsoft/TypeScript/blob/d701d908d534e68cfab24b6df15539014ac348a3/src/compiler/utilities.ts#L2048
https://github.com/line/tsr/blob/06a0ef5e63739e78fa51aba49b63e898f5a6b7d3/lib/util/parseFile.ts#L26-L27
06a0ef5e63739e78fa51aba49b63e898f5a6b7d3
yiyin
github_2023
ggchivalrous
typescript
ExifBase.Make
Make(v = this.exif.Make) { return v ? v[0] + v.slice(1).toLowerCase() : ''; }
/** * 相机厂商 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L11-L13
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.Model
Model(v = this.exif.Model) { return v ? v.toLowerCase() : ''; }
/** * 机型 Nikon Z 30 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L18-L20
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.DateTimeOriginal
DateTimeOriginal(v = this.exif.DateTimeOriginal) { return v; }
/** * 照片拍摄时间 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L25-L27
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.ExposureTime
ExposureTime(v = this.exif.ExposureTime) { if (!v) { return ''; } if (v < 1) { return `1/${Math.round(1 / v)}`; } return v; }
/** * 快门速度 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L32-L41
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.FNumber
FNumber(v = this.exif.FNumber) { return v; }
/** * 光圈大小 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L46-L48
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.FocalLength
FocalLength(v = this.exif.FocalLength) { return v ? Math.round(v) : ''; }
/** * 焦距 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L53-L55
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.FocalLengthIn35mmFormat
FocalLengthIn35mmFormat(v = this.exif.FocalLengthIn35mmFormat) { return v ? Math.round(v) : ''; }
/** * 等效焦距 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L60-L62
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.ExposureProgram
ExposureProgram(v = this.exif.ExposureProgram) { return v; }
/** * 档位 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L71-L73
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.LensModel
LensModel() { return this.exif.LensModel || ''; }
/** * 镜头型号 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L78-L80
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.LensMake
LensMake() { return this.exif.LensMake || ''; }
/** * 镜头厂商 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L85-L87
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.ExposureCompensation
ExposureCompensation() { return this.exif.ExposureCompensation; }
/** * 曝光补偿 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L92-L94
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.MeteringMode
MeteringMode() { return this.exif.MeteringMode; }
/** * 测光模式 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L99-L101
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.Flash
Flash() { return this.exif.Flash; }
/** * 闪光灯 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L106-L108
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.ExposureMode
ExposureMode() { return this.exif.ExposureMode; }
/** * 曝光模式 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L113-L115
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ExifBase.WhiteBalance
WhiteBalance() { return this.exif.WhiteBalance; }
/** * 白平衡 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/common/modules/exif-format/base.ts#L120-L122
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ImageTool.clacBgImgSize
clacBgImgSize(height: number = this.sizeInfo.h) { if (!this.isInit) throw NotInit; let resetHeight = this.sizeInfo.resetH; let resetWidth = this.sizeInfo.resetW; const whRate = resetWidth / resetHeight; // 按照重置后的宽高比算出适合内容高度的宽度 if (height) { resetHeight = height; resetWidth = Math....
/** * @param height - 指定内容高度,默认为创建时的输入的图片高度 */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/electron/src/modules/image-tool/index.ts#L400-L434
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
ImageTool.calcAverageBrightness
calcAverageBrightness(ctx: CanvasRenderingContext2D, width: number, height: number) { const imageData = ctx.getImageData(0, 0, width, height); const { data } = imageData; let totalBrightness = 0; // 简单的亮度计算方法 for (let i = 0; i < data.length; i += 4) { const brightness = (data[i] + data[i + 1]...
// 计算图片整体亮度
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/web/modules/image-tool/index.ts#L90-L102
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
yiyin
github_2023
ggchivalrous
typescript
fillTempFieldInfo
async function fillTempFieldInfo( tempFieldConf: Record<string, IFieldInfoItem>, logoPath: string, exifInfo?: Record<string, any>, ) { const exif = new ExifFormat(exifInfo || {}); const tempFieldInfo: Record<string, IFieldInfoItem> = {}; for (const field in tempFieldConf) { const info = tempFieldConf[f...
/** * 模版 Field 对象信息填充 * @param tempFieldConf * @param exifInfo - 规范化的相机信息对象 * @returns */
https://github.com/ggchivalrous/yiyin/blob/6fa0d2f5e1dba71526029ee8a0a45237eb40644f/web/modules/temp-field/index.ts#L58-L107
6fa0d2f5e1dba71526029ee8a0a45237eb40644f
relagit
github_2023
relagit
typescript
cron
const cron = <T extends CronStringsArray | number>( time: T ): T extends number ? { [unit in 'minutes' | 'hours' | 'days' | 'months']: number; } : number => { if (typeof time === 'number') { return { minutes: time * 60 * 1000, hours: time * 60 * 60 * 1000, days: time * 24 * 60 * 60 * 1000, months: t...
/** * A utility to generate CRON timings. * @param time - Either a CRON string `'*\/5 * * * * *'` or a template string `'5 minutes'` or a number `5`. * @returns - If a CRON or template string is passed, it returns a number. If a number is passed, it returns an object with the time in minutes, hours, days, months and...
https://github.com/relagit/relagit/blob/8ed9fcfb2cc76b31a417aa90d766f003d07240bd/packages/app/src/modules/actions/workflows.ts#L445-L485
8ed9fcfb2cc76b31a417aa90d766f003d07240bd
relagit
github_2023
relagit
typescript
listener
const listener = () => set(factory());
// @ts-expect-error - not doing gymnastics to make this work
https://github.com/relagit/relagit/blob/8ed9fcfb2cc76b31a417aa90d766f003d07240bd/packages/app/src/stores/index.ts#L37-L37
8ed9fcfb2cc76b31a417aa90d766f003d07240bd
relagit
github_2023
relagit
typescript
updateCheck
const updateCheck = () => { if (__NODE_ENV__ === 'development') return; autoUpdater.checkForUpdatesAndNotify(); autoUpdater.logger = { info: (message: string) => webContents .getAllWebContents() .forEach((w) => w.executeJavaScript( `console.info(\`${ typeof message === 'string' ? mes...
// TODO: Fix auto-updater
https://github.com/relagit/relagit/blob/8ed9fcfb2cc76b31a417aa90d766f003d07240bd/packages/main/src/index.ts#L41-L78
8ed9fcfb2cc76b31a417aa90d766f003d07240bd
file-organizer-2000
github_2023
different-ai
typescript
sanitizeContent
async function sanitizeContent(content: string): Promise<string> { try { // If content is empty or not a string, return empty string if (!content || typeof content !== "string") { return ""; } const lines = content.split("\n"); let inFrontmatter = false; let validContent: string[] = [];...
/** * Sanitizes content to ensure it's valid for Obsidian * Handles frontmatter and content separately for safety */
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/fileUtils.ts#L194-L256
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
FileOrganizer.appendAttachment
async appendAttachment(markdownFile: TFile, attachmentFile: TFile) { await this.app.vault.append( markdownFile, `\n\n![[${attachmentFile.name}]]` ); }
// adds an attachment to a file using the ![[attachment]] syntax
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/index.ts#L554-L559
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
FileOrganizer.getAllUserMarkdownFiles
getAllUserMarkdownFiles(): TFile[] { const settingsPaths = [ this.settings.pathToWatch, this.settings.defaultDestinationPath, this.settings.attachmentsPath, this.settings.backupFolderPath, ]; const allFiles = this.app.vault.getMarkdownFiles(); // remove any file path that is part...
// rn used to provide aichat contex
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/index.ts#L597-L611
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
FileOrganizer.getAllUserFolders
getAllUserFolders(): string[] { const allFolders = this.app.vault.getAllFolders(); const allFoldersPaths = allFolders.map(folder => folder.path); const ignoredFolders = this.getAllIgnoredFolders(); // If ignoreFolders includes "*", return empty array as all folders are ignored if (this.settings.ign...
// this is a list of all the folders that file organizer to use for organization
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/index.ts#L630-L649
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
FileOrganizer.getTemplateNames
async getTemplateNames(): Promise<string[]> { // get all file names in the template folder const templateFolder = this.app.vault.getAbstractFileByPath( this.settings.templatePaths ); if (!templateFolder || !(templateFolder instanceof TFolder)) { logger.error("Template folder not found or is ...
// and doesn't reuse getTemplates()
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/index.ts#L1033-L1046
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
Inbox.processInboxFile
private async processInboxFile( inboxFile: TFile, hash?: string ): Promise<void> { this.recordManager.setStatus(hash, "processing"); const context: ProcessingContext = { inboxFile, hash, plugin: this.plugin, recordManager: this.recordManager, idService: this.idService, ...
// Refactored method using parallel processing where possible
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L299-L397
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
startProcessing
async function startProcessing( context: ProcessingContext ): Promise<ProcessingContext> { console.log("startProcessing", context); return context; }
// Pipeline processing steps
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L521-L526
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
handleBypass
async function handleBypass( context: ProcessingContext, reason: string ): Promise<void> { try { logger.info("Bypassing file", context.inboxFile); // First mark as bypassed in the record manager // Then move the file const bypassedFolderPath = context.plugin.settings.bypassedFilePath; await s...
// New helper function to handle bypassing
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L567-L586
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
handleError
async function handleError( error: any, context: ProcessingContext ): Promise<void> { const lastError = context.recordManager.getLastError(context.hash); logger.error(`Error in step ${lastError?.action}:`, { error: error.message, step: lastError?.action, file: context.inboxFile.path, }); conte...
// Error handling
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L716-L746
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
moveToBackupFolder
async function moveToBackupFolder(context: ProcessingContext): Promise<void> { await safeMove( context.plugin.app, context.inboxFile, context.plugin.settings.backupFolderPath ); }
// moveToBackupFolder
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L749-L755
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
moveFileToErrorFolder
async function moveFileToErrorFolder( context: ProcessingContext ): Promise<void> { await safeMove( context.plugin.app, context.inboxFile, context.plugin.settings.errorFilePath ); }
// Helper functions for file operations
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L758-L766
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
shouldSkipAction
function shouldSkipAction(context: ProcessingContext, action: Action): boolean { switch (action) { case Action.CLASSIFY: return !context.plugin.settings.enableDocumentClassification; case Action.FORMATTING: return !context.plugin.settings.enableDocumentClassification; case Action.RENAME: ...
// skip actions when settings below are false
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/index.ts#L782-L795
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
ErrorService.handleFileOperationError
public handleFileOperationError(operation: string, path: string, error: Error): void { this.handleError({ message: `Failed to ${operation} file: ${path}`, severity: ErrorSeverity.HIGH, context: { operation, path }, error, shouldNotify: true }); }
// Helper methods for common error scenarios
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/services/error-service.ts#L105-L113
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
RecordManager.getRecord
public getRecord(hash: string): FileRecord | undefined { return this.records.get(hash); }
// Query methods
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/services/record-manager.ts#L311-L313
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
RecordManager.getAllRecords
public getAllRecords(): FileRecord[] { return Array.from(this.records.values()); }
// Query methods for multiple records
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/inbox/services/record-manager.ts#L351-L353
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
BaseFolderButton
const BaseFolderButton: React.FC<{ folder: string; onClick: (folder: string) => void; className?: string; score?: number; reason?: string; }> = ({ folder, onClick, className, score, reason }) => ( <motion.button className={`px-3 py-1 rounded-md transition-colors duration-200 shadow-none ${className}`} ...
// Base Folder Button Component
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/plugin/views/assistant/organizer/components/suggestion-buttons.tsx#L5-L23
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
NextRequest.cookies
get cookies() { return new Map(); }
// Add other required Next.js Request methods
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/__mocks__/next/server.ts#L25-L27
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
prepTask
const prepTask = (text: string): string[] => { const tokens: string[] = []; nlp.readDoc(text) .tokens() .filter((t) => t.out(its.type) === "word" && !t.out(its.stopWordFlag)) .each((t) => tokens.push( t.out(its.negationFlag) ? `!${t...
// Define the preparation task for tokenization
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/app/api/(newai)/folders/embeddings/bm25.ts#L14-L25
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
computeBM25Scores
function computeBM25Scores(query: string, bm25: any): Map<string, number> { const results = bm25.search(query); const scoreMap = new Map<string, number>(); results.forEach((result: any) => { scoreMap.set(result.ref, result.score); }); return scoreMap; }
/** * Function to compute BM25 scores for a query. * @param query The search query string * @param bm25 BM25TextSearch instance * @returns A Map of folder names to their BM25 scores */
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/app/api/(newai)/folders/embeddings/route.ts#L24-L31
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
sortByScore
const sortByScore = <T extends { score: number }>(arr: T[]) => [...arr].sort((a, b) => b.score - a.score);
// Sort all arrays by score
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/app/api/(newai)/organize-all/route.ts#L69-L70
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
handleSubscription
const handleSubscription = async ( session: Stripe.Checkout.Session & { metadata: ProductMetadata } ) => { const metadata = session.metadata; console.log("creating subscription with metadata", metadata); // insert or update await db .insert(UserUsageTable) .values({ userId: metadata.userId, ...
// sample yearly metadata
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/app/api/webhook/handlers/checkout-complete.ts#L18-L47
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
getUrls
const getUrls = () => { const origin = getUrl(); return { success: `${origin}/dashboard/subscribers`, cancel: `${origin}/dashboard`, lifetime: `${origin}/dashboard/lifetime`, }; };
// Helper to get URLs
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/app/dashboard/pricing/actions.ts#L13-L20
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
handleLogging
async function handleLogging( req: NextRequest, userId: string, isCustomer: boolean ) { const authClient = await clerkClient(); const user = await authClient.users.getUser(userId); const client = PostHogClient(); if (client) { client.capture({ distinctId: userId, event: "call-api", p...
/** * @deprecated This function is being deprecated in favor of a new authorization method. * Please use the new handleAuthorizationV2 function instead. */
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/lib/handleAuthorization.ts#L11-L30
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
generateTestUserId
function generateTestUserId(testCase: string): string { return `test_${testCase}_${uuidv4().split("-")[0]}`; }
// Helper to generate unique test user IDs
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/scripts/webhooks.test.ts#L53-L55
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
triggerWebhook
function triggerWebhook(command: string) { try { execSync(command, { stdio: "inherit" }); } catch (error) { console.error("Error triggering webhook:", error); throw error; } }
// Helper to trigger stripe webhook
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/packages/web/scripts/webhooks.test.ts#L58-L65
80acdb2c6aef3545890c7c58b8b26c203b85aabb
file-organizer-2000
github_2023
different-ai
typescript
onFocus
const onFocus = () => loadSettings();
// Refresh on window focus
https://github.com/different-ai/file-organizer-2000/blob/80acdb2c6aef3545890c7c58b8b26c203b85aabb/pipes/file-organizer-notifications/src/lib/hooks/use-settings.tsx#L57-L57
80acdb2c6aef3545890c7c58b8b26c203b85aabb
marz
github_2023
hex2f
typescript
startChildWorker
async function startChildWorker() { if (child) { child.kill() } child = child_process.spawn("bun", ["run", path.join(import.meta.dir, "dev-worker.ts")], { stdio: "inherit", env: { ...process.env, MARZ_DEV: "true", }, }) child.on("close", () => { child = undefined }) }
// hm.. not the best name 😅
https://github.com/hex2f/marz/blob/5c34776e6c21649617adcd7421d6e628e0584665/packages/marz/dev.ts#L43-L59
5c34776e6c21649617adcd7421d6e628e0584665
purest-admin
github_2023
dymproject
typescript
pathResolve
const pathResolve = (dir = ".", metaUrl = import.meta.url) => { // 当前文件目录的绝对路径 const currentFileDir = dirname(fileURLToPath(metaUrl)); // build 目录的绝对路径 const buildDir = resolve(currentFileDir, "build"); // 解析的绝对路径 const resolvedPath = resolve(currentFileDir, dir); // 检查解析的绝对路径是否在 build 目录内 if (resolvedP...
/** * @description 根据可选的路径片段生成一个新的绝对路径 * @param dir 路径片段,默认`build` * @param metaUrl 模块的完整`url`,如果在`build`目录外调用必传`import.meta.url` */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/build/utils.ts#L22-L36
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
wrapperEnv
const wrapperEnv = (envConf: Recordable): ViteEnv => { // 默认值 const ret: ViteEnv = { VITE_PORT: 8848, VITE_PUBLIC_PATH: "", VITE_ROUTER_HISTORY: "", VITE_CDN: false, VITE_HIDE_HOME: "false", VITE_COMPRESSION: "none" }; for (const envName of Object.keys(envConf)) { let realName = env...
/** 处理环境变量 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/build/utils.ts#L51-L78
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getPackageSize
const getPackageSize = options => { const { folder = "dist", callback, format = true } = options; readdir(folder, (err, files: string[]) => { if (err) throw err; let count = 0; const checkEnd = () => { ++count == files.length && callback(format ? formatBytes(sum(fileListTotal)) : sum(fileL...
/** 获取指定文件夹中所有文件的总大小 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/build/utils.ts#L83-L108
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
addDialog
const addDialog = (options: DialogOptions) => { const open = () => dialogStore.value.push(Object.assign(options, { visible: true })); if (options?.openDelay) { useTimeoutFn(() => { open(); }, options.openDelay); } else { open(); } };
/** 打开弹框 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/components/ReDialog/index.ts#L16-L26
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
closeDialog
const closeDialog = (options: DialogOptions, index: number, args?: any) => { dialogStore.value[index].visible = false; options.closeCallBack && options.closeCallBack({ options, index, args }); const closeDelay = options?.closeDelay ?? 200; useTimeoutFn(() => { dialogStore.value.splice(index, 1); }, close...
/** 关闭弹框 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/components/ReDialog/index.ts#L29-L37
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
updateDialog
const updateDialog = (value: any, key = "title", index = 0) => { dialogStore.value[index][key] = value; };
/** * @description 更改弹框自身属性值 * @param value 属性值 * @param key 属性,默认`title` * @param index 弹框索引(默认`0`,代表只有一个弹框,对于嵌套弹框要改哪个弹框的属性值就把该弹框索引赋给`index`) */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/components/ReDialog/index.ts#L45-L47
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
closeAllDialog
const closeAllDialog = () => { dialogStore.value = []; };
/** 关闭所有弹框 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/components/ReDialog/index.ts#L50-L52
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
responsiveStorageNameSpace
const responsiveStorageNameSpace = () => getConfig().ResponsiveStorageNameSpace;
/** 本地响应式存储的命名空间 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/config/index.ts#L53-L53
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
setLayoutThemeColor
function setLayoutThemeColor( theme = getConfig().Theme ?? "light", isClick = true ) { layoutTheme.value.theme = theme; toggleTheme({ scopeName: `layout-theme-${theme}` }); // 如果非isClick,保留之前的themeColor const storageThemeColor = $storage.layout.themeColor; $storage.layout = { ...
/** 设置导航主题色 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useDataThemeChange.ts#L52-L78
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
setEpThemeColor
const setEpThemeColor = (color: string) => { useEpThemeStoreHook().setEpThemeColor(color); document.documentElement.style.setProperty("--el-color-primary", color); for (let i = 1; i <= 2; i++) { setPropertyPrimary("dark", i, color); } for (let i = 1; i <= 9; i++) { setPropertyPrimary("li...
/** 设置 `element-plus` 主题色 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useDataThemeChange.ts#L88-L97
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
dataThemeChange
function dataThemeChange(overall?: string) { overallStyle.value = overall; if (useEpThemeStoreHook().epTheme === "light" && dataTheme.value) { setLayoutThemeColor("default", false); } else { setLayoutThemeColor(useEpThemeStoreHook().epTheme, false); } if (dataTheme.value) { docume...
/** 浅色、深色整体风格切换 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useDataThemeChange.ts#L100-L116
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
onReset
function onReset() { removeToken(); storageLocal().clear(); const { Grey, Weak, MultiTagsCache, EpThemeColor, Layout } = getConfig(); useAppStoreHook().setLayout(Layout); setEpThemeColor(EpThemeColor); useMultiTagsStoreHook().multiTagsCacheChange(MultiTagsCache); toggleClass(Grey, "html-grey...
/** 清空缓存并返回登录页 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useDataThemeChange.ts#L119-L131
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
changeTitle
function changeTitle(meta: routeMetaType) { const Title = getConfig().Title; if (Title) document.title = `${meta.title} | ${Title}`; else document.title = meta.title; }
/** 动态title */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useNav.ts#L66-L70
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
logout
function logout() { useUserStoreHook().logOut(); }
/** 退出登录 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useNav.ts#L73-L75
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
isRemaining
function isRemaining(path: string) { return remainingPaths.includes(path); }
/** 判断路径是否参与菜单 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useNav.ts#L110-L112
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getLogo
function getLogo() { return new URL("/logo.svg", import.meta.url).href; }
/** 获取`logo` */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useNav.ts#L115-L117
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
onMouseenter
function onMouseenter(index) { if (index) activeIndex.value = index; if (unref(showModel) === "smart") { if (hasClass(instance.refs["schedule" + index][0], "schedule-active")) return; toggleClass(true, "schedule-in", instance.refs["schedule" + index][0]); toggleClass(false, "schedule-o...
/** 鼠标移入添加激活样式 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useTag.ts#L168-L180
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
onMouseleave
function onMouseleave(index) { activeIndex.value = -1; if (unref(showModel) === "smart") { if (hasClass(instance.refs["schedule" + index][0], "schedule-active")) return; toggleClass(false, "schedule-in", instance.refs["schedule" + index][0]); toggleClass(true, "schedule-out", instance....
/** 鼠标移出恢复默认样式 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/layout/hooks/useTag.ts#L183-L195
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
toCorrectRoute
function toCorrectRoute() { // 开启隐藏首页后在浏览器地址栏手动输入首页welcome路由则跳转到404页面 if (VITE_HIDE_HOME === "true" && to.fullPath === "/welcome") { next({ path: "/error/404" }); } // 无权限跳转403页面 else if ( to.meta?.permissions && !isOneOfArray(to.meta?.permissions, currentUser?.permissions) ) {...
/** 如果已经登录并存在登录信息后不能跳转到路由白名单,而是继续保持在当前页面 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/index.ts#L122-L136
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
ascending
function ascending(arr: any[]) { arr.forEach((v, index) => { // 当rank不存在时,根据顺序自动创建,首页路由永远在第一位 if (handRank(v)) v.meta.rank = index + 2; }); return arr.sort( (a: { meta: { rank: number } }, b: { meta: { rank: number } }) => { return a?.meta.rank - b?.meta.rank; } ); }
/** 按照路由中meta下的rank等级升序来排序路由 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L42-L52
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
filterTree
function filterTree(data: RouteComponent[]) { const newTree = cloneDeep(data).filter( (v: { meta: { showLink: boolean } }) => v.meta?.showLink !== false ); newTree.forEach( (v: { children }) => v.children && (v.children = filterTree(v.children)) ); return newTree; }
/** 过滤meta中showLink为false的菜单 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L55-L63
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
filterChildrenTree
function filterChildrenTree(data: RouteComponent[]) { const newTree = cloneDeep(data).filter((v: any) => v?.children?.length !== 0); newTree.forEach( (v: { children }) => v.children && (v.children = filterTree(v.children)) ); return newTree; }
/** 过滤children长度为0的的目录,当目录下没有菜单时,会过滤此目录,目录没有赋予roles权限,当目录下只要有一个菜单有显示权限,那么此目录就会显示 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L66-L72
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
isOneOfArray
function isOneOfArray(a: Array<string>, b: Array<string>) { return Array.isArray(a) && Array.isArray(b) ? intersection(a, b).length > 0 ? true : false : true; }
/** 判断两个数组彼此是否存在相同值 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L75-L81
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
filterNoPermissionTree
function filterNoPermissionTree(data: RouteComponent[]) { const currentUser = useUserStoreHook().getCurrentUser; const permissions = currentUser?.permissions ?? []; const newTree = cloneDeep(data).filter((v: any) => { return isOneOfArray(v.meta?.permissions, permissions); }); newTree.forEach( (v: any)...
/** 从sessionStorage里取出当前登陆用户的角色roles,过滤无权限的菜单 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L84-L94
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getParentPaths
function getParentPaths(value: string, routes: RouteRecordRaw[], key = "path") { // 深度遍历查找 function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) { for (let i = 0; i < routes.length; i++) { const item = routes[i]; // 返回父级path if (item[key] === value) return parents; // ...
/** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L97-L118
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
dfs
function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) { for (let i = 0; i < routes.length; i++) { const item = routes[i]; // 返回父级path if (item[key] === value) return parents; // children不存在或为空则不递归 if (!item.children || !item.children.length) continue; // 往下查找时将...
// 深度遍历查找
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L99-L115
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
findRouteByPath
function findRouteByPath(path: string, routes: RouteRecordRaw[]) { let res = routes.find((item: { path: string }) => item.path == path); if (res) { return isProxy(res) ? toRaw(res) : res; } else { for (let i = 0; i < routes.length; i++) { if ( routes[i].children instanceof Array && r...
/** 查找对应 `path` 的路由信息 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L121-L139
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
handleAsyncRoutes
function handleAsyncRoutes(routeList) { if (routeList.length === 0) { usePermissionStoreHook().handleWholeMenus(routeList); } else { formatFlatteningRoutes(addAsyncRoutes(routeList)).map( (v: RouteRecordRaw) => { // 防止重复添加路由 if ( router.options.routes[0].children.findIndex( ...
/** 处理动态路由(后端返回的路由) */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L152-L181
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
initRouter
function initRouter() { if (getConfig()?.CachingAsyncRoutes) { // 开启动态路由缓存本地sessionStorage const key = "async-routes"; const asyncRouteList = storageSession().getItem(key) as any; if (asyncRouteList && asyncRouteList?.length > 0) { return new Promise(resolve => { handleAsyncRoutes(asyncR...
/** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L184-L196
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
formatFlatteningRoutes
function formatFlatteningRoutes(routesList: RouteRecordRaw[]) { if (routesList.length === 0) return routesList; let hierarchyList = buildHierarchyTree(routesList); for (let i = 0; i < hierarchyList.length; i++) { if (hierarchyList[i].children) { hierarchyList = hierarchyList .slice(0, i + 1) ...
/** * 将多级嵌套路由处理成一维数组 * @param routesList 传入路由 * @returns 返回处理后的一维路由 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L203-L214
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
formatTwoStageRoutes
function formatTwoStageRoutes(routesList: RouteRecordRaw[]) { if (routesList.length === 0) return routesList; const newRoutesList: RouteRecordRaw[] = []; routesList.forEach((v: RouteRecordRaw) => { if (v.path === "/") { newRoutesList.push({ component: v.component, name: v.name, p...
/** * 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存) * https://github.com/pure-admin/vue-pure-admin/issues/67 * @param routesList 处理后的一维路由菜单数组 * @returns 返回将一维数组重新处理成规定路由的格式 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L222-L240
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
handleAliveRoute
function handleAliveRoute({ name }: ToRouteType, mode?: string) { switch (mode) { case "add": usePermissionStoreHook().cacheOperate({ mode: "add", name }); break; case "delete": usePermissionStoreHook().cacheOperate({ mode: "delete", name }); ...
/** 处理缓存路由(添加、删除、刷新) */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L243-L275
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
addAsyncRoutes
function addAsyncRoutes(arrRoutes: Array<RouteRecordRaw>) { if (!arrRoutes || !arrRoutes.length) return; const modulesRoutesKeys = Object.keys(modulesRoutes); arrRoutes.forEach((v: RouteRecordRaw) => { // 将backstage属性加入meta,标识此路由为后端返回路由 v.meta.backstage = true; // 父级的redirect属性取值:如果子级存在且父级的redirect属性不...
/** 过滤后端传来的动态路由 重新生成规范路由 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L278-L304
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getHistoryMode
function getHistoryMode(routerHistory): RouterHistory { // len为1 代表只有历史模式 为2 代表历史模式中存在base参数 https://next.router.vuejs.org/zh/api/#%E5%8F%82%E6%95%B0-1 const historyMode = routerHistory.split(","); const leftMode = historyMode[0]; const rightMode = historyMode[1]; // no param if (historyMode.length === 1) {...
/** 获取路由历史模式 https://next.router.vuejs.org/zh/guide/essentials/history-mode.html */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L307-L327
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getAuths
function getAuths(): Array<string> { // return router.currentRoute.value.meta.auths as Array<string>; const currentUser = useUserStoreHook().currentUser; return currentUser?.permissions ?? []; }
/** 获取当前页面按钮级别的权限 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L330-L334
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
hasAuth
function hasAuth(value: string | Array<string>): boolean { if (!value) return false; /** 从当前路由的`meta`字段里获取按钮级别的所有自定义`code`值 */ const metaAuths = getAuths(); if (!metaAuths) return false; const isAuths = isString(value) ? metaAuths.includes(value) : isIncludeAllChildren(value, metaAuths); return isAu...
/** 是否有按钮级别的权限 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L337-L346
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
getTopMenu
function getTopMenu(tag = false): menuType { const topMenu = usePermissionStoreHook().wholeMenus[0]?.children[0]; tag && useMultiTagsStoreHook().handleTags("push", topMenu); return topMenu; }
/** 获取所有菜单中的第一个菜单(顶级菜单)*/
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/router/utils.ts#L349-L353
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
message
const message = ( message: string | VNode | (() => VNode), params?: MessageParams ): MessageHandler => { if (!params) { return ElMessage({ message, customClass: "pure-message" }); } else { const { icon, type = "info", dangerouslyUseHTMLString = false, customClass ...
/** 用法非常简单,参考 src/views/components/message/index.vue 文件 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/utils/message.ts#L38-L78
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
closeAllMessage
const closeAllMessage = (): void => ElMessage.closeAll();
/** * 关闭所有 `Message` 消息提示函数 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/utils/message.ts#L83-L83
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
isImgElement
function isImgElement(element) { return typeof HTMLImageElement !== "undefined" ? element instanceof HTMLImageElement : element.tagName.toLowerCase() === "img"; }
/** 是否为`img`标签 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/utils/preventDefault.ts#L4-L8
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
propTypes.style
static get style() { return toValidableType("style", { type: [String, Object] }); }
// a native-like validator that supports the `.validable` method
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/utils/propTypes.ts#L28-L32
5d07de62daefeb4797975e839bad066e1d88cf4c
purest-admin
github_2023
dymproject
typescript
PureHttp.retryOriginalRequest
private static retryOriginalRequest(config: PureHttpRequestConfig) { return new Promise(resolve => { PureHttp.requests.push((token: string) => { config.headers["Authorization"] = `Bearer ${token}`; resolve(config); }); }); }
/** 重连原始请求 */
https://github.com/dymproject/purest-admin/blob/5d07de62daefeb4797975e839bad066e1d88cf4c/client-vue/pure-admin/src/utils/http/index.ts#L53-L60
5d07de62daefeb4797975e839bad066e1d88cf4c