node_modules/es5-ext/string/#/at.js

Maintainability

54.40

Lines of code

30

Created with Raphaël 2.1.002550751002015-1-52014-12-42014-12-3

2015-5-18
Maintainability: 54.4

Created with Raphaël 2.1.007.51522.5302015-1-52014-12-42014-12-3

2015-5-18
Lines of Code: 30

Difficulty

16.29

Estimated Errors

0.20

Function weight

By Complexity

Created with Raphaël 2.1.0module.exports5

By SLOC

Created with Raphaël 2.1.0module.exports25
1
// Based on: https://github.com/mathiasbynens/String.prototype.at
2
// Thanks @mathiasbynens !
3
 
4
'use strict';
Column: 1 "Use the function form of "use strict"."
5
 
6
var toInteger  = require('../../number/to-integer')
Column: 51 "Bad line breaking before ','."
Column: 18 "'require' is not defined."
7
  , validValue = require('../../object/valid-value');
Column: 3 "Comma warnings can be turned off with 'laxcomma'."
Column: 18 "'require' is not defined."
8
 
9
module.exports = function (pos) {
Column: 1 "'module' is not defined."
10
    var str = String(validValue(this)), size = str.length
Column: 52 "Bad line breaking before ','."
11
      , cuFirst, cuSecond, nextPos, len;
12
    pos = toInteger(pos);
13
 
14
    // Account for out-of-bounds indices
15
    // The odd lower bound is because the ToInteger operation is
16
    // going to round `n` to `0` for `-1 < n <= 0`.
17
    if (pos <= -1 || pos >= size) return '';
18
 
19
    // Second half of `ToInteger`
20
    pos = pos | 0;
21
    // Get the first code unit and code unit value
22
    cuFirst = str.charCodeAt(pos);
23
    nextPos = pos + 1;
24
    len = 1;
25
    if ( // check if it’s the start of a surrogate pair
26
        (cuFirst >= 0xD800) && (cuFirst <= 0xDBFF) && // high surrogate
27
            (size > nextPos) // there is a next code unit
28
    ) {
29
        cuSecond = str.charCodeAt(nextPos);
30
        if (cuSecond >= 0xDC00 && cuSecond <= 0xDFFF) len = 2; // low surrogate
31
    }
32
    return str.slice(pos, pos + len);
33
};