Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'is-buffer' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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) {
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;
}
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();
});
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;
});
}
}
.then((res) => {
expect(isBuffer(res.body)).toBe(false);
expect(res.body.error).toBe('NOTEXT');
}));
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
};
}