https://github.com/tomokimiyauci/infra
Infra Standard, based on WHATWG spec reference implementation
https://github.com/tomokimiyauci/infra
infra whatwg
Last synced: 3 months ago
JSON representation
Infra Standard, based on WHATWG spec reference implementation
- Host: GitHub
- URL: https://github.com/tomokimiyauci/infra
- Owner: TomokiMiyauci
- License: mit
- Created: 2024-08-13T06:14:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-24T02:23:53.000Z (about 1 year ago)
- Last Synced: 2024-10-20T03:11:10.758Z (12 months ago)
- Topics: infra, whatwg
- Language: TypeScript
- Homepage: https://jsr.io/@miyauci/infra
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# infra
[](https://jsr.io/@miyauci/infra)
[](https://codecov.io/gh/TomokiMiyauci/infra)
[](https://github.com/TomokiMiyauci/infra/blob/main/LICENSE)
[](https://github.com/semantic-release/semantic-release)
[](https://github.com/RichardLitt/standard-readme)[Infra Standard](https://infra.spec.whatwg.org/), based on WHATWG spec reference
implementation.## Table of Contents
- [Install](#install)
- [Usage](#usage)
- [Data Structures](#data-structures)
- [List](#list)
- [Stack](#stack)
- [Queue](#queue)
- [Set](#set)
- [Map](#map)
- [API](#api)
- [Contributing](#contributing)
- [License](#license)## Install
deno:
```bash
deno add @miyauci/infra
```node:
```bash
npx jsr add @miyauci/infra
```## Usage
### Data Structures
This section is is an implementation corresponding to
[5. Data structures](https://infra.spec.whatwg.org/#data-structures).#### List
[List](https://infra.spec.whatwg.org/#list) is an ordered sequence consisting of
a finite number of items.```ts
import { List } from "@miyauci/infra";const list = new List();
list.size;
list.isEmpty;
list[0];list.append(0);
list.prepend(1);
list.empty();
list.extend([2, 3, 4]);
list.insert(3, Infinity);
list.replace(3, 6);
list.remove(2);
list.removeIf((item) => item % 3 === 1);for (const item of list) {}
const has = list.contains(3);
const other = list.clone();
const indices = list.indices();
```#### Stack
[Queue](https://infra.spec.whatwg.org/#queues) is a [list](#list). It is
available `push`, `pop` and `peek` instead of list operations.```ts
import { Stack } from "@miyauci/infra";const stack = new Stack();
stack.push(0);
const item = stack.pop();
const lastItem = stack.peek();
```#### Queue
[Queue](https://infra.spec.whatwg.org/#queues) is a [list](#list). It is
available `enqueue` and `dequeue` instead of list operations.```ts
import { Queue } from "@miyauci/infra";const queue = new Queue();
queue.enqueue("value");
while (!queue.isEmpty) queue.dequeue();
```#### Set
[Set](https://infra.spec.whatwg.org/#ordered-set) is a [list](#list) and has the
semantics that items do not overlap.```ts
import { type List, Set } from "@miyauci/infra";declare const listLike: List;
const set = new Set();const intersection = set.intersection(listLike);
const union = set.union(listLike);
const isSubsetOf = set.isSubsetOf(listLike);
const isSupersetOf = set.isSupersetOf(listLike);
```#### Map
[Map](https://infra.spec.whatwg.org/#ordered-map) is a finite ordered sequence
of tuples, each consisting of a key and a value, with no key appearing twice.```ts
import { Map } from "@miyauci/infra";const map = new Map();
const size = map.size;
const isEmpty = map.isEmpty;map.set("key", "value");
map.get("key");
map.remove("key");
map.clear();const has = map.exists("key");
const keys = map.keys();
const values = map.values();
const cloned = map.clone();
const sorted = map.sort("asc", (left, right) => left[0] < right[0]);
```## API
See [jsr doc](https://jsr.io/@miyauci/infra) for all APIs.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md)
## License
[MIT](LICENSE) © 2024 Tomoki Miyauchi