Repository: keichi/binary-parser (ts)

Issue:
Please, correct the typo: endianess -> endianness
The correct spelling of the word "endianess" is "endianness". A typo exists in the documentation as well as in the method names.

Pull request:
Fix typo (endianess -> endianness)
Closes #201

Patch:
diff --git a/README.md b/README.md
index 6a9638e..ec835a9 100644
--- a/README.md
+++ b/README.md
@@ -44,7 +44,7 @@ const Parser = require("binary-parser").Parser;
 
 // Build an IP packet header Parser
 const ipHeader = new Parser()
-  .endianess("big")
+  .endianness("big")
   .bit4("version")
   .bit4("headerLength")
   .uint8("tos")
@@ -329,17 +329,17 @@ Move the buffer offset for `relOffset` bytes from the current position. Use a
 negative `relOffset` value to rewind the offset. This method was previously
 named `skip(length)`.
 
-### endianess(endianess)
-Define what endianess to use in this parser. `endianess` can be either
-`"little"` or `"big"`. The default endianess of `Parser` is set to big-endian.
+### endianness(endianness)
+Define what endianness to use in this parser. `endianness` can be either
+`"little"` or `"big"`. The default endianness of `Parser` is set to big-endian.
 
 ```javascript
 const parser = new Parser()
-  .endianess("little")
-  // You can specify endianess explicitly
+  .endianness("little")
+  // You can specify endianness explicitly
   .uint16be("a")
   .uint32le("a")
-  // Or you can omit endianess (in this case, little-endian is used)
+  // Or you can omit endianness (in this case, little-endian is used)
   .uint16("b")
   .int32("c");
 ```
@@ -518,7 +518,7 @@ These options can be used in all parsers.
     ```javascript
     // simple maginc number validation
     const ClassFile = Parser.start()
-      .endianess("big")
+      .endianness("big")
       .uint32("magic", { assert: 0xcafebabe });
 
     // Doing more complex assertion with a predicate function
diff --git a/example/bmp.ts b/example/bmp.ts
index 33e3e1f..d0651c5 100644
--- a/example/bmp.ts
+++ b/example/bmp.ts
@@ -12,7 +12,7 @@ import { Parser } from "../lib/binary_parser";
 //   DWORD bfOffBits;
 // } BITMAPFILEHEADER, *PBITMAPFILEHEADER;
 const bmpFileHeader = new Parser()
-  .endianess("little")
+  .endianness("little")
   .string("type", {
     length: 2,
     assert: "BM",
@@ -37,7 +37,7 @@ const bmpFileHeader = new Parser()
 //     DWORD  biClrImportant;
 // } BITMAPINFOHEADER;
 const bmpInfoHeader = new Parser()
-  .endianess("little")
+  .endianness("little")
   .uint32("size")
   .int32("width")
   .int32("height")
diff --git a/example/classfile.ts b/example/classfile.ts
index fdbccb7..dc97d7e 100644
--- a/example/classfile.ts
+++ b/example/classfile.ts
@@ -73,7 +73,7 @@ const CpInfo = Parser.start()
   });
 
 const ClassFile = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint32("magic", { assert: 0xcafebabe })
   .uint16("minor_version")
   .uint16("major_version")
diff --git a/example/elf32.ts b/example/elf32.ts
index 1646c67..f7b672e 100644
--- a/example/elf32.ts
+++ b/example/elf32.ts
@@ -5,7 +5,7 @@ import { inspect } from "util";
 import { Parser } from "../lib/binary_parser";
 
 const ELF32ProgramHeader = new Parser()
-  .endianess("little")
+  .endianness("little")
   .uint32("type")
   .uint32("offset")
   .uint32("vaddr")
@@ -23,7 +23,7 @@ const ELF32ProgramHeaderTable = new Parser().array("items", {
 });
 
 const ELF32SectionHeader = new Parser()
-  .endianess("little")
+  .endianness("little")
   .uint32("name")
   .uint32("type")
   .uint32("flags")
@@ -51,7 +51,7 @@ const ELF32SectionHeaderStringTable = new Parser().seek(1).array("items", {
 });
 
 const ELF32Header = new Parser()
-  .endianess("little")
+  .endianness("little")
   .buffer("ident", { length: 16 })
   .uint16("type")
   .uint16("machine")
diff --git a/example/ip.ts b/example/ip.ts
index 46aea6c..ed4b63f 100644
--- a/example/ip.ts
+++ b/example/ip.ts
@@ -1,7 +1,7 @@
 import { Parser } from "../lib/binary_parser";
 
 const ipHeader = new Parser()
-  .endianess("big")
+  .endianness("big")
   .bit4("version")
   .bit4("headerLength")
   .uint8("tos")
diff --git a/example/jpg.ts b/example/jpg.ts
index f3d4873..010c4eb 100644
--- a/example/jpg.ts
+++ b/example/jpg.ts
@@ -9,7 +9,7 @@ const SOI = Parser.start();
 const EOI = Parser.start();
 
 const APP0 = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .string("id", {
     encoding: "ascii",
@@ -31,7 +31,7 @@ const APP0 = Parser.start()
 
 // @ts-ignore
 const COM = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .string("comment", {
     encoding: "ascii",
@@ -41,7 +41,7 @@ const COM = Parser.start()
   });
 
 const SOS = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .uint8("componentCount")
   .array("components", {
@@ -53,7 +53,7 @@ const SOS = Parser.start()
   .uint8("spectrumSelect");
 
 const DQT = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .array("tables", {
     type: Parser.start().uint8("precisionAndTableId").array("table", {
@@ -66,7 +66,7 @@ const DQT = Parser.start()
   });
 
 const SOF0 = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .uint8("precision")
   .uint16("width")
@@ -81,14 +81,14 @@ const SOF0 = Parser.start()
   });
 
 const Ignore = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("length")
   .seek(function (this: any) {
     return this.length - 2;
   });
 
 const Segment = Parser.start()
-  .endianess("big")
+  .endianness("big")
   .uint16("marker")
   .choice("segment", {
     tag: "marker",
diff --git a/example/tcp.ts b/example/tcp.ts
index 93a5b56..269bc35 100644
--- a/example/tcp.ts
+++ b/example/tcp.ts
@@ -1,7 +1,7 @@
 import { Parser } from "../lib/binary_parser";
 
 const tcpHeader = new Parser()
-  .endianess("big")
+  .endianness("big")
   .uint16("srcPort")
   .uint16("dstPort")
   .uint32("seq")
diff --git a/lib/binary_parser.ts b/lib/binary_parser.ts
index c557b45..5edc73a 100644
--- a/lib/binary_parser.ts
+++ b/lib/binary_parser.ts
@@ -145,7 +145,7 @@ type ComplexTypes =
   | "wrapper"
   | "";
 
-type Endianess = "be" | "le";
+type Endianness = "be" | "le";
 
 type PrimitiveTypes =
   | "uint8"
@@ -281,7 +281,7 @@ export class Parser {
   next?: Parser;
   head?: Parser;
   compiled?: Function;
-  endian: Endianess = "be";
+  endian: Endianness = "be";
   constructorFn?: Function;
   alias?: string;
   useContextVariables = false;
@@ -724,8 +724,8 @@ export class Parser {
     return this.setNextParser("saveOffset", varName, options);
   }
 
-  endianess(endianess: "little" | "big"): this {
-    switch (endianess.toLowerCase()) {
+  endianness(endianness: "little" | "big"): this {
+    switch (endianness.toLowerCase()) {
       case "little":
         this.endian = "le";
         break;
@@ -733,12 +733,16 @@ export class Parser {
         this.endian = "be";
         break;
       default:
-        throw new Error('endianess must be one of "little" or "big"');
+        throw new Error('endianness must be one of "little" or "big"');
     }
 
     return this;
   }
 
+  endianess(endianess: "little" | "big"): this {
+    return this.endianness(endianess);
+  }
+
   useContextVars(useContextVariables = true): this {
     this.useContextVariables = useContextVariables;
 


Test patch:
diff --git a/test/primitive_parser.ts b/test/primitive_parser.ts
index e643c9b..2b18c75 100644
--- a/test/primitive_parser.ts
+++ b/test/primitive_parser.ts
@@ -86,7 +86,7 @@ function primitiveParserTests(
         ok(Math.abs(result.a - 12.345) < FLT_EPSILON);
         ok(Math.abs(result.b - -0.0678) < FLT_EPSILON);
       });
-      it("should handle endianess", () => {
+      it("should handle endianness", () => {
         const parser = Parser.start().int32le("little").int32be("big");
 
         const buffer = factory([
@@ -147,7 +147,7 @@ function primitiveParserTests(
         });
 
         const parser2 = new Parser()
-          .endianess("little")
+          .endianness("little")
           .bit1("a")
           .bit2("b")
           .bit4("c")
@@ -171,7 +171,7 @@ function primitiveParserTests(
         });
 
         const parser2 = new Parser()
-          .endianess("little")
+          .endianness("little")
           .bit3("a")
           .bit9("b")
           .bit4("c");
@@ -198,7 +198,7 @@ function primitiveParserTests(
         });
 
         const parser2 = new Parser()
-          .endianess("little")
+          .endianness("little")
           .bit1("a")
           .bit24("b")
           .bit4("c")
@@ -345,7 +345,7 @@ function primitiveParserTests(
 
       it("should parse until function returns true when readUntil is function", () => {
         const parser = new Parser()
-          .endianess("big")
+          .endianness("big")
           .uint8("cmd")
           .buffer("data", {
             readUntil: (item: number) => item === 2,