feat(mobile-h5): add formatCornerIndex for OA list corner badges.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
53e4a52b4f
commit
349019863b
2 files changed
+24
No files matched your search
@@ -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)
|
||||
}
|
||||
@@ -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')
|
||||
Reference in new issue
Block a user