unicorn/prefer-blob-reading-methods
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-blob-reading-methods": "error",
},
},
];Prefer Blob#arrayBuffer() over FileReader#readAsArrayBuffer(…) and Blob#text() over FileReader#readAsText(…).
const arrayBuffer = await new Promise((resolve, reject) => {
const fileReader = new FileReader();
fileReader.addEventListener('load', () => {
resolve(fileReader.result);
});
fileReader.addEventListener('error', () => {
reject(fileReader.error);
});
fileReader.readAsArrayBuffer(blob);
});fileReader.readAsText(blob);const arrayBuffer = await blob.arrayBuffer();const text = await blob.text();fileReader.readAsText(blob, 'ascii');Examples from the ESLint documentation.
unicorn/prefer-blob-reading-methods
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-blob-reading-methods": "error",
},
},
];unicorn/prefer-blob-reading-methods
unicorn plugin · pedantic
{
"rules": {
"unicorn/prefer-blob-reading-methods": "error"
}
}Biome does not have this rule.
Prefer Array#flat() over legacy techniques to flatten arrays.
Prefer class field declarations over this assignments in constructors.
Prefer .find(…) and .findLast(…) over the first or last element from .filter(…).
Prefer using Element#classList.toggle() to toggle class names.
Prefer .addEventListener() and .removeEventListener() over on-functions.
Prefer String#codePointAt(…) over String#charCodeAt(…) and String.fromCodePoint(…) over String.fromCharCode(…).