ob1 0.83.1 → 0.83.3

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.83.1",
3
+ "version": "0.83.3",
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
  "exports": {
@@ -1,37 +1,41 @@
1
1
  "use strict";
2
2
 
3
- const { add, add0, add1, get0, get1, inc, neg, sub, sub1 } = require("../ob1");
4
- const FORTY_TWO_0 = add0(42);
5
- const FORTY_TWO_1 = add1(42);
6
- module.exports = {
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.default = void 0;
7
+ var _ob = require("../ob1");
8
+ const FORTY_TWO_0 = (0, _ob.add0)(42);
9
+ const FORTY_TWO_1 = (0, _ob.add1)(42);
10
+ var _default = (exports.default = {
7
11
  testSafeOps() {
8
- add(FORTY_TWO_0, FORTY_TWO_0);
9
- add(FORTY_TWO_0, FORTY_TWO_1);
10
- add(FORTY_TWO_1, FORTY_TWO_0);
11
- sub(FORTY_TWO_1, FORTY_TWO_1);
12
- add(FORTY_TWO_0, 9000);
13
- add(FORTY_TWO_0, 9000);
14
- add(FORTY_TWO_1, 9000);
15
- sub(FORTY_TWO_1, 9000);
16
- get0(FORTY_TWO_0);
17
- get1(FORTY_TWO_1);
18
- neg(FORTY_TWO_0);
19
- add1(FORTY_TWO_0);
20
- sub1(FORTY_TWO_1);
21
- inc(FORTY_TWO_0);
22
- inc(FORTY_TWO_1);
12
+ (0, _ob.add)(FORTY_TWO_0, FORTY_TWO_0);
13
+ (0, _ob.add)(FORTY_TWO_0, FORTY_TWO_1);
14
+ (0, _ob.add)(FORTY_TWO_1, FORTY_TWO_0);
15
+ (0, _ob.sub)(FORTY_TWO_1, FORTY_TWO_1);
16
+ (0, _ob.add)(FORTY_TWO_0, 9000);
17
+ (0, _ob.add)(FORTY_TWO_0, 9000);
18
+ (0, _ob.add)(FORTY_TWO_1, 9000);
19
+ (0, _ob.sub)(FORTY_TWO_1, 9000);
20
+ (0, _ob.get0)(FORTY_TWO_0);
21
+ (0, _ob.get1)(FORTY_TWO_1);
22
+ (0, _ob.neg)(FORTY_TWO_0);
23
+ (0, _ob.add1)(FORTY_TWO_0);
24
+ (0, _ob.sub1)(FORTY_TWO_1);
25
+ (0, _ob.inc)(FORTY_TWO_0);
26
+ (0, _ob.inc)(FORTY_TWO_1);
23
27
  },
24
28
  testUnsafeOps() {
25
- add(FORTY_TWO_1, FORTY_TWO_1);
26
- sub(FORTY_TWO_0, FORTY_TWO_1);
29
+ (0, _ob.add)(FORTY_TWO_1, FORTY_TWO_1);
30
+ (0, _ob.sub)(FORTY_TWO_0, FORTY_TWO_1);
27
31
  FORTY_TWO_0 - 1;
28
32
  FORTY_TWO_1 - 1;
29
- get0(FORTY_TWO_1);
30
- get1(FORTY_TWO_0);
31
- neg(FORTY_TWO_1);
32
- add1(FORTY_TWO_1);
33
- sub1(FORTY_TWO_0);
34
- get0(42);
35
- get1(42);
33
+ (0, _ob.get0)(FORTY_TWO_1);
34
+ (0, _ob.get1)(FORTY_TWO_0);
35
+ (0, _ob.neg)(FORTY_TWO_1);
36
+ (0, _ob.add1)(FORTY_TWO_1);
37
+ (0, _ob.sub1)(FORTY_TWO_0);
38
+ (0, _ob.get0)(42);
39
+ (0, _ob.get1)(42);
36
40
  },
37
- };
41
+ });
@@ -9,16 +9,14 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  import type {Number0, Number1} from '../ob1';
15
13
 
16
- const {add, add0, add1, get0, get1, inc, neg, sub, sub1} = require('../ob1');
14
+ import {add, add0, add1, get0, get1, inc, neg, sub, sub1} from '../ob1';
17
15
 
18
16
  const FORTY_TWO_0 = add0(42);
19
17
  const FORTY_TWO_1 = add1(42);
20
18
 
21
- module.exports = {
19
+ export default {
22
20
  testSafeOps() {
23
21
  (add(FORTY_TWO_0, FORTY_TWO_0): Number0);
24
22
  (add(FORTY_TWO_0, FORTY_TWO_1): Number1);
@@ -37,37 +35,37 @@ module.exports = {
37
35
  (inc(FORTY_TWO_1): Number1);
38
36
  },
39
37
  testUnsafeOps() {
40
- // $FlowExpectedError - adding two 1-based offsets.
38
+ // $FlowExpectedError[incompatible-type] - adding two 1-based offsets.
41
39
  add(FORTY_TWO_1, FORTY_TWO_1);
42
40
 
43
- // $FlowExpectedError - subtracting 1-based offset from 0-based offset.
41
+ // $FlowExpectedError[incompatible-type] - subtracting 1-based offset from 0-based offset.
44
42
  sub(FORTY_TWO_0, FORTY_TWO_1);
45
43
 
46
- // $FlowExpectedError - direct computations with offsets are disallowed.
44
+ // $FlowExpectedError[unsafe-arithmetic] - direct computations with offsets are disallowed.
47
45
  FORTY_TWO_0 - 1;
48
46
 
49
- // $FlowExpectedError - direct computations with offsets are disallowed.
47
+ // $FlowExpectedError[unsafe-arithmetic] - direct computations with offsets are disallowed.
50
48
  FORTY_TWO_1 - 1;
51
49
 
52
- // $FlowExpectedError - extracting a 1-based offset as a 0-based number
50
+ // $FlowExpectedError[incompatible-type] - extracting a 1-based offset as a 0-based number
53
51
  get0(FORTY_TWO_1);
54
52
 
55
- // $FlowExpectedError - extracting a 0-based offset as a 1-based number
53
+ // $FlowExpectedError[incompatible-type] - extracting a 0-based offset as a 1-based number
56
54
  get1(FORTY_TWO_0);
57
55
 
58
- // $FlowExpectedError - negating a 1-based offset
56
+ // $FlowExpectedError[incompatible-type] - negating a 1-based offset
59
57
  neg(FORTY_TWO_1);
60
58
 
61
- // $FlowExpectedError - adding 1 to an offset that's already 1-based
59
+ // $FlowExpectedError[incompatible-type] - adding 1 to an offset that's already 1-based
62
60
  add1(FORTY_TWO_1);
63
61
 
64
- // $FlowExpectedError - subtracting 1 from an offset that's already 0-based
62
+ // $FlowExpectedError[incompatible-type] - subtracting 1 from an offset that's already 0-based
65
63
  sub1(FORTY_TWO_0);
66
64
 
67
- // $FlowExpectedError - extracting an arbitrary number as a 0-based number
65
+ // $FlowExpectedError[incompatible-type] - extracting an arbitrary number as a 0-based number
68
66
  get0(42);
69
67
 
70
- // $FlowExpectedError - extracting an arbitrary number as a 1-based number
68
+ // $FlowExpectedError[incompatible-type] - extracting an arbitrary number as a 1-based number
71
69
  get1(42);
72
70
  },
73
71
  };
package/src/ob1.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ * @format
8
+ * @oncall react_native
9
+ */
10
+
11
+ export declare type Number0 = symbol & {__Number0__: string};
12
+ export declare type Number1 = symbol & {__Number1__: string};
13
+ export declare function add(a: number, b: number): number;
14
+ export declare function sub(a: number, b: number): number;
15
+ export declare function get0(x: number): number;
16
+ export declare function get1(x: number): number;
17
+ export declare function add1(x: Number0 | number): Number1;
18
+ export declare function sub1(x: Number1): Number0;
19
+ export declare function neg(x: Number0): Number0;
20
+ export declare function add0(x: number): Number0;
21
+ export declare function inc(x: number): number;
package/src/ob1.js CHANGED
@@ -1,5 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true,
5
+ });
6
+ exports.add = add;
7
+ exports.add0 = add0;
8
+ exports.add1 = add1;
9
+ exports.get0 = get0;
10
+ exports.get1 = get1;
11
+ exports.inc = inc;
12
+ exports.neg = neg;
13
+ exports.sub = sub;
14
+ exports.sub1 = sub1;
3
15
  function add(a, b) {
4
16
  return a + b;
5
17
  }
@@ -27,14 +39,3 @@ function add0(x) {
27
39
  function inc(x) {
28
40
  return x + 1;
29
41
  }
30
- module.exports = {
31
- add,
32
- get0,
33
- get1,
34
- add1,
35
- sub1,
36
- sub,
37
- neg,
38
- add0,
39
- inc,
40
- };
package/src/ob1.js.flow CHANGED
@@ -9,8 +9,6 @@
9
9
  * @oncall react_native
10
10
  */
11
11
 
12
- 'use strict';
13
-
14
12
  /* eslint-disable no-redeclare */
15
13
 
16
14
  // A type representing 0-based offsets.
@@ -27,7 +25,7 @@ declare function add(a: Number1, b: Number0): Number1;
27
25
  declare function add(a: Number0, b: Number1): Number1;
28
26
  declare function add(a: Number0, b: Number0): Number0;
29
27
 
30
- function add(a: number, b: number): number {
28
+ export function add(a: number, b: number): number {
31
29
  return a + b;
32
30
  }
33
31
 
@@ -40,41 +38,41 @@ declare function sub(a: Number1, b: Number0): Number1;
40
38
  declare function sub(a: Number0, b: Number0): Number0;
41
39
  declare function sub(a: Number1, b: Number1): Number0;
42
40
 
43
- function sub(a: number, b: number): number {
41
+ export function sub(a: number, b: number): number {
44
42
  return a - b;
45
43
  }
46
44
 
47
45
  // Get the underlying number of a 0-based offset, casting away the opaque type.
48
46
  declare function get0(x: Number0): number;
49
47
  declare function get0(x: void | null): void | null;
50
- function get0(x: number): number {
48
+ export function get0(x: number): number {
51
49
  return x;
52
50
  }
53
51
 
54
52
  // Get the underlying number of a 1-based offset, casting away the opaque type.
55
53
  declare function get1(x: Number1): number;
56
54
  declare function get1(x: void | null): void | null;
57
- function get1(x: number): number {
55
+ export function get1(x: number): number {
58
56
  return x;
59
57
  }
60
58
 
61
59
  // Add 1 to a 0-based offset, thus converting it to 1-based.
62
- function add1(x: Number0 | number): Number1 {
60
+ export function add1(x: Number0 | number): Number1 {
63
61
  return x + 1;
64
62
  }
65
63
 
66
64
  // Subtract 1 from a 1-based offset, thus converting it to 0-based.
67
- function sub1(x: Number1): Number0 {
65
+ export function sub1(x: Number1): Number0 {
68
66
  return x - 1;
69
67
  }
70
68
 
71
69
  // Negate a 0-based offset.
72
- function neg(x: Number0): Number0 {
70
+ export function neg(x: Number0): Number0 {
73
71
  return -x;
74
72
  }
75
73
 
76
74
  // Cast a number to a 0-based offset.
77
- function add0(x: number): Number0 {
75
+ export function add0(x: number): Number0 {
78
76
  return x;
79
77
  }
80
78
 
@@ -83,8 +81,6 @@ declare function inc(a: Number0): Number0;
83
81
  // Increment a 1-based offset.
84
82
  declare function inc(a: Number1): Number1;
85
83
 
86
- function inc(x: number): number {
84
+ export function inc(x: number): number {
87
85
  return x + 1;
88
86
  }
89
-
90
- module.exports = {add, get0, get1, add1, sub1, sub, neg, add0, inc};