包详细信息

string-at

ljharb186.9kMIT不推荐使用1.1.0

The original String.prototype.at proposal has been replaced by a new one; please use v1 or later of string.prototype.at instead

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

String, string, unicode, ES6

自述文件

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

更新日志

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Generated by auto-changelog.

v1.1.0 - 2019-12-19

Commits

  • [Tests] use shared travis-ci configs cb8740c
  • Update define-properties, tape, eslint, semver, es5-shim; use my personal shared eslint config. 4c0b886
  • [Tests] remove jscs d47b0ea
  • [Tests] up to node v8.2, v7.10, v6.11, v4.8; newer npm breaks on older node; improve matrix 44e9dc3
  • [meta] remove unused Makefile and associated utilities 46aa4a2
  • [Tests] up to node v11.6, v10.15, v8.15, v6.16 30532b9
  • [Tests] up to node v9.2; v8.9; v6.12; use nvm install-latest-npm; pin included builds to LTS. 226999c
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver, es5-shim, es6-shim c31b8b0
  • [meta] add auto-changelog c5fc05e
  • [Tests] up to node v12.7, v11.15, v10.16, v8.16, v6.17; use nvm install-latest-npm d4444bb
  • [Tests] up to node v10.0, v9.11, v8.11, v6.14, v4.9 b69db22
  • Update es-abstract, jscs, eslint, @ljharb/eslint-config, es6-shim 3839e7d
  • Update nsp, eslint, es5-shim, es6-shim fa89f64
  • [Tests] up to node v7.2, v6.9, v4.6; improve test matrix; allow coverage to fail. 6bb9230
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, eslint, nsp, tape, semver ca95176
  • [Dev Deps] update eslint, @ljharb/eslint-config, replace b994ee8
  • [Tests] up to node v5.6, v4.3 ec9187e
  • [Dev Deps] update tape, jscs, eslint, @ljharb/eslint-config, es5-shim, es6-shim 7597246
  • Update define-properties, eslint, semver, es5-shim, es6-shim c147b44
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config a46f365
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config 5fe26c7
  • [Dev Deps] update jscs, nsp, eslint, es5-shim 20ee134
  • [Refactor] use split-up es-abstract (78% bundle size decrease) f01bb1e
  • [Dev Deps] update eslint, @ljharb/eslint-config, covert, replace, semver, tape, es5-shim, es6-shim 32c06c2
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 7e6eeec
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config, es5-shim, es6-shim 5433d98
  • [actions] add automatic rebasing / merge commit blocking 86cb327
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config, es5-shim, es6-shim b4e41b5
  • [Dev Deps] update jscs, eslint, @ljharb/eslint-config dbe9284
  • [Dev Deps] update jscs, nsp, eslint, @ljharb/eslint-config, semver, es5-shim, es6-shim e25e94c
  • package.json: use object form of "authors", add "contributors" ab0891c
  • [Dev Deps] update es5-shim, es6-shim, eslint, replace, semver, tape ef73bb8
  • [Dev Deps] update tape, jscs, nsp, eslint, @ljharb/eslint-config, semver 00ac6fe
  • [Dev Deps] update @es-shims/api, es5-shim, eslint, nsp, semver, tape 284e78c
  • [Tests] up to io.js v3.3, node v4.1 c7d5cc7
  • [Dev Deps] update eslint, @ljharb/eslint-config, functions-have-names, tape 001bdf1
  • [Tests] up to node v12.11 658bd56
  • [Tests] use npm audit instead of nsp 3cda4df
  • [Dev Deps] update nsp, eslint, @ljharb/eslint-config, es6-shim 6655a7c
  • [Tests] use pretest/posttest b6e180f
  • [Tests] up to node v5.9, v4.4 2519b15
  • [Dev Deps] update jscs 954e885
  • Test up to io.js v2.2 e56a178
  • [Tests] use npx aud instead of nsp or npm audit with hoops e75464e
  • [Tests] up to node v6.2 24cbf33
  • [Dev Deps] update eslint, @ljharb/eslint-config, nsp e48cfb1
  • Only apps should have lockfiles 62754a7
  • [Dev Deps] update tape, eslint, @ljharb/eslint-config bcb53c6
  • [meta] clean up scripts bd09780
  • [Dev Deps] update eslint, @ljharb/eslint-config 8e1b5e8
  • [Tests] on node v12.8 62b166d
  • [Dev Deps] update semver, tape aa12572
  • [Tests] use eclint instead of editorconfig-tools d09a00f
  • [Deps] update define-properties, es-abstract da9ce3d
  • [Dev Deps] update @es-shims/api, replace 0361c7e
  • [Tests] on node v10.1 abe2801
  • [Deps] update es-abstract, function-bind 8ca4a62
  • [Deps] update es-abstract, function-bind ce5560b
  • [Deps] update define-properties, es-abstract f7392c2
  • Update tape, eslint e831ec8
  • [meta] add funding field 16721ed
  • [Tests] use functions-have-names 12e5b3c
  • [New] add auto entry point 7c46663
  • [Deps] update es-abstract 7fe28a4
  • [Dev Deps] update semver 608f43c
  • [Deps] update es-abstract d63023b
  • [Deps] update es-abstract 4f71450
  • [Deps] update es-abstract ebd0b7e
  • [Tests] on node v5.12 adcd99d
  • [Deps] update es-abstract 9b80bca
  • [Tests] on node v5.10 5896da7
  • [Tests] on node v5.7 b630576
  • [Tests] on node v4.2 ecf605a
  • [Deps] update es-abstract 9712990
  • [Deps] update es-abstract 0979ce2
  • [Dev Deps] update tape fad1430
  • [Dev Deps] update tape 92b7c87
  • Switch from vb.teelaun.ch to versionbadg.es for the npm version badge SVG. 0f00781
  • Update tape 789827e
  • Test on io.js v2.5 01e0b96
  • Test on io.js v2.4 6be715a
  • Test on io.js v2.3 fc92e06
  • Test on io.js v3.0 ab286c0

v1.0.1 - 2015-05-23

Commits

v1.0.0 - 2015-03-20

Commits