enforce either
TextEncoderorrequire("util").TextEncoder
The TextEncoder class of util module is defined as a global variable.
console.log(TextEncoder === require("util").TextEncoder) //→ trueIt will be readable if we use either TextEncoder consistently.
This rule enforces which TextEncoder we should use.
This rule has a string option.
{
"node/prefer-global/text-encoder": ["error", "always" | "never"]
}"always"(default) ... enforces to use the global variableTextEncoderrather thanrequire("util").TextEncoder."never"... enforces to userequire("util").TextEncoderrather than the global variableTextEncoder.
Examples of 👎 incorrect code for this rule:
/*eslint node/prefer-global/text-encoder: [error]*/
const { TextEncoder } = require("util")
const u = new TextEncoder(s)Examples of 👍 correct code for this rule:
/*eslint node/prefer-global/text-encoder: [error]*/
const u = new TextEncoder(s)Examples of 👎 incorrect code for the "never" option:
/*eslint node/prefer-global/text-encoder: [error, never]*/
const u = new TextEncoder(s)Examples of 👍 correct code for the "never" option:
/*eslint node/prefer-global/text-encoder: [error, never]*/
const { TextEncoder } = require("util")
const u = new TextEncoder(s)