open-index/open-npm huggingface dataset:
npm package: @libn/aead
Description: XChaCha20-Poly1305 authenticated encryption and XChaCha20 stream cipher.
Latest version: 0.4.2

# @libn/aead

XChaCha20-Poly1305 authenticated encryption and XChaCha20 stream cipher.

## default

[ChaCha20-Poly1305](https://www.rfc-editor.org/rfc/rfc8439) AEAD scheme with
[extended nonces](https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha).

```ts
import { cipher, decrypt, encrypt } from "@libn/aead";
import { assert, assertEquals, assertNotEquals } from "@std/assert";

const key = crypto.getRandomValues(new Uint8Array(32));
const plaintext = crypto.getRandomValues(new Uint8Array(100));
const data = crypto.getRandomValues(new Uint8Array(100));

const secret = encrypt(key, plaintext, data);
assert(secret);
assertEquals(decrypt(key, secret, data), plaintext);
assertEquals(decrypt(key, secret), null);

// Or stream directly
const ciphertext = new Uint8Array(plaintext);
const iv = crypto.getRandomValues(new Uint8Array(24));
cipher(key, iv, ciphertext);
assertNotEquals(ciphertext, plaintext);
cipher(key, iv, ciphertext);
assertEquals(ciphertext, plaintext);
```
npm package: @libn/csv
Description: Comma-separated values.
Latest version: 0.4.0

# @libn/csv

Comma-separated values.

## parse

[Parse](https://github.com/fabiospampinato/csv-simple-parser)
[RFC 4180](https://www.rfc-editor.org/rfc/rfc4180) CSV.

```ts
import { deCsv } from "@libn/csv/parse";
import { assertEquals } from "@std/assert";

assertEquals(
  deCsv("aaa,bbb,ccc\nzzz,yyy,xxx\n"),
  [["aaa", "bbb", "ccc"], ["zzz", "yyy", "xxx"]],
);
```

## stringify

Stringify [RFC 4180](https://www.rfc-editor.org/rfc/rfc4180) CSV.

```ts
import { enCsv } from "@libn/csv/stringify";
import { assertEquals } from "@std/assert";

assertEquals(
  enCsv([["aaa", "bbb", "ccc"], ["zzz", "yyy", "xxx"]]),
  "aaa,bbb,ccc\nzzz,yyy,xxx\n",
);
```
npm package: @libn/ecc
Description: Curve25519 key exchange and digital signatures.
Latest version: 0.4.2

# @libn/ecc

Curve25519 key exchange and digital signatures.

## x25519

[RFC 7748](https://www.rfc-editor.org/rfc/rfc7748) key exchange.

```ts
import { derive, exchange } from "@libn/ecc/x25519";
import { assertEquals } from "@std/assert";

const secretKeyA = crypto.getRandomValues(new Uint8Array(32));
const secretKeyB = crypto.getRandomValues(new Uint8Array(32));

const publicKeyA = derive(secretKeyA); // A sends to B
const publicKeyB = derive(secretKeyB); // B sends to A

assertEquals(
  exchange(secretKeyA, publicKeyB),
  exchange(secretKeyB, publicKeyA),
);
```

## ed25519

[RFC 8032](https://www.rfc-editor.org/rfc/rfc8032) digital signatures.

```ts
import { generate, sign, verify } from "@libn/ecc/ed25519";
import { assert } from "@std/assert";

const message = crypto.getRandomValues(new Uint8Array(100));
const secretKey = crypto.getRandomValues(new Uint8Array(32));

const signature = sign(secretKey, message);
assert(verify(generate(secretKey), message, signature));
```

## convert

Ed25519-to-X25519 key conversion.

```ts
import { generate } from "@libn/ecc/ed25519";
import { exchange } from "@libn/ecc/x25519";
import { convertPublic, convertSecret } from "@libn/ecc/convert";
import { assertEquals } from "@std/assert";

const secretKeyA = crypto.getRandomValues(new Uint8Array(32));
const secretKeyB = crypto.getRandomValues(new Uint8Array(32));

const publicKeyA = generate(secretKeyA); // A sends to B
const publicKeyB = generate(secretKeyB); // B sends to A

assertEquals(
  exchange(convertSecret(secretKeyA), convertPublic(publicKeyB)),
  exchange(convertSecret(secretKeyB), convertPublic(publicKeyA)),
);
```
npm package: @libn/element
Description: Better-typed [createElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement) with a mostly-JSX-compatible interface.
Latest version: 0.4.0

# @libn/element

Better-typed
[createElement](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement)
with a mostly-JSX-compatible interface.

## default

```ts
// Only necessary in non-browser environments.
import { parseHTML } from "linkedom";
globalThis.document = parseHTML("").document;

import { h } from "@libn/element";
import { assertEquals } from "@std/assert";

const div = h("div", {
  id: "id",
  style: { color: "#111", boxSizing: "border-box" },
}, h("span", { class: "class" }, "text!")); // type is HTMLDivElement
assertEquals(
  div.outerHTML,
  '<div id="id" style="color:#111;box-sizing:border-box"><span class="class">text!</span></div>',
);
```
npm package: @libn/fuzzy
Description: Fuzzy-match strings.
Latest version: 0.4.0

# @libn/fuzzy

Fuzzy-match strings.

## default

Check for [general presence](https://github.com/bevacqua/fuzzysearch) or
calculate
[Levenshtein distance](https://github.com/ka-weihe/fastest-levenshtein).

```ts
import { distance, includes } from "@libn/fuzzy";
import { assertEquals } from "@std/assert";

assertEquals(includes("a b c", "abc"), true);
assertEquals(distance("a b c", "abc"), 2);
```
npm package: @libn/hash
Description: Cryptographic hash functions.
Latest version: 0.4.1

# @libn/hash

Cryptographic hash functions.

## sha2

[SHA-224, SHA-256, SHA-384, and SHA-512](https://www.rfc-editor.org/rfc/rfc6234).

```ts
import { sha256 } from "@libn/hash/sha2";
import { assertEquals } from "@std/assert";

const data = crypto.getRandomValues(new Uint8Array(100));
assertEquals(sha256(data).buffer, await crypto.subtle.digest("SHA-256", data));
```

## hmac

[HMAC-SHA256](https://www.rfc-editor.org/rfc/rfc2104) and
[HKDF-SHA256](https://www.rfc-editor.org/rfc/rfc5869).

```ts
import { hkdf, hmac } from "@libn/hash/hmac";
import { assertEquals } from "@std/assert";

const key = crypto.getRandomValues(new Uint8Array(32));
const data = crypto.getRandomValues(new Uint8Array(100));
assertEquals(
  hmac(key, data).buffer,
  await crypto.subtle.sign(
    "HMAC",
    await crypto.subtle.importKey(
      "raw",
      key,
      { name: "HMAC", hash: "SHA-256" },
      false,
      ["sign"],
    ),
    data,
  ),
);
assertEquals(
  hkdf(key).buffer,
  await crypto.subtle.deriveBits(
    {
      name: "HKDF",
      hash: "SHA-256",
      info: new Uint8Array(),
      salt: new Uint8Array(),
    },
    await crypto.subtle.importKey("raw", key, "HKDF", false, ["deriveBits"]),
    256,
  ),
);
```

## blake2

[BLAKE2s and BLAKE2b](https://www.rfc-editor.org/rfc/rfc7693).

```ts
import { blake2b, blake2s } from "@libn/hash/blake2";
import { assertEquals } from "@std/assert";
import { crypto } from "@std/crypto";

const data = crypto.getRandomValues(new Uint8Array(100));
assertEquals(blake2s(data).buffer, await crypto.subtle.digest("BLAKE2S", data));
assertEquals(blake2b(data).buffer, await crypto.subtle.digest("BLAKE2B", data));
```

## blake3

[BLAKE3](https://github.com/BLAKE3-team/BLAKE3) hashing, keyed hashing, and key
derivation.

```ts
import { blake3 } from "@libn/hash/blake3";
import { assertEquals, assertNotEquals } from "@std/assert";
import { crypto } from "@std/crypto";

const data = crypto.getRandomValues(new Uint8Array(100));
const key1 = crypto.getRandomValues(new Uint8Array(32));
const key2 = crypto.getRandomValues(new Uint8Array(32));

// Mode `hash`
assertEquals(blake3(data).buffer, await crypto.subtle.digest("BLAKE3", data));

// Mode `keyed_hash`
assertNotEquals(blake3(data, key1, 512), blake3(data, key2, 512));

// Mode `derive_key`
assertNotEquals(blake3(key1), blake3(key2));
assertNotEquals(blake3(key1, "context 1"), blake3(key1, "context 2"));
```
npm package: @libn/json
Description: JSON schema types, builders, and validators.
Latest version: 0.5.0

# @libn/json

JSON schema types, builders, and validators.

## schema

Subset of [Draft 2020-12](https://json-schema.org/draft/2020-12).

```ts
import { arr, bit, nil, num, obj, opt, str } from "@libn/json/schema";
import { assertEquals } from "@std/assert";

assertEquals(
  // Each function returns a regular object
  obj({
    boolean: bit(),
    integer: num({ multipleOf: 1 }),
    nullable: nil(opt([false, 0, ""])),
    datetimes: arr(str({ format: "date-time" }), { uniqueItems: true }),
  }),
  {
    type: "object",
    properties: {
      boolean: { type: "boolean" },
      integer: { type: "number", multipleOf: 1 },
      nullable: { oneOf: [{ type: "null" }, { enum: [false, 0, ""] }] },
      datetimes: {
        type: "array",
        items: { type: "string", format: "date-time" },
        uniqueItems: true,
      },
    },
    additionalProperties: false,
    // All properties are required unless specified otherwise
    required: ["boolean", "integer", "nullable", "datetimes"],
  },
);
```

## check

Validate, or parse to either valid data or error
[pointers](https://www.rfc-editor.org/rfc/rfc6901).

```ts
import { compile, is, point, to } from "@libn/json/check";
import { assert, assertEquals } from "@std/assert";

const schema = {
  type: "array",
  items: { type: "number", multipleOf: 2 },
} as const;
const check = compile(schema);

// Fast-path type predicate
assertEquals(is(check, [4, 24]), true);

// Parse a deep copy or an array of error pointers
const instance = [0, true];
const result = to(check, instance);
assert(result.error);
assertEquals(result.value, [{
  type: "/items/type", // path to failed constraint
  data: "/1", // path to invalid value
}]);
assertEquals(point(schema, result.value[0].type), "number"); // expected number
assertEquals(point(instance, result.value[0].data), true); // but got this
```
npm package: @libn/nchf
Description: Non-cryptographic hash functions.
Latest version: 0.4.0

# @libn/nchf

Non-cryptographic hash functions.

## oaat

[32-bit seeded hash](https://github.com/rurban/smhasher/commit/3931fd6f723f4fb2afab6ef9a628912220e90ce7/).

```ts
import { oaat32 } from "@libn/nchf/oaat";

oaat32(new Uint8Array([0, 1, 2, 3]), 0); // e7d12840
oaat32(new Uint8Array([0, 1, 2, 3]), 1); // 80ea5ab8
oaat32(new Uint8Array([0, 1, 2, 4]), 0); // 9080e04c
```

## a5hash

[32-bit and 64-bit seeded hashes](https://github.com/avaneev/a5hash).

```ts
import { a5hash32, a5hash64 } from "@libn/nchf/a5hash";

a5hash32(new Uint8Array([0, 1, 2, 3]), 0); // 5c78d6a6
a5hash32(new Uint8Array([0, 1, 2, 3]), 1); // 97c63c95
a5hash32(new Uint8Array([0, 1, 2, 4]), 0); // d252f967

a5hash64(new Uint8Array([0, 1, 2, 3]), 0n); // 72585f77d63bbd56
a5hash64(new Uint8Array([0, 1, 2, 3]), 1n); // 7b8fd954a91ba3ed
a5hash64(new Uint8Array([0, 1, 2, 4]), 0n); // c6ab2ffce1a74b56
```

## halfsiphash

[32-bit and 64-bit keyed hashes](https://github.com/veorq/SipHash).

```ts
import { halfsiphash32, halfsiphash64 } from "@libn/nchf/halfsiphash";

const key0 = new Uint8Array(8);
const key1 = key0.with(0, 1);
halfsiphash32(new Uint8Array([0, 1, 2, 3]), key0); // abeeaa6d
halfsiphash32(new Uint8Array([0, 1, 2, 3]), key1); // f167aa09
halfsiphash32(new Uint8Array([0, 1, 2, 4]), key0); // 26affe00

halfsiphash64(new Uint8Array([0, 1, 2, 3]), key0); // 5ad7d3cf8dcbf2b9
halfsiphash64(new Uint8Array([0, 1, 2, 3]), key1); // a2c6ee6ab51b12fa
halfsiphash64(new Uint8Array([0, 1, 2, 4]), key0); // 6dbe762a1eb369ba
```
npm package: @libn/paseto
Description: [Platform-agnostic security tokens](https://paseto.io/).
Latest version: 0.4.0

# @libn/paseto

[Platform-agnostic security tokens](https://paseto.io/).

## local

Version 4 symmetric authenticated encryption.

```ts
import { deLocal, enLocal, keyLocal } from "@libn/paseto/local4";
import { assert, assertEquals } from "@std/assert";

const key = keyLocal();
const payload = new TextEncoder().encode("Local message");
const footer = crypto.getRandomValues(new Uint8Array(20));

const token = enLocal(key, payload, footer);
assert(token);
assertEquals(deLocal(key, token), { payload, footer });
```

## public

Version 4 asymmetric authentication.

```ts
import { dePublic, enPublic, keyPair } from "@libn/paseto/public4";
import { assert, assertEquals } from "@std/assert";

const keys = keyPair();
const payload = new TextEncoder().encode("Public message");
const footer = crypto.getRandomValues(new Uint8Array(20));

const token = enPublic(keys.secret, payload, footer);
assert(token);
assertEquals(dePublic(keys.public, token), { payload, footer });
```
npm package: @libn/query
Description: Better-typed [querySelector](https://dev.mozilla.org/docs/Web/API/Element/querySelector) and [querySelectorAll](https://dev.mozilla.org/docs/Web/API/Element/querySelectorAll).
Latest version: 0.4.0

# @libn/query

Better-typed
[querySelector](https://dev.mozilla.org/docs/Web/API/Element/querySelector) and
[querySelectorAll](https://dev.mozilla.org/docs/Web/API/Element/querySelectorAll).

## default

```ts
import { queryFirst } from "@libn/query";
import { parseHTML } from "linkedom";
import { assertEquals } from "@std/assert";

const span = queryFirst(
  "div#i > span.c",
  // Only necessary in non-browser environments.
  parseHTML('<div id="i"><span class="c">text</span></div>').document,
); // type is HTMLSpanElement
assertEquals(span?.textContent, "text");
```
npm package: @libn/result
Description: Simple result handling.
Latest version: 0.5.0

# @libn/result

Simple result handling.

## default

Handle errors like
[Rust's `std::result`](https://doc.rust-lang.org/std/result/#the-question-mark-operator-)
and [Go's (in)famous `if err != nil`](https://go.dev/blog/errors-are-values).

```ts
import { as, open, seal, wrap } from "@libn/result";

// Define possible errors and their corresponding values
type Errors = {
  NonStringInput: unknown;
  InvalidJson: Error;
};
const parse = (raw: unknown) =>
  // Parameterize symbol with errors
  wrap(as<Errors>(), (no) => {
    // Throw as expression
    const json = typeof raw === "string" ? raw : no("NonStringInput", raw);
    // Wrap unsafe functions
    const result = seal(JSON.parse, "InvalidJson")(json);
    // Re-throw when types are compatible
    return open(result, { InvalidJson: no });
  });
```
npm package: @libn/router
Description: Simple HTTP router.
Latest version: 0.5.0

# @libn/router

Simple HTTP router.

## default

Define path parameters by prefixing their names with a `#`. Only one handler
runs per request.

```ts ignore
import { Router } from "@libn/router";

// Parameterize if passing extra arguments to `router.fetch`
const router = new Router<[Deno.Addr]>().route("GET /hello", ({ url }) => {
  const name = url.searchParams.get("name");
  return name ? `Hello, ${name}!` : 400;
});
router.route("POST /upload/#user", async ({ path, request }) => {
  const result = await uploadFile({
    user: path.user,
    blob: await request.blob(),
  });
  if (!result.state) return Error(result.value);
});

// Use in `Deno.serve` callback
Deno.serve(router.fetch);

// Export as `Deno.ServeDefaultExport` for `deno serve`
export default router satisfies Deno.ServeDefaultExport;

// Use in `Bun.serve`
Bun.serve(router);

// Export as a Cloudflare Workers ES Module
interface Env {
  SECRET_KEY: string;
}
export default new Router<[Env, ExecutionContext]>().route(
  "GET /key",
  (_, env) => env.SECRET_KEY,
) satisfies ExportedHandler<Env>;
```
npm package: @libn/signal
Description: Reactive state.
Latest version: 0.4.0

# @libn/signal

Reactive state.

## default

System derived from
[alien-signals](https://github.com/stackblitz/alien-signals).

```ts
import { derive, effect, signal } from "@libn/signal";
import { assertEquals } from "@std/assert";

const count = signal(0);
const half = derive(() => count() >> 1);

let called = 0;
effect(() => {
  half();
  ++called;
});
assertEquals(called, 1);
count(1);
assertEquals(called, 1);
count(2);
assertEquals(called, 2);
```
npm package: @libn/types
Description: Utility types and tests.
Latest version: 0.4.0

# @libn/types

Utility types and tests.

## default

Compose and compare types.

```ts
import { type Is, type Json, type Tuple, type } from "@libn/types";

const object = { a: null, b: null } satisfies Json;
type<Is<Tuple<keyof typeof object>, ["a", "b"]>>(true);
```
npm package: @libn/utf
Description: Process UTF-8 and UTF-16.
Latest version: 0.4.3

# @libn/utf

Process UTF-8 and UTF-16.

## default

Escape strings before including them in
[HTML](https://dev.mozilla.org/docs/Glossary/Character_reference) or
[regex](https://dev.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape).

```ts
import { unhtml, unrexp } from "@libn/utf";
import { assertMatch } from "@std/assert";

assertMatch(unhtml("<script>alert(1)</script>"), /^[^<>]*$/);
assertMatch("(?:[\n])", RegExp(unrexp("(?:[\n])")));
```

Restrict strings to [RFC 9839](https://www.rfc-editor.org/rfc/rfc9839.txt)
Unicode Assignables subset, or at least replace lone surrogates.

```ts
import { uncode, unlone } from "@libn/utf";
import { assertEquals } from "@std/assert";

const string = "\ud800\0";
assertEquals(uncode(string), "\ufffd\ufffd");
assertEquals(unlone(string), "\ufffd\0");
```

Remove nonstandard
[breaks](https://dev.mozilla.org/docs/Web/JavaScript/Reference/Lexical_grammar#line_terminators)
and [diacritics](https://wikipedia.org/wiki/Diacritic).

```ts
import { unline, unmark } from "@libn/utf";
import { assertEquals } from "@std/assert";

const string = "\r\n\xf1";
assertEquals(unline(string), "\n\xf1");
assertEquals(unmark(string), "\r\nn");
```

[Case fold](https://www.unicode.org/Public/UNIDATA/CaseFolding.txt) strings to
compare them case-insensitively.

```ts
import { uncase } from "@libn/utf";
import { assertEquals, assertNotEquals } from "@std/assert";

const one = "FUSS", two = "Fu\xdf";
assertNotEquals(one, two);
assertEquals(uncase(one), uncase(two));
```
npm package: @libn/words
Description: Convert between [case formats]((https://en.wikipedia.org/wiki/Naming_convention_(programming)#Examples_of_multiple-word_identifier_formats)).
Latest version: 0.4.1

# @libn/words

Convert between
[case formats]((https://en.wikipedia.org/wiki/Naming_convention_(programming)#Examples_of_multiple-word_identifier_formats)).

## default

```ts
import {
  lowerCamel,
  lowerKebab,
  lowerSnake,
  upperCamel,
  upperKebab,
  upperSnake,
} from "@libn/words";
import { assertEquals } from "@std/assert";

const words = "This is a sequence of words";

assertEquals(lowerCamel(words), "thisIsASequenceOfWords");
assertEquals(upperCamel(words), "ThisIsASequenceOfWords");
assertEquals(lowerKebab(words), "this-is-a-sequence-of-words");
assertEquals(upperKebab(words), "This-Is-A-Sequence-Of-Words");
assertEquals(lowerSnake(words), "this_is_a_sequence_of_words");
assertEquals(upperSnake(words), "THIS_IS_A_SEQUENCE_OF_WORDS");
```