diff --git a/mobile-h5/utils/oa-corner-index.js b/mobile-h5/utils/oa-corner-index.js new file mode 100644 index 00000000..85738352 --- /dev/null +++ b/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) +} diff --git a/mobile-h5/utils/oa-corner-index.test.js b/mobile-h5/utils/oa-corner-index.test.js new file mode 100644 index 00000000..6b73f7d7 --- /dev/null +++ b/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')