andreypopp / andreypopp/deps-topo-sort
Unpredictable sorting order with exposed modules
- Vorherrschende Sprache
- JavaScript
- Sterne
- 5
- Forks
- 1
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
When using `.require('./path/to/module', {expose: 'my-module'})` syntax module id becomes the 'my-module' string. It breaks the `cmp` function:
```js
function cmp (a, b) {
return a.id < b.id ? -1 : 1;
}
```
Which always returns `false`, when comparing String to a Number (other ids are numbers).
Proposed fix:
```js
function isString (o) {
return toString.call(o) === '[object String]'
}
function cmp (a, b) {
if (isString(a.id) && !isString(b.id))
return -1
if (!isString(a.id) && isString(b.id))
return 1
return a.id < b.id ? -1 : 1
}
```
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.