Urara-Blog/node_modules/.pnpm-store/v3/files/01/6cdd665fe8a7191d913b4bd9238bd6dc54354434f53900c543dea815135e67d0e716010e8faa315cc0911957c788a39163bbf62acc51bcbbcf48546d6d6abb
2022-08-14 01:14:53 +08:00

23 lines
410 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,
}