New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

string-at

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

string-at

A robust & optimized ES3-compatible polyfill for the `String.prototype.at` proposal for ECMAScript 6/7 - based on https://mths.be/at

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
57K
increased by9.21%
Maintainers
1
Weekly downloads
 
Created
Source

string-at Version Badge

Build Status dependency status dev dependency status License Downloads

npm badge

browser support

A robust & optimized ES3-compatible polyfill for the String.prototype.at proposal for ECMAScript 6/7.

This code is almost entirely copied from @mathiasbynens's excellent polyfill at https://mths.be/at - I created this one so that it did not automatically modify String.prototype, and so that it would fit in more neatly with the es7-shim.

Use it as a standalone function, or call its shim method to install it as a polyfill.

Example

var at = require('string-at');
var assert = require('assert');

var surrogatePair = '\uD834\uDF06 abc'; // a surrogate pair
assert(surrogatePair.length === 6);
assert(at(surrogatePair, 0) === '\uD834\uDF06');
assert(at(surrogatePair, 1) === '\uDF06');

var i = 0;
var str = '';
while (str.length < surrogatePair.length) {
	str += at(surrogatePair, str.length);
	i += 1;
}
assert(str === surrogatePair);
assert(i === 4); // 4 code points
assert(str.length === 6); // 6 "characters"

at.shim();
assert(surrogatePair.at(0) === at(surrogatePair, 0));

Tests

Simply clone the repo, npm install, and run npm test

Keywords

FAQs

Package last updated on 19 Dec 2019

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