1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00
denoland-deno/testdata/read_file_sync.ts
2018-05-27 12:49:20 -04:00

14 lines
418 B
TypeScript

import { readFileSync } from "deno";
let data = readFileSync("package.json");
if (!data.byteLength) {
throw Error(`Expected positive value for data.byteLength ${data.byteLength}`);
}
const decoder = new TextDecoder("utf-8");
const json = decoder.decode(data);
const pkg = JSON.parse(json);
if (pkg.name !== "deno") {
throw Error(`Expected "deno" but got "${pkg.name}"`)
}
console.log("package.name ", pkg.name);