npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shogo82148/sfv

v0.2.0

Published

[![test](https://github.com/shogo82148/sfvjs/actions/workflows/test.yaml/badge.svg)](https://github.com/shogo82148/sfvjs/actions/workflows/test.yaml) [![npm](https://img.shields.io/npm/v/@shogo82148/sfv)](https://www.npmjs.com/package/@shogo82148/sfv) [![

Downloads

190

Readme

@shogo82148/sfv

test npm npm JSR

TypeScript implementation for RFC 8941 Structured Field Values for HTTP.

SYNOPSIS

Decoding Structured Field Values

import {
  Decimal,
  decodeDictionary,
  decodeItem,
  decodeList,
  DisplayString,
  Integer,
  Item,
  Token,
} from "@shogo82148/sfv";

// decoding Items
const item = decodeItem("abc");
const value = item.value;
if (value instanceof Integer) {
  // Integers
}
if (value instanceof Decimal) {
  // Decimals
}
if (typeof value === "string") {
  // Strings
}
if (value instanceof Token) {
  // Tokens
}
if (value instanceof Uint8Array) {
  // Binary Sequences
}
if (typeof value === "boolean") {
  // Booleans
}
if (value instanceof Date) {
  // Dates
}
if (value instanceof DisplayString) {
  // Display Strings
}

// decoding Lists
const list = decodeList("abc, efg");

// decoding dictionary
const dict = decodeDictionary("foo=bar, baz=qux");

Encoding Structured Field Values

import {
  Decimal,
  encodeItem,
  encodeList,
  Integer,
  Item,
  Token,
} from "@shogo82148/sfv";

// encoding Items
encodeItem(new Item(new Token("a"))); // a
encodeItem(new Item("a")); // "a"
encodeItem(new Item(new Integer(10))); // 10
encodeItem(new Item(new Decimal(3.14))); // 3.14
encodeItem(new Item(new Uint8Array([1, 2, 3]))); // :AQID:
encodeItem(new Item(true)); // ?1
encodeItem(new Item(new Date(0))); // @0
encodeItem(new Item(new DisplayString("a"))); // %"a"

// encoding Lists
encodeList([new Item(new Token("abc")), new Item(new Token("efg"))]); // abc, efg

// encoding Dictionary
const dict = new Dictionary();
dict.set("foo", new Item(new Token("bar")));
dict.set("baz", new Item(new Token("qux")));
encodeDictionary(dict); // foo=bar, baz=qux

Supported Data Types

SFV types are mapped to TypeScript types as described in this section. Note that only List, Dictionary, and Item can be in a top-level.

Values of Items

The actual type might be one of them:

| Type of SFV | Example of SFV | Type in TypeScript | Example in TypeScript | | ------------- | ------------------ | ------------------ | --------------------------- | | Integer | 10 | Integer | new Integer(10) | | Decimal | 3.14 | Decimal | new Decimal(3.14) | | String | "hello" | string | "hello" | | Token | x | Token | new Token("x") | | Byte Seq | :AQID: | Uint8Array | new Uint8Array([1, 2, 3]) | | Boolean | ?1 | boolean | true | | Date | @1659578233 | Date | new Date(1659578233000) | | DisplayString | %"f%c3%bc%c3%bc" | DisplayString | new DisplayString("füü") | | Inner List | (1 2) | InnerList | new InnerList() |

Parameters of Items

Parameters are ordered map of key-value pairs. They are decoded to Parameters.

Lists

Lists are decoded to List.

Inner Lists

Inner Lists are decoded to InnerList.

Dictionaries

Dictionaries are ordered maps of key-value pairs. They are decoded to Dictionary.