Skip to content

Commit 6379fe9

Browse files
authored
Make dedicated api.md from source
1 parent 1e39cf1 commit 6379fe9

File tree

5 files changed

+644
-47
lines changed

5 files changed

+644
-47
lines changed

README.md

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const len = mr.length(ranges1); // 10
7979

8080
## Creating a _normalized_ MultiIntegerRange
8181

82-
The fundamental data structure of this package is a **normalized** array of `[min, max]` tuples, as shown below. Here, "normalized" means the range data is in the smallest possible representation and is sorted in ascending order. You can denote an unbounded range using the JavaScript constant `Infinity`.
82+
The fundamental data structure of this package is a **normalized** array of `[min, max]` tuples, as shown below. Here, "normalized" means the range data is in the smallest possible representation and is sorted in ascending order. You can denote an unbounded (aka infinite) range using the JavaScript constant `Infinity`.
8383

8484
<!-- prettier-ignore -->
8585
```ts
@@ -144,30 +144,7 @@ console.log(
144144

145145
## API Reference
146146

147-
All functions are _pure_; they do not change the input data nor do they have any side effects. All functions are exported as named exports. All `MultiIntegerRange`s returned by these functions are normalized. `MIR` is just a short alias for `MultiIntegerRange` (also available in d.ts).
148-
149-
- `parse(data: string, options?: Options): MIR` Parses the given string. See below for the options.
150-
- `normalize(data?:(number | Range)[] | number): MIR` Normalizes the given number or the array of numbers/Ranges.
151-
- `initialize(data?: (number | Range)[] | number | string, options?: Options)`: Conditionally calls either `parse` or `normalize` and returns a new MultiIntegerRange. This takes an "Initializer" in version &le; 4.
152-
- `append(a: MIR, b: MIR): MIR` Appends the two values.
153-
- `subtract(a: MIR, b: MIR): MIR` Subtracts `b` from `a`.
154-
- `intersect(a: MIR, b: MIR): MIR` Calculates the interesction, i.e., integers that belong to both `a` and `b`.
155-
- `has(a: MIR, b: MIR): boolean` Checks if `b` is equal to or a subset of `a`.
156-
- `length(data: MIR): number` Calculates how many numbers are effectively included in the given data (i.e., 5 for '3,5-7,9'). Returns Inifnity for unbounded ranges.
157-
- `equals(a: MIR, b: MIR): boolean` Checks if `a` and `b` contains the same range data. (If you like, you can use other deep-equal utilities instead.)
158-
- `isUnbounded(data: MIR): boolean` Returns true if the instance is unbounded.
159-
- `min(data: MIR): number | undefined` Returns the minimum integer. May return -Infinity.
160-
- `max(data: MIR): number | undefined` Returns the maxinum integer. May return Infinity.
161-
- `tail(data: MIR): MIR` Removes the minimum integer.
162-
- `init(data: MIR): MIR` Removes the maxinum integer.
163-
- `stringify(data: MIR): string` Returns the string respresentation of the given data (the opposite of parse()).
164-
- `flatten(data: MIR): number[]` Builds a flat array of integers. This may be slow and memory-consuming for large ranges such as '1-10000'.
165-
- `iterate(data: MIR): Iterable<number>` Returns an ES6 iterable object. See the description below.
166-
167-
Available `options` that can be passed to `parse()`:
168-
169-
- `parseNegative` (boolean, default = false): Enables parsing negative ranges (e.g., `(-10)-(-3)`).
170-
- `parseUnbounded` (boolean, default = false): Enables parsing unbounded ranges (e.g., `-5,10-`).
147+
See [api-reference.md](api-reference.md).
171148

172149
## Iteration
173150

@@ -197,11 +174,11 @@ Intersection is especially useful to "trim" unbounded ranges.
197174

198175
```ts
199176
const userInput = '-5,15-';
200-
const pagesInMyDoc = [[1, 20]]; // '1-20'
177+
const pagesInMyDoc = [[1, 20]]; // (1-20)
201178
const pagesToPrint = mr.intersect(
202179
mr.parse(userInput, { parseUnbounded: true }),
203180
pagesInMyDoc
204-
);
181+
); // [[1, 5], [15, 20]]
205182
for (const page of mr.iterate(pagesToPrint)) await printPage(page);
206183
```
207184

0 commit comments

Comments
 (0)