ob1.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * strict-local
  8. * @format
  9. */
  10. "use strict";
  11. /* eslint-disable no-redeclare */
  12. // A type representing 0-based offsets.
  13. // A type representing 1-based offsets.
  14. // Add two offsets or numbers.
  15. function add(a, b) {
  16. return a + b;
  17. } // Subtract a number or 0-based offset from a 1/0-based offset.
  18. function sub(a, b) {
  19. return a - b;
  20. } // Get the underlying number of a 0-based offset, casting away the opaque type.
  21. function get0(x) {
  22. return x;
  23. } // Get the underlying number of a 1-based offset, casting away the opaque type.
  24. function get1(x) {
  25. return x;
  26. } // Add 1 to a 0-based offset, thus converting it to 1-based.
  27. function add1(x) {
  28. return x + 1;
  29. } // Subtract 1 from a 1-based offset, thus converting it to 0-based.
  30. function sub1(x) {
  31. return x - 1;
  32. } // Negate a 0-based offset.
  33. function neg(x) {
  34. return -x;
  35. } // Cast a number to a 0-based offset.
  36. function add0(x) {
  37. return x;
  38. } // Increment a 0-based offset.
  39. function inc(x) {
  40. return x + 1;
  41. }
  42. module.exports = {
  43. add,
  44. get0,
  45. get1,
  46. add1,
  47. sub1,
  48. sub,
  49. neg,
  50. add0,
  51. inc
  52. };