Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-string-at

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-string-at

Array/string `.at()` ponyfill.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

array-string-at

Build Status Browser testing by BrowserStack

Array/string .at() ponyfill.

[…] at(), that is on the prototype of the built-in indexable objects: Array, String, and TypedArrays objects. The method supports relative indexing from the end when passed a negative index.

Install

npm install array-string-at --save

Usage

import at from 'array-string-at';

at('becky', 1); // e
at('becky', -2); // k

You can use named export preferNative if you wish to use native implementation if it’s available. In all other cases, ponyfill will be used. Beware of caveats!

Polyfill

import at from 'array-string-at';

if (typeof String.prototype.at === 'undefined') {
	String.prototype.at = function (index) {
		return at(this, index);
	};
}

if (typeof Array.prototype.at === 'undefined') {
	Array.prototype.at = function (index) {
		return at(this, index);
	};
}

API

at(item, index)

Returns: *

Returns value at specified index. Supports relative indexing from the end when passed a negative index.

item

Type: string|Array<unknown>|TypedArray

Item to search.

index

Type: number

Relative index.

Browser support

Tested in Chrome 72, Edge 15, Firefox 65 and should work in all modern browsers (support based on Browserslist configuration).

Test

Test suite is taken and modified from following packages:

For automated tests, run npm run test:automated (append :watch for watcher support).

License

MIT © Ivan Nikolić

Keywords

FAQs

Package last updated on 13 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc