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

shiorijk

v1.1.5

Published

SHIORI/3.x Parser/Container

Downloads

82

Readme

ShioriJK - SHIORI/3.x パーサ/コンテナ

npm npm license npm download total npm download by month Bower Bower

Dependency Status devDependency Status Travis Build Status AppVeyor Build Status codecov.io Codacy Badge

つまるところ、栞はJKである

インストール

npm install shiorijk

or

bower install shiorijk

ShioriJKとは何か?

伺かのSHIORIサブシステム構築のためのSHIORIプロトコルパーサとコンテナのJavaScript(TypeScript)による実装です。

JavaScriptで栞を組みたくなった場合にお使いください。

ShioriJKとは何でないか?

ShioriJKはSHIORIプロトコルパーサとコンテナのみを実装しているライブラリであり、これ単体で栞とすることは出来ません。

利用方法概要

SHIORIリクエスト/レスポンスあるいはその断片を渡すとてきとうに解釈してコンテナに入れて返します。 またコンテナからリクエスト/レスポンス文字列を生成することも出来ます。

現在のところSHIORI/3.xのみを扱えます。(SHIORI/2.xにも対応していますが、同一ヘッダが複数存在する一部リクエストを正しくパースできません。)

example/example.ts

import * as ShioriJK from "shiorijk";
// const ShioriJK = require("shiorijk"); // also OK

// ---------- リクエストのパース ----------

// 1つのトランザクションをパース
const requestParser = new ShioriJK.Shiori.Request.Parser();
const requestStr =
  "GET SHIORI/3.0\r\n" +
  "Charset: UTF-8\r\n" +
  "Sender: embryo\r\n" +
  "ID: OnBIFFComplete\r\n" +
  "Reference0: 2\r\n" +
  "Reference1: 1024\r\n" +
  "Reference2: mail.example.com\r\n" +
  "Reference3: 1\r\n" +
  "Reference4: Subject: foo\x01X-Mailer: sendmail\x02Subject: bar\x01X-Mailer: Sylpheed\r\n" +
  "Reference5: 512\x01512\r\n" +
  "Reference6: [email protected]\[email protected]\r\n" +
  "\r\n";
const request = requestParser.parse(requestStr);
console.log(request.request_line.method === "GET"); // リクエスト行の情報
console.log(request.headers.get("ID") === "OnBIFFComplete"); // ヘッダ値を取得
console.log(request.headers.ID === "OnBIFFComplete"); // よく使うヘッダへのショートカット
console.log(request.headers.Reference(1) === "1024"); // Reference*へのショートカット
console.log(request.headers.references().length === 7); // 全てのReference*の値を取得
console.log((request.headers.get_separated("Reference6") || [])[0] === "[email protected]"); // \x01で区切られた値の取得
console.log((request.headers.get_separated2("Reference4") || [])[1][0] === "Subject: bar"); // \x01と\x02で区切られた値の取得

// チャンクを元にパース(HTTPのように)
let parseResult;
parseResult = requestParser.parse_chunk("GET SHIORI/3.0\r\nCharset: UTF-8\r\n");
console.log(parseResult.state === "continue");
parseResult = requestParser.parse_chunk("ID: version\r\n\r\n");
console.log(parseResult.state === "end");
console.log(parseResult.results.length === 1);
console.log(parseResult.results[0].headers.ID === "version");

// 行ごとにパース
parseResult = requestParser.parse_lines(["GET SHIORI/3.0", "Charset: UTF-8"]);
console.log(parseResult.state === "continue");
parseResult = requestParser.parse_lines(["ID: version", ""]);
console.log(parseResult.state === "end");
console.log(parseResult.results[0].headers.ID === "version");

// ---------- レスポンスのパース ----------

const responseParser = new ShioriJK.Shiori.Response.Parser();
const responseStr =
  "SHIORI/3.0 200 OK\r\n" +
  "Sender: ikaga\r\n" +
  "Charset: UTF-8\r\n" +
  "Value: 8.2.8\r\n" +
  "\r\n";
const response = responseParser.parse(responseStr);
console.log(response.headers.Value === "8.2.8");

// チャンクや行を元にしたパースも対応

// ---------- リクエストのビルド ----------

const request2 = new ShioriJK.Message.Request({
  request_line: {method: "GET", version: "3.0"},
  headers: {
    Charset: "UTF-8",
    Sender: "embryo",
  },
});

// 初期化後にも値をセット
request2.headers.set("ID", "version");

console.log(request2.toString() === "GET SHIORI/3.0\r\nCharset: UTF-8\r\nSender: embryo\r\nID: version\r\n\r\n");

// ---------- レスポンスのビルド ----------

const response2 = new ShioriJK.Message.Response({
  status_line: {code: 200, version: "3.0"},
  headers: {
    Charset: "UTF-8",
    Sender: "ikaga",
    Value: "8.2.8",
  }
});

console.log(response2.toString() === "SHIORI/3.0 200 OK\r\nCharset: UTF-8\r\nSender: ikaga\r\nValue: 8.2.8\r\n\r\n");

さらに見る: このライブラリを使用した栞の実装であるSanaJKや、ベースウェアの実装であるイカガカをご参照ください。

APIドキュメント

http://narazaka.github.io/shiorijk/か、lib/にあるコメント付きのソースをご覧ください。

ドキュメントがルーズだと感じたら、ライブラリやテストコードの中身を読んでいただいたほうがわかりやすいかもしれません。

履歴

v1.0.0

  • CoffeeScript -> TypeScript
  • 基本的なJavaScript APIに変化はありません。
  • null結合型は次のように変更されました : Foo | null | undefined -> Foo | undefined
  • いくつかのAPIに存在した文字列throwはErrorを継承したクラスをthrowするように変更されました。
  • ES5以上を要求します(つまりIE8以下で動作させるにはshimが必要です)。

ライセンス

Zlibライセンスの元で配布いたします。