1const numeric = /^[0-9]+$/ 2const compareIdentifiers = (a, b) => { 3 const anum = numeric.test(a) 4 const bnum = numeric.test(b) 5 6 if (anum && bnum) { 7 a = +a 8 b = +b 9 } 10 11 return a === b ? 0 12 : (anum && !bnum) ? -1 13 : (bnum && !anum) ? 1 14 : a < b ? -1 15 : 1 16} 17 18const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a) 19 20module.exports = { 21 compareIdentifiers, 22 rcompareIdentifiers, 23} 24