LoginSignup
11
7

More than 5 years have passed since last update.

SION - is now Interchangeable

Last updated at Posted at 2018-07-12

SIONは Swift Interchangeable Object Notation から取ったと紹介記事で書きましたが、実装が単一言語ではinterchangeableとはとても言えません。というわけでJSの実装を書いたのですが、なんとGoの実装をそれより先にmattnが文字通り一晩で書いてくれちゃいましたよ。

というわけで誕生二日目で早くもinterchangeableになったSIONですが、

どちらもドキュ貧なのですが、ここでは私が書いた方のjs-sionの方を少し解説しておきます。

  • ESMですモダンです。いやあ楽ですねえ。
  • なのでCORSさえクリアすればこんなことも出来ます。
<html>
<head>
    <meta charset="utf-8">
    <title>Console</title>
</head>
<body>
<script type="module">
import SION from 'https://cdn.rawgit.com/dankogai/js-sion/master/sion.js';    
console.log(SION);
window.SION = SION;
</script>
open sonsole and use SION interactively.
</body>
</html>
  • ECMAScript標準のJSONオブジェクト同様、.parse().stringify()が提供されます。
  • Dictionaryはキーが全てStringならObjectに、そうでない場合はMapにマップしてます。そうなんです。ECMAScriptでも今や文字列でないキーも使えるんですよ。
  • .DataUint8Arrayにマップしてます。node.jsとブラウザーでここだけ処理を切り替えています。
  • 数値は…IntDoubleNumberです。が、.stringify()ではInt(で表現可能)なものは10進で、Doubleなものは16進で出力するようにしました。

おっと時間もないので今はこの辺で。引き続きSIONをよろしくお願いします。

Dan the Safe, Fast, and Expressive

11
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
7