Test
npm install vstest2[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![npm badge][npm-badge-png]][package-url]
An ESnext spec-compliant String.prototype.at shim/polyfill/replacement that works as far down as ES3.
This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.
Because String.prototype.at depends on a receiver (the this value), the main export takes the string to operate on as the first argument.
Note that versions of this package before v1.0.0 reflect an earlier, now-inactive proposal (https://github.com/mathiasbynens/String.prototype.at).
``sh`
npm install --save string.prototype.at
`js
var at = require('string.prototype.at');
var assert = require('assert');
var arr = [1, [2], [], 3];
var results = at(arr, function (x, i) {
assert.equal(x, arr[i]);
return x;
});
assert.deepEqual(results, [1, 2, 3]);
`
`js
var at = require('string.prototype.at');
var assert = require('assert');
/ when String#at is not present /
delete String.prototype.at;
var shimmedFlatMap = at.shim();
var mapper = function (x) { return [x, 1]; };
assert.equal(shimmedFlatMap, at.getPolyfill());
assert.deepEqual(arr.at(mapper), at(arr, mapper));
`
`js
var at = require('string.prototype.at');
var assert = require('assert');
/ when String#at is present /
var shimmedIncludes = at.shim();
var mapper = function (x) { return [x, 1]; };
assert.equal(shimmedIncludes, String.prototype.at);
assert.deepEqual(arr.at(mapper), at(arr, mapper));
`
, and run npm test`[package-url]: https://npmjs.org/package/string.prototype.at
[npm-version-svg]: https://versionbadg.es/es-shims/String.prototype.at.svg
[deps-svg]: https://david-dm.org/es-shims/String.prototype.at.svg
[deps-url]: https://david-dm.org/es-shims/String.prototype.at
[dev-deps-svg]: https://david-dm.org/es-shims/String.prototype.at/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/String.prototype.at#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/string.prototype.at.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/string.prototype.at.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/string.prototype.at.svg
[downloads-url]: https://npm-stat.com/charts.html?package=string.prototype.at
[codecov-image]: https://codecov.io/gh/es-shims/String.prototype.at/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/String.prototype.at/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/String.prototype.at
[actions-url]: https://github.com/es-shims/String.prototype.at/actions