lib/bit-field.js
/**
   * Prepares the class to handle data according to it's schema provided in `BitField.fields`.
   * The method is called automatically the first time the constructor is used.
   *
   * @returns {void}
   */
Prepares the class to handle data according to it's schema provided in `BitField.fields`.
The method is called automatically the first time the constructor is used.

@returns {void}
Prepares the class to handle data according to it ' s schema provided in ` BitField . fields ` . The method is called automatically the first time the constructor is used . @returns { void }
static initialize() {
    const totalSize = this.fields.reduce((result, field) => result += (field.size || 1), 0);
    const isBigInt = totalSize > BITWISE_SIZE;
    const [zero, one, two] = isBigInt ? [BigInt(0), BigInt(1), BigInt(2)] : [0, 1, 2];
    const fields = [];
    const masks = {};
    const offsets = {};
    let lastOffset = zero;
    for (let i = 0; i < this.fields.length; i++) {
      const field = this.fields[i];
      const name = field.name || field;
      const size = isBigInt ? BigInt(field.size || 1) : field.size || 1;
      masks[name] = (two << size - one) - one;
      offsets[name] = lastOffset;
      lastOffset += size;
      fields.push({ name, size });
    }
    this.fields = fields;
    this.size = totalSize;
    this.mask = two << ((isBigInt ? BigInt(totalSize) : totalSize) - one);
    this.isBigInt = isBigInt;
    this.isSafe = totalSize <= MAX_SIZE;
    this.zero = zero;
    this.one = one;
    this.two = two;
    this.masks = masks;
    this.offsets = offsets;
    this.isInitialized = true;
  }
static initialize ( ) { const totalSize = this . fields . reduce ( ( result , field ) => result += ( field . size || 1 ) , 0 ) ; const isBigInt = totalSize > BITWISE_SIZE ; const [ zero , one , two ] = isBigInt ? [ BigInt ( 0 ) , BigInt ( 1 ) , BigInt ( 2 ) ] : [ 0 , 1 , 2 ] ; const fields = [ ] ; const masks = { } ; const offsets = { } ; let lastOffset = zero ; for ( let i = 0 ; i < this . fields . length ; i ++ ) { const field = this . fields [ i ] ; const name = field . name || field ; const size = isBigInt ? BigInt ( field . size || 1 ) : field . size || 1 ; masks [ name ] = ( two << size - one ) - one ; offsets [ name ] = lastOffset ; lastOffset += size ; fields . push ( { name , size } ) ; } this . fields = fields ; this . size = totalSize ; this . mask = two << ( ( isBigInt ? BigInt ( totalSize ) : totalSize ) - one ) ; this . isBigInt = isBigInt ; this . isSafe = totalSize <= MAX_SIZE ; this . zero = zero ; this . one = one ; this . two = two ; this . masks = masks ; this . offsets = offsets ; this . isInitialized = true ; }
Prepares the class to handle data according to it's schema provided in `BitField.fields`.
Prepares the class to handle data according to it ' s schema provided in ` BitField . fields ` .
// determine total size and if BigInts are required // normalize fields, set masks and offsets