Sha256: f4c4ecdcaf3f694159126ec3b888987b3fe232124a9bf0e61cc602cb5ff8a7da

Contents?: true

Size: 1.02 KB

Versions: 29

Compression:

Stored size: 1.02 KB

Contents

// Based on: https://github.com/mathiasbynens/String.prototype.at
// Thanks @mathiasbynens !

'use strict';

var toInteger  = require('../../number/to-integer')
  , validValue = require('../../object/valid-value');

module.exports = function (pos) {
	var str = String(validValue(this)), size = str.length
	  , cuFirst, cuSecond, nextPos, len;
	pos = toInteger(pos);

	// Account for out-of-bounds indices
	// The odd lower bound is because the ToInteger operation is
	// going to round `n` to `0` for `-1 < n <= 0`.
	if (pos <= -1 || pos >= size) return '';

	// Second half of `ToInteger`
	pos = pos | 0;
	// Get the first code unit and code unit value
	cuFirst = str.charCodeAt(pos);
	nextPos = pos + 1;
	len = 1;
	if ( // check if it’s the start of a surrogate pair
		(cuFirst >= 0xD800) && (cuFirst <= 0xDBFF) && // high surrogate
			(size > nextPos) // there is a next code unit
	) {
		cuSecond = str.charCodeAt(nextPos);
		if (cuSecond >= 0xDC00 && cuSecond <= 0xDFFF) len = 2; // low surrogate
	}
	return str.slice(pos, pos + len);
};

Version data entries

29 entries across 19 versions & 7 rubygems

Version Path
guard-sass-lint-0.1.2 node_modules/es5-ext/string/#/at.js
guard-sass-lint-0.1.1 node_modules/es5-ext/string/#/at.js
lanes-0.8.0 node_modules/es5-ext/string/#/at.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/string/#/at.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/string/#/at.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/string/#/at.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/es5-ext/string/#/at.js
node-compiler-0.7.0 vendor/node-v7.1.0/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/string/#/at.js
node-compiler-0.7.0 vendor/node-v6.9.1/deps/npm/node_modules/node-gyp/node_modules/path-array/node_modules/array-index/node_modules/es6-symbol/node_modules/es5-ext/string/#/at.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/es5-ext/string/#/at.js
blackboard-3.1.9 lib/site_template/node_modules/es5-ext/string/#/at.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/string/#/at.js
eslint_node_modules-1.6.0.1 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/es5-ext/string/#/at.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-map/node_modules/es5-ext/string/#/at.js
eslint_node_modules-1.6.0 vendor/node_modules/eslint/node_modules/escope/node_modules/es6-weak-map/node_modules/es5-ext/string/#/at.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/string/#/at.js
entangled-0.0.16 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/string/#/at.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/string/#/at.js
entangled-0.0.15 spec/dummy/public/node_modules/bower/node_modules/insight/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/string/#/at.js
entangled-0.0.14 spec/dummy/public/node_modules/bower/node_modules/inquirer/node_modules/cli-color/node_modules/es5-ext/string/#/at.js