@awayfl/avm2
Version:
Virtual machine for executing AS3 code
22 lines (21 loc) • 687 B
text/typescript
import { SORT } from '../abc/lazy/SORT';
import { assertNotImplemented, release } from '@awayfl/swf-loader';
export function axCompare(a: any, b: any, options: SORT, sortOrder: number,
compareFunction: (a, b) => number) {
release || assertNotImplemented(!(options & SORT.UNIQUESORT), 'UNIQUESORT');
release || assertNotImplemented(!(options & SORT.RETURNINDEXEDARRAY),
'RETURNINDEXEDARRAY');
let result = 0;
if (options & SORT.CASEINSENSITIVE) {
a = String(a).toLowerCase();
b = String(b).toLowerCase();
}
if (options & SORT.NUMERIC) {
a = +a;
b = +b;
result = a < b ? -1 : (a > b ? 1 : 0);
} else {
result = compareFunction(a, b);
}
return result * sortOrder;
}