Skip to main content
Home

Built and signed on GitHub Actions

Works with
This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score100%
Publisheda year ago (1.0.0)

Infra Standard, based on WHATWG spec reference implementation

infra

JSR codecov GitHub semantic-release: angular standard-readme compliant

Infra Standard, based on WHATWG spec reference implementation.

Table of Contents

Install

deno:

deno add @miyauci/infra

node:

npx jsr add @miyauci/infra

Usage

Data Structures

This section is is an implementation corresponding to 5. Data structures.

List

List is an ordered sequence consisting of a finite number of items.

import { List } from "@miyauci/infra";

const list = new List<number>();

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 is a list. It is available push, pop and peek instead of list operations.

import { Stack } from "@miyauci/infra";

const stack = new Stack();

stack.push(0);

const item = stack.pop();
const lastItem = stack.peek();

Queue

Queue is a list. It is available enqueue and dequeue instead of list operations.

import { Queue } from "@miyauci/infra";

const queue = new Queue();

queue.enqueue("value");

while (!queue.isEmpty) queue.dequeue();

Set

Set is a list and has the semantics that items do not overlap.

import { type List, Set } from "@miyauci/infra";

declare const listLike: List<number>;
const set = new Set<number>();

const intersection = set.intersection(listLike);
const union = set.union(listLike);
const isSubsetOf = set.isSubsetOf(listLike);
const isSupersetOf = set.isSupersetOf(listLike);

Map

Map is a finite ordered sequence of tuples, each consisting of a key and a value, with no key appearing twice.

import { Map } from "@miyauci/infra";

const map = new Map<string, string>();

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 for all APIs.

Contributing

See CONTRIBUTING.md

License

MIT © 2024 Tomoki Miyauchi

Built and signed on
GitHub Actions

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";
or

Import directly with a jsr specifier

import * as infra from "jsr:@miyauci/infra";

Add Package

pnpm i jsr:@miyauci/infra
or (using pnpm 10.8 or older)
pnpm dlx jsr add @miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";

Add Package

yarn add jsr:@miyauci/infra
or (using Yarn 4.8 or older)
yarn dlx jsr add @miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";

Add Package

vlt install jsr:@miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";

Add Package

npx jsr add @miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";

Add Package

bunx jsr add @miyauci/infra

Import symbol

import * as infra from "@miyauci/infra";