From 39b5d85d1cf7b9c3be9c37c01a15121418fccaba Mon Sep 17 00:00:00 2001 From: Offroaders123 <65947371+Offroaders123@users.noreply.github.com> Date: Fri, 24 Jun 2022 18:53:36 -0700 Subject: [PATCH] Parse to Read Changes: - Renamed the `parse` function to `read`! This is more consistent with the Read and Write kind of idea, considering the Parse class is called Reader, instead of Parser. This also simplifies things for when I add JSON support too, with my mixed SNBT-JSON format that I want to create. - The JSON functions will likely be called `parse` and `stringify`, and the binary NBT functions will be `read` and `write`. --- src/index.js | 6 +++--- src/{parse.js => read.js} | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) rename src/{parse.js => read.js} (93%) diff --git a/src/index.js b/src/index.js index 15e085c..4795524 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ -import parse from "./parse.js"; +import read from "./read.js"; import write from "./write.js"; -export { parse, write }; +export { read, write }; -export default { parse, write, [Symbol.toStringTag]: "NBT" }; \ No newline at end of file +export default { read, write, [Symbol.toStringTag]: "NBT" }; \ No newline at end of file diff --git a/src/parse.js b/src/read.js similarity index 93% rename from src/parse.js rename to src/read.js index 78cfddd..da65f10 100644 --- a/src/parse.js +++ b/src/read.js @@ -1,7 +1,7 @@ import { tags, types } from "./tags.js"; import { decompress } from "./compression.js"; -export default async function parse(data,{ endian } = {}){ +export default async function read(data,{ endian } = {}){ if (!data) throw new Error("Unexpected falsy value for the data parameter"); if (typeof endian !== "undefined" && !["big","little"].includes(endian)){ @@ -15,7 +15,7 @@ export default async function parse(data,{ endian } = {}){ if (typeof endian !== "undefined"){ try { - const result = await runParser(data,endian); + const result = await runReader(data,endian); return result; } catch (error){ throw error; @@ -23,10 +23,10 @@ export default async function parse(data,{ endian } = {}){ } else { let result = null; try { - result = await runParser(data,"big"); + result = await runReader(data,"big"); } catch (error){ try { - result = await runParser(data,"little"); + result = await runReader(data,"little"); } catch { throw error; } @@ -35,7 +35,7 @@ export default async function parse(data,{ endian } = {}){ } } -async function runParser(data,endian){ +async function runReader(data,endian){ if (hasGzipHeader(data)) data = await decompress(data,{ encoding: "gzip" }); const reader = new Reader(data,endian);