generated from namidapoo/next15-shadcn-use-bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from namidapoo/dev
Release `v1.0.1`
- Loading branch information
Showing
5 changed files
with
49 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* 去年の数値(prevYear) と 今年の数値(currentYear)を引数に取り、 | ||
* 数値(小数第2位まで) か "-" を返す関数 | ||
* | ||
* @param {number} prevYear - 去年のコミット数や指標となる数値 | ||
* @param {number} currentYear - 今年のコミット数や指標となる数値 | ||
* @returns {number|"-"} - 有効な場合は数値型、無効の場合は "-" | ||
*/ | ||
export function calculateChangeRate( | ||
prevYear: number, | ||
currentYear: number, | ||
): number | "-" { | ||
if (typeof prevYear !== "number" || typeof currentYear !== "number") { | ||
return "-"; | ||
} | ||
|
||
if (prevYear === 0) { | ||
return "-"; | ||
} | ||
|
||
const ratio = ((currentYear - prevYear) / prevYear) * 100; | ||
|
||
if (!Number.isFinite(ratio)) { | ||
return "-"; | ||
} | ||
|
||
return Number.parseFloat(ratio.toFixed(2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters