Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Created December 31, 2021 05:18
Show Gist options
  • Save ryaninvents/d52c872d596fc8c6d765abe0e369898d to your computer and use it in GitHub Desktop.
Save ryaninvents/d52c872d596fc8c6d765abe0e369898d to your computer and use it in GitHub Desktop.
var iso31662 = require("iso-3166-2");
function typeValue(a) {
switch (a.type) {
case 'Outlying area': return 1;
default: return 0;
}
};
[...Object.entries(iso31662.country('USA').sub)].sort(([,a], [,b]) => {
return (typeValue(a) - typeValue(b)) || a.name.localeCompare(b.name)
}).map(([key]) => iso31662.subdivision(key));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment