construct-js
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -27,3 +27,3 @@ export declare enum Endian { | ||
private fields; | ||
private allFieldNames; | ||
private fieldMap; | ||
name: string; | ||
@@ -30,0 +30,0 @@ constructor(name: string, alignment?: StructAlignment, paddingDirection?: AlignmentPadding); |
@@ -40,3 +40,3 @@ "use strict"; | ||
this.fields = []; | ||
this.allFieldNames = []; | ||
this.fieldMap = {}; | ||
this.name = name; | ||
@@ -47,4 +47,4 @@ this.alignment = alignment; | ||
get(name) { | ||
assert(this.allFieldNames.includes(name), `No field with name ${name} exists on Struct ${this.name}`); | ||
return this.fields.find(f => f.name === name).field; | ||
assert((name in this.fieldMap), `No field with name ${name} exists on Struct ${this.name}`); | ||
return this.fieldMap[name].field; | ||
} | ||
@@ -73,3 +73,3 @@ getDeep(path) { | ||
getOffset(name) { | ||
assert(this.allFieldNames.includes(name), `No field with name ${name} exists on Struct ${this.name}`); | ||
assert((name in this.fieldMap), `No field with name ${name} exists on Struct ${this.name}`); | ||
let total = 0; | ||
@@ -88,6 +88,7 @@ for (let { name: fName, field } of this.fields) { | ||
field(name, item) { | ||
assert(!this.allFieldNames.includes(name), `A field already exists on Struct ${this.name} with name ${name}`); | ||
assert(!(name in this.fieldMap), `A field already exists on Struct ${this.name} with name ${name}`); | ||
assert(validNameRegex.test(name), `Name "${name}" is not valid. Names can be made of letters, numbers, underscores, and dashes`); | ||
this.fields.push({ name, field: item }); | ||
this.allFieldNames.push(name); | ||
const field = { name, field: item }; | ||
this.fields.push(field); | ||
this.fieldMap[name] = field; | ||
return this; | ||
@@ -94,0 +95,0 @@ } |
{ | ||
"name": "construct-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
831
0
70239