From f4603b553cf0b038731520921d043f07b0e271c2 Mon Sep 17 00:00:00 2001 From: Michael Beutler Date: Tue, 28 Jun 2022 12:11:09 +0200 Subject: [PATCH] =?UTF-8?q?Extended=20`rename`=20function=20arguments.=20?= =?UTF-8?q?=F0=9F=A7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows for content specific renaming. 🔬 --- package.json | 2 +- src/index.ts | 14 +++++++++----- src/query.ts | 4 +++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index f7f278c..6acd7ca 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@iperka/scan-categorizer", "description": "Categorize your scanned documents and organize them in folders.", - "version": "2.0.0", + "version": "2.0.2", "main": "index.js", "license": "MIT", "author": { diff --git a/src/index.ts b/src/index.ts index af4126b..fae98dd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -88,7 +88,11 @@ namespace ScanCategorizer { const rename = typeof category.rename === 'string' ? category.rename - : category.rename({getName: () => 'TEMP'} as any); + : category.rename({ + getName: () => 'TEMP', + getId: () => 'TEMP', + text: 'Lorem Ipsum', + } as any); // Check if rename is valid. if (!/\.pdf$/.test(rename)) { @@ -163,7 +167,7 @@ namespace ScanCategorizer { // Handle first category matched. Logger.log('Apply category: ' + sorted[0].name); - handleMatch(file, sorted[0]); + handleMatch({...file, text}, sorted[0]); if (sorted.length > 1) { for (let i = 1; i < sorted.length; i++) { @@ -180,7 +184,7 @@ namespace ScanCategorizer { } Logger.log('Creating shortcuts for category: ' + category.name); - handleMatch(file, category, true); + handleMatch({...file, text}, category, true); } } @@ -190,7 +194,7 @@ namespace ScanCategorizer { }; const handleMatch = ( - file: GoogleAppsScript.Drive.File, + file: GoogleAppsScript.Drive.File & {text: string}, category: Query.Category, onlyShortcut?: boolean, ) => { @@ -201,7 +205,7 @@ namespace ScanCategorizer { category.rename !== undefined ? typeof category.rename === 'string' ? Helpers.populate(category.rename, date) - : category.rename(file) + : category.rename({...file}) : file.getName(); if (!/\.pdf$/.test(name)) { diff --git a/src/query.ts b/src/query.ts index cb36673..ae71056 100644 --- a/src/query.ts +++ b/src/query.ts @@ -39,7 +39,9 @@ export namespace Query { /** * Optional custom rename function. */ - rename?: ((document: GoogleAppsScript.Drive.File) => string) | string; + rename?: + | ((document: GoogleAppsScript.Drive.File & {text: string}) => string) + | string; /** * Allow secondary match. When this option is set `true`,