Просмотр исходного кода

feat(mobile-h5): add formatCornerIndex for OA list corner badges.

Co-authored-by: Cursor <cursoragent@cursor.com>
zlwu 2 месяцев назад
Родитель
Сommit
349019863b
2 измененных файлов с 24 добавлено и 0 удалено
  1. 12 0
      mobile-h5/utils/oa-corner-index.js
  2. 12 0
      mobile-h5/utils/oa-corner-index.test.js

+ 12 - 0
mobile-h5/utils/oa-corner-index.js

@@ -0,0 +1,12 @@
+// mobile-h5/utils/oa-corner-index.js
+/**
+ * @param {number} n 从 1 起的序号
+ * @returns {string}
+ */
+export function formatCornerIndex(n) {
+  const num = Number(n)
+  if (!Number.isFinite(num) || num < 1) return '01'
+  const i = Math.floor(num)
+  if (i < 10) return '0' + i
+  return String(i)
+}

+ 12 - 0
mobile-h5/utils/oa-corner-index.test.js

@@ -0,0 +1,12 @@
+// mobile-h5/utils/oa-corner-index.test.js
+import assert from 'node:assert/strict'
+import { formatCornerIndex } from './oa-corner-index.js'
+
+assert.equal(formatCornerIndex(1), '01')
+assert.equal(formatCornerIndex(9), '09')
+assert.equal(formatCornerIndex(10), '10')
+assert.equal(formatCornerIndex(11), '11')
+assert.equal(formatCornerIndex(99), '99')
+assert.equal(formatCornerIndex(100), '100')
+
+console.log('oa-corner-index: ok')