Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 82 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ buf.insert(11, "\n");
assertEquals(buf.count, 12);
assertEquals(buf.line_count, 3);
assertEquals(buf.read(0).toArray().join(""), "Lorem\nipsum\n");
assertEquals(buf.read([0, 0], [1, 0]).toArray().join(""), "Lorem\n");
assertEquals(buf.read([1, 0], [2, 0]).toArray().join(""), "ipsum\n");
assertEquals(buf.read([2, 0], [3, 0]).toArray().join(""), "");
assertEquals(buf.read2([0, 0], [1, 0]).toArray().join(""), "Lorem\n");
assertEquals(buf.read2([1, 0], [2, 0]).toArray().join(""), "ipsum\n");
assertEquals(buf.read2([2, 0], [3, 0]).toArray().join(""), "");

buf.delete(0, 6);
buf.delete(5, 6);

assertEquals(buf.count, 5);
assertEquals(buf.line_count, 1);
assertEquals(buf.read(0).toArray().join(""), "ipsum");
assertEquals(buf.read([0, 0], [1, 0]).toArray().join(""), "ipsum");
assertEquals(buf.read2([0, 0], [1, 0]).toArray().join(""), "ipsum");
```

## API
Expand Down Expand Up @@ -214,12 +214,12 @@ assertEquals(buf.read(0).toArray().join(""), "0");
### `TextBuf.proto.read()`

Returns text in the buffer's section, specified by start (inclusive) and end
(exclusive) positions.
(exclusive) indexes.

Syntax

```ts ignore
read(start: Position, end?: Position): Generator<string>
*read(start: number, end = Number.MAX_SAFE_INTEGER): Generator<string>
```

Example
Expand All @@ -232,18 +232,39 @@ const buf = new TextBuf("Lorem\nipsum");

assertEquals(buf.read(0).toArray().join(""), "Lorem\nipsum");
assertEquals(buf.read(6).toArray().join(""), "ipsum");
assertEquals(buf.read([0, 0], [1, 0]).toArray().join(""), "Lorem\n");
assertEquals(buf.read([1, 0], [2, 0]).toArray().join(""), "ipsum");
```

### `TextBuf.proto.read2()`

Returns text in the buffer's section, specified by start (inclusive) and end
(exclusive) positions.

Syntax

```ts ignore
*read2(start: [number, number], end?: [number, number]): Generator<string>
```

Example

```ts
import { assertEquals } from "jsr:@std/assert";
import { TextBuf } from "jsr:@eu-ge-ne/text-buf";

const buf = new TextBuf("Lorem\nipsum");

assertEquals(buf.read2([0, 0], [1, 0]).toArray().join(""), "Lorem\n");
assertEquals(buf.read2([1, 0], [2, 0]).toArray().join(""), "ipsum");
```

### `TextBuf.proto.insert()`

Inserts text into the buffer at the specified position
Inserts text into the buffer at the specified index.

Syntax

```ts ignore
insert(pos: Position, text: string): void
insert(i: number, text: string): void
```

Example
Expand All @@ -255,7 +276,31 @@ import { TextBuf } from "jsr:@eu-ge-ne/text-buf";
const buf = new TextBuf();

buf.insert(0, "Lorem");
buf.insert([0, 5], " ipsum");
buf.insert(5, " ipsum");

assertEquals(buf.read(0).toArray().join(""), "Lorem ipsum");
```

### `TextBuf.proto.insert2()`

Inserts text into the buffer at the specified position.

Syntax

```ts ignore
insert2(pos: [number, number], text: string): void
```

Example

```ts
import { assertEquals } from "jsr:@std/assert";
import { TextBuf } from "jsr:@eu-ge-ne/text-buf";

const buf = new TextBuf();

buf.insert2([0, 0], "Lorem");
buf.insert2([0, 5], " ipsum");

assertEquals(buf.read(0).toArray().join(""), "Lorem ipsum");
```
Expand Down Expand Up @@ -311,12 +356,12 @@ assertEquals(buf.read(0).toArray().join(""), "");
### `TextBuf.proto.delete()`

Removes characters in the buffer's section, specified by start (inclusive) and
end (exclusive) positions.
end (exclusive) indexes.

Syntax

```ts ignore
delete(start: Position, end?: Position): void
delete(start: number, end = Number.MAX_SAFE_INTEGER): void
```

Example
Expand All @@ -332,6 +377,30 @@ buf.delete(5, 11);
assertEquals(buf.read(0).toArray().join(""), "Lorem");
```

### `TextBuf.proto.delete2()`

Removes characters in the buffer's section, specified by start (inclusive) and
end (exclusive) positions.

Syntax

```ts ignore
delete2(start: [number, number], end?: [number, number]): void
```

Example

```ts
import { assertEquals } from "jsr:@std/assert";
import { TextBuf } from "jsr:@eu-ge-ne/text-buf";

const buf = new TextBuf("Lorem ipsum");

buf.delete2([0, 5], [0, 11]);

assertEquals(buf.read(0).toArray().join(""), "Lorem");
```

## Benchmarks

### Create
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 99%
informational: true
patch:
default:
target: 99%
informational: true
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eu-ge-ne/text-buf",
"version": "0.13.6",
"version": "0.14.0",
"license": "MIT",
"exports": "./src/mod.ts",
"imports": {
Expand Down
1 change: 0 additions & 1 deletion src/mod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export type { Node } from "./node.ts";
export type { Pos } from "./position.ts";
export { TextBuf } from "./text-buf.ts";
7 changes: 0 additions & 7 deletions src/position.ts

This file was deleted.

Loading