Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
identifiers.js30 linesDownload Raw Back to internal
1'use strict'
2
3const numeric = /^[0-9]+$/
4const compareIdentifiers = (a, b) => {
5  if (typeof a === 'number' && typeof b === 'number') {
6    return a === b ? 0 : a < b ? -1 : 1
7  }
8
9  const anum = numeric.test(a)
10  const bnum = numeric.test(b)
11
12  if (anum && bnum) {
13    a = +a
14    b = +b
15  }
16
17  return a === b ? 0
18    : (anum && !bnum) ? -1
19    : (bnum && !anum) ? 1
20    : a < b ? -1
21    : 1
22}
23
24const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a)
25
26module.exports = {
27  compareIdentifiers,
28  rcompareIdentifiers,
29}
30 
codekingpro/portable-devtools · Team Ai