ob1 0.73.2 → 0.73.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ob1",
3
- "version": "0.73.2",
3
+ "version": "0.73.5",
4
4
  "description": "A small library for working with 0- and 1-based offsets in a type-checked way.",
5
5
  "main": "src/ob1.js",
6
6
  "repository": {
@@ -8,10 +8,10 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
12
13
 
13
14
  const { add, add0, add1, get0, get1, inc, neg, sub, sub1 } = require("../ob1");
14
-
15
15
  const FORTY_TWO_0 = add0(42);
16
16
  const FORTY_TWO_1 = add1(42);
17
17
  module.exports = {
@@ -32,29 +32,38 @@ module.exports = {
32
32
  inc(FORTY_TWO_0);
33
33
  inc(FORTY_TWO_1);
34
34
  },
35
-
36
35
  testUnsafeOps() {
37
36
  // $FlowExpectedError - adding two 1-based offsets.
38
- add(FORTY_TWO_1, FORTY_TWO_1); // $FlowExpectedError - subtracting 1-based offset from 0-based offset.
37
+ add(FORTY_TWO_1, FORTY_TWO_1);
39
38
 
40
- sub(FORTY_TWO_0, FORTY_TWO_1); // $FlowExpectedError - direct computations with offsets are disallowed.
39
+ // $FlowExpectedError - subtracting 1-based offset from 0-based offset.
40
+ sub(FORTY_TWO_0, FORTY_TWO_1);
41
41
 
42
- FORTY_TWO_0 - 1; // $FlowExpectedError - direct computations with offsets are disallowed.
42
+ // $FlowExpectedError - direct computations with offsets are disallowed.
43
+ FORTY_TWO_0 - 1;
43
44
 
44
- FORTY_TWO_1 - 1; // $FlowExpectedError - extracting a 1-based offset as a 0-based number
45
+ // $FlowExpectedError - direct computations with offsets are disallowed.
46
+ FORTY_TWO_1 - 1;
45
47
 
46
- get0(FORTY_TWO_1); // $FlowExpectedError - extracting a 0-based offset as a 1-based number
48
+ // $FlowExpectedError - extracting a 1-based offset as a 0-based number
49
+ get0(FORTY_TWO_1);
47
50
 
48
- get1(FORTY_TWO_0); // $FlowExpectedError - negating a 1-based offset
51
+ // $FlowExpectedError - extracting a 0-based offset as a 1-based number
52
+ get1(FORTY_TWO_0);
49
53
 
50
- neg(FORTY_TWO_1); // $FlowExpectedError - adding 1 to an offset that's already 1-based
54
+ // $FlowExpectedError - negating a 1-based offset
55
+ neg(FORTY_TWO_1);
51
56
 
52
- add1(FORTY_TWO_1); // $FlowExpectedError - subtracting 1 from an offset that's already 0-based
57
+ // $FlowExpectedError - adding 1 to an offset that's already 1-based
58
+ add1(FORTY_TWO_1);
53
59
 
54
- sub1(FORTY_TWO_0); // $FlowExpectedError - extracting an arbitrary number as a 0-based number
60
+ // $FlowExpectedError - subtracting 1 from an offset that's already 0-based
61
+ sub1(FORTY_TWO_0);
55
62
 
56
- get0(42); // $FlowExpectedError - extracting an arbitrary number as a 1-based number
63
+ // $FlowExpectedError - extracting an arbitrary number as a 0-based number
64
+ get0(42);
57
65
 
66
+ // $FlowExpectedError - extracting an arbitrary number as a 1-based number
58
67
  get1(42);
59
68
  },
60
69
  };
package/src/ob1.js CHANGED
@@ -8,48 +8,61 @@
8
8
  * @format
9
9
  * @oncall react_native
10
10
  */
11
+
11
12
  "use strict";
13
+
12
14
  /* eslint-disable no-redeclare */
13
- // A type representing 0-based offsets.
14
15
 
16
+ // A type representing 0-based offsets.
15
17
  // A type representing 1-based offsets.
16
18
  // Add two offsets or numbers.
17
19
  function add(a, b) {
18
20
  return a + b;
19
- } // Subtract a number or 0-based offset from a 1/0-based offset.
21
+ }
22
+
23
+ // Subtract a number or 0-based offset from a 1/0-based offset.
20
24
 
21
25
  function sub(a, b) {
22
26
  return a - b;
23
- } // Get the underlying number of a 0-based offset, casting away the opaque type.
27
+ }
28
+
29
+ // Get the underlying number of a 0-based offset, casting away the opaque type.
24
30
 
25
31
  function get0(x) {
26
32
  return x;
27
- } // Get the underlying number of a 1-based offset, casting away the opaque type.
33
+ }
34
+
35
+ // Get the underlying number of a 1-based offset, casting away the opaque type.
28
36
 
29
37
  function get1(x) {
30
38
  return x;
31
- } // Add 1 to a 0-based offset, thus converting it to 1-based.
39
+ }
32
40
 
41
+ // Add 1 to a 0-based offset, thus converting it to 1-based.
33
42
  function add1(x) {
34
43
  return x + 1;
35
- } // Subtract 1 from a 1-based offset, thus converting it to 0-based.
44
+ }
36
45
 
46
+ // Subtract 1 from a 1-based offset, thus converting it to 0-based.
37
47
  function sub1(x) {
38
48
  return x - 1;
39
- } // Negate a 0-based offset.
49
+ }
40
50
 
51
+ // Negate a 0-based offset.
41
52
  function neg(x) {
42
53
  return -x;
43
- } // Cast a number to a 0-based offset.
54
+ }
44
55
 
56
+ // Cast a number to a 0-based offset.
45
57
  function add0(x) {
46
58
  return x;
47
- } // Increment a 0-based offset.
59
+ }
60
+
61
+ // Increment a 0-based offset.
48
62
 
49
63
  function inc(x) {
50
64
  return x + 1;
51
65
  }
52
-
53
66
  module.exports = {
54
67
  add,
55
68
  get0,