Urara-Blog/node_modules/.pnpm-store/v3/files/44/83a83474be8e4fd834ad374f88f682a0450dc233081b16ddef7f23406e334fa38a8e827be00dfa8155fa7a747b4eaa08e296f80dedb2c0d4dd83c4ad636cc0
2022-08-14 01:14:53 +08:00

23 lines
409 B
Text

const numeric = /^[0-9]+$/
const compareIdentifiers = (a, b) => {
const anum = numeric.test(a)
const bnum = numeric.test(b)
if (anum && bnum) {
a = +a
b = +b
}
return a === b ? 0
: (anum && !bnum) ? -1
: (bnum && !anum) ? 1
: a < b ? -1
: 1
}
const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a)
module.exports = {
compareIdentifiers,
rcompareIdentifiers
}