safe-at
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

safe-at

A safe version of .at

Native .at method is very harmful:

const arr = [1, 2, 3];
console.log(arr.at("foo")); // => 1
console.log(arr.at(NaN)); // => 1
console.log(arr.at(1.5)); // => 2

You can use safe-at instead:

import safeAt from "safe-at";

const arr = [1, 2, 3];
console.log(safeAt(arr, "foo")); // => undefined
console.log(safeAt(arr, NaN)); // => undefined
console.log(safeAt(arr, 1.5)); // => undefined

Install

npm install safe-at

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    0
  • 0.0.1
    0

Package Sidebar

Install

npm i safe-at

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

5.08 kB

Total Files

6

Last publish

Collaborators

  • petamoriken