unicorn/prefer-code-point
eslint-plugin-unicorn
Suggestion
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-code-point": "error",
},
},
];Prefer String#codePointAt(…) over String#charCodeAt(…) and String.fromCodePoint(…) over String.fromCharCode(…).
const unicorn = '🦄'.charCodeAt(0).toString(16);
// → 'd83e' (incorrect)String.fromCharCode(0x1f984);
// → '濾' (wrong character — the code point is truncated to 16 bits)const emoji = String.fromCharCode(0x1f60a); // Smileyconst unicorn = '🦄'.codePointAt(0).toString(16);
// → '1f984' (correct)String.fromCodePoint(0x1f984);
// → '🦄' (correct)const emoji = String.fromCodePoint(0x1f60a); // SmileyExamples from the ESLint documentation.
unicorn/prefer-code-point
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-code-point": "error",
},
},
];unicorn/prefer-code-point
unicorn plugin · pedantic
{
"rules": {
"unicorn/prefer-code-point": "error"
}
}Biome does not have this rule.
Prefer using Element#classList.toggle() to toggle class names.
Prefer default parameters and destructuring defaults over reassignment and fallback expressions.
Prefer class field declarations over this assignments in constructors.
Prefer Element#append() over Node#appendChild().
Prefer Blob#arrayBuffer() over FileReader#readAsArrayBuffer(…) and Blob#text() over FileReader#readAsText(…).
Prefer childNode.remove() over parentNode.removeChild(childNode).