Skip to content

Commit

Permalink
fix: 全角英数を半角英数に置き換える (#6)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
nandenjin authored Jan 23, 2025
1 parent 4ea0b2b commit 298f7d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/lib/string.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** 全角英数を半角英数に置き換える */
export const replaceFullWidthWithHalfWidth = (str: string) => {
return str.replace(/[---]/g, (s) =>
String.fromCharCode(s.charCodeAt(0) - 0xFEE0)
)
}
5 changes: 3 additions & 2 deletions src/store/data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'
import { Transaction, TransactionCategory } from '../types/transaction'
import { replaceFullWidthWithHalfWidth } from '../lib/string'

/** 仕訳に応じて収支のセルの値を選択し返す
*
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 298f7d5

Please sign in to comment.