How to use is-buffer - 6 common examples

To help you get started, we’ve selected a few is-buffer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrai / enum / lib / enum.es6 View on Github external
get(key, offset) {
    if (key === null || key === undefined) {
      return;
    } // Buffer instance support, part of the ref Type interface
    if (isBuffer(key)) {
      key = key["readUInt32" + this._options.endianness](offset || 0);
    }

    if (EnumItem.isEnumItem(key)) {
      var foundIndex = indexOf.call(this.enums, key);
      if (foundIndex >= 0) {
        return key;
      }
      if (!this.isFlaggable || this.isFlaggable && key.key.indexOf(this._options.separator) < 0) {
        return;
      }
      return this.get(key.key);
    } else if (isString(key)) {

      var enums = this;
      if (this._options.ignoreCase) {
github jcblw / drawable / src / image.js View on Github external
constructor(img, styles = {}) {
    // be able to set image buffer
    if (isBuffer(img)) {
      this._image = new Image();
      this._image.src = img;
      this._dimensions = sizeOf(img);
    } else {
      this._img = img;
    }
    this._styles = styles;
  }
github Azure / azure-sdk-for-js / tests / dataTransformer.spec.ts View on Github external
it("should correctly encode/decode a boolean message body", function (done) {
    const encoded: any = transformer.encode(booleanBody);
    encoded.typecode.should.equal(117);
    isBuffer(encoded.content).should.equal(true);
    const decoded: any = transformer.decode(encoded);
    decoded.should.equal(booleanBody);
    done();
  });
github PlotterClub / penplotPlayground / lib / penplot.js View on Github external
function print () {
    if (process.env.NODE_ENV === 'production') {
      console.log('You need to be in development mode to print a plot!');
    } else if (typeof plot.print !== 'function') {
      throw new Error('Plot has no print() function defined!');
    } else {
      const svg = plot.print();
      if (!svg || (!isBuffer(svg) && typeof svg !== 'string')) {
        throw new Error('print() must return a string or Buffer SVG file!');
      }
      xhr.post('/print', {
        json: true,
        body: {
          dimensions,
          orientation,
          lineWidth,
          svg
        }
      }, err => {
        if (err) throw err;
      });
    }
  }
github ChrisCinelli / branded-qr-code / lib / route.spec.js View on Github external
.then((res) => {
      expect(isBuffer(res.body)).toBe(false);
      expect(res.body.error).toBe('NOTEXT');
    }));
github Azure / azure-sdk-for-js / sdk / core / core-amqp / src / auth / sas.ts View on Github external
protected _createToken(
    expiry: number,
    audience: string,
    hashInput?: string | Buffer
  ): AccessToken {
    audience = encodeURIComponent(audience);
    const keyName = encodeURIComponent(this.keyName);
    const stringToSign = audience + "\n" + expiry;
    hashInput = hashInput || this.key;
    let shaObj: any;
    if (isBuffer(hashInput)) {
      shaObj = new jssha("SHA-256", "ARRAYBUFFER");
      shaObj.setHMACKey(hashInput, "ARRAYBUFFER");
      shaObj.update(Buffer.from(stringToSign));
    } else {
      shaObj = new jssha("SHA-256", "TEXT");
      shaObj.setHMACKey(hashInput, "TEXT");
      shaObj.update(stringToSign);
    }
    const sig = encodeURIComponent(shaObj.getHMAC("B64"));
    return {
      token: `SharedAccessSignature sr=${audience}&sig=${sig}&se=${expiry}&skn=${keyName}`,
      expiresOnTimestamp: expiry
    };
  }

is-buffer

Determine if an object is a Buffer

MIT
Latest version published 4 years ago

Package Health Score

67 / 100
Full package analysis

Popular is-buffer functions