summaryrefslogtreecommitdiff
path: root/lib/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.ts')
-rw-r--r--lib/utils.ts14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/utils.ts b/lib/utils.ts
index cb15e830..4d987902 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -275,3 +275,17 @@ export function formatHtml(html: string): string {
return result.join('\n');
}
+
+
+export function compareItemNumber(a?: string, b?: string) {
+ const as = (a ?? "").split(".").map((v) => Number(v));
+ const bs = (b ?? "").split(".").map((v) => Number(v));
+
+ const len = Math.max(as.length, bs.length);
+ for (let i = 0; i < len; i++) {
+ const av = Number.isFinite(as[i]) ? as[i] : Number.NEGATIVE_INFINITY; // 부모가 먼저
+ const bv = Number.isFinite(bs[i]) ? bs[i] : Number.NEGATIVE_INFINITY;
+ if (av !== bv) return av - bv;
+ }
+ return as.length - bs.length;
+} \ No newline at end of file