"[…] and I do open source because, Power To The People" — Azer Koçulu
Require from npm instead of using JS builtins (prefer-npm
)
💼 This rule is enabled in the following configs: 🌐 all
, ✅ recommended
.
🔧 This rule is automatically fixable by the --fix
CLI option.
📖 Rule details
Using NPM packages over native JavaScript has many advantages:
- Controlled Updates: Decide when to upgrade, avoiding sudden breaks.
- Contribute Easily: Open-source and accessible nature allows for quick bug fixes or enhancements.
- Find Better Solutions: Often more efficient or elegant than native methods.
- Flexibility: Avoid lock-ins; switch packages as needs evolve.
- Community Support: Active communities mean faster fixes and richer documentation.
- Tailored Solutions: Greater customization options than native functionalities.
💡 Examples
js
// ❌ Incorrect
const padded = str.padStart(' ', 10) // starts on which end? Right or left?
const color = n % 2 ? 'blue' : 'red' // wtf is '%' ?
// ✅ Correct
const leftPad = require('left-pad')
const isOdd = require('is-odd')
const padded = leftPad(str, 10)
const color = isOdd(n) ? 'blue' : 'red'
🔧 Config
js
{ rules: { 'ninja/prefer-npm': 2 } }