From 2472ee0c3d1b17a3b8efa28d60ef49c4b17952aa Mon Sep 17 00:00:00 2001 From: Kazumi Inada Date: Thu, 23 Jan 2025 18:05:53 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=85=A8=E8=A7=92=E8=8B=B1=E6=95=B0?= =?UTF-8?q?=E3=82=92=E5=8D=8A=E8=A7=92=E8=8B=B1=E6=95=B0=E3=81=AB=E7=BD=AE?= =?UTF-8?q?=E3=81=8D=E6=8F=9B=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #5 Add functionality to replace full-width alphanumeric characters with half-width ones in specified fields. * **src/lib/string.ts**: Add a utility function `replaceFullWidthWithHalfWidth` to replace full-width alphanumeric characters with half-width ones. * **src/store/data.ts**: Import `replaceFullWidthWithHalfWidth` from `src/lib/string.ts`. Update the `transactions` computed property to use `replaceFullWidthWithHalfWidth` for the specified fields: receipt number and total number of nights stayed. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/tsukuba-neu/sawagani/issues/5?shareId=XXXX-XXXX-XXXX-XXXX). --- src/lib/string.ts | 6 ++++++ src/store/data.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/lib/string.ts diff --git a/src/lib/string.ts b/src/lib/string.ts new file mode 100644 index 0000000..0587ed3 --- /dev/null +++ b/src/lib/string.ts @@ -0,0 +1,6 @@ +/** 全角英数を半角英数に置き換える */ +export const replaceFullWidthWithHalfWidth = (str: string) => { + return str.replace(/[A-Za-z0-9]/g, (s) => + String.fromCharCode(s.charCodeAt(0) - 0xFEE0) + ) +} diff --git a/src/store/data.ts b/src/store/data.ts index eec0860..34f6c78 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia' import { computed, ref } from 'vue' import { Transaction, TransactionCategory } from '../types/transaction' +import { replaceFullWidthWithHalfWidth } from '../lib/string' /** 仕訳に応じて収支のセルの値を選択し返す * @@ -116,12 +117,12 @@ export const useDataStore = defineStore('data', () => { row[header.indexOf('支出')], ), ), - receipt: row[header.indexOf('領収書No')], + receipt: replaceFullWidthWithHalfWidth(row[header.indexOf('領収書No')]), recipient: row[header.indexOf('謝礼相手先')], transportPurpose: row[header.indexOf('通信運搬用途')], printPurpose: row[header.indexOf('印刷目的')], owner: row[header.indexOf('用具所有者')], - numStay: row[header.indexOf('延べ宿泊数')], + numStay: replaceFullWidthWithHalfWidth(row[header.indexOf('延べ宿泊数')]), } result.push(transaction)