tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

positionCmp.js (633B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
      4 
      5 import { locColumn } from "./locColumn";
      6 
      7 /**
      8 * * === 0 - Positions are equal.
      9 * * < 0 - first position before second position
     10 * * > 0 - first position after second position
     11 */
     12 export function positionCmp(p1, p2) {
     13  if (p1.line === p2.line) {
     14    const l1 = locColumn(p1);
     15    const l2 = locColumn(p2);
     16 
     17    if (l1 === l2) {
     18      return 0;
     19    }
     20    return l1 < l2 ? -1 : 1;
     21  }
     22 
     23  return p1.line < p2.line ? -1 : 1;
     24 }