Skip to content

Commit

Permalink
Use naturalCompare
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jan 23, 2025
1 parent bab406c commit 7c681a9
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions scripts/update-data-npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const validateNpmPackageName = require('validate-npm-package-name')
const constants = require('@socketsecurity/registry/lib/constants')
const { pFilter } = require('@socketsecurity/registry/lib/promises')
const { confirm } = require('@socketsecurity/registry/lib/prompts')
const { naturalCompare } = require('@socketsecurity/registry/lib/sorts')
const { Spinner } = require('@socketsecurity/registry/lib/spinner')

const { abortSignal } = constants
Expand All @@ -20,11 +21,6 @@ const npmDataPath = path.join(dataPath, 'npm')
const npmBuiltinNamesJsonPath = path.join(npmDataPath, 'builtin-names.json')
const npmLegacyNamesJsonPath = path.join(npmDataPath, 'legacy-names.json')

const { compare: alphanumericComparator } = new Intl.Collator(undefined, {
numeric: true,
sensitivity: 'base'
})

void (async () => {
if (
!(await confirm({
Expand All @@ -35,7 +31,7 @@ void (async () => {
return
}
const spinner = new Spinner().start()
const builtinNames = Module.builtinModules.toSorted(alphanumericComparator)
const builtinNames = Module.builtinModules.toSorted(naturalCompare)
const allThePackageNames = [
...new Set([
// Load the 43.1MB names.json file of 'all-the-package-names@2.0.0'
Expand All @@ -53,7 +49,7 @@ void (async () => {
// Instead let registry.npmjs.org be our source of truth to whether a
// package exists or not.
.filter(n => !validateNpmPackageName(n).validForNewPackages)
.sort(alphanumericComparator)
.sort(naturalCompare)
const seenNames = new Set()
const invalidNames = new Set()
const legacyNames =
Expand Down

0 comments on commit 7c681a9

Please sign in to comment.