route.builders Tech document

route.builders Tech document

3. 使い方

(TBD)

なお、文字コードが SJIS の場合は UTF-8 へ変換する必要があります。

詳細は Oud2JSONのドキュメントも参照してください。

import { O_O } from "@route-builders/oud-operator";

import * as Encoder from "encoding-japanese";
import { readFileSync, writeFileSync } from "fs";

const o_o = new O_O();
const filepath = "/path/to/file.oud";
const buffer = readFileSync(filepath);

const encoding = Encoder.detect(buffer, ["SJIS", "UTF8"]);
if (!encoding) {
  throw new Error();
}

const sources = Encoder.convert(buffer, {
  to: "UNICODE",
  from: encoding,
  type: "string",
  bom: false,
})
  .replace(/\r/g, "")
  .split("\n");

const dataSet = o_o.fromOud(sources);