voca
Version:
The ultimate JavaScript string library
32 lines (27 loc) • 979 B
JavaScript
;
require('./internal/is_nil.js');
require('./is_string.js');
var coerce_to_string = require('./internal/coerce_to_string.js');
/**
* Extracts from `subject` a string from `start` position a number of `length` characters.
*
* @function substr
* @static
* @since 1.0.0
* @memberOf Chop
* @param {string} [subject=''] The string to extract from.
* @param {number} start The position to start extraction.
* @param {number} [length=subject.endOfString] The number of characters to extract. If omitted, extract to the end of `subject`.
* @return {string} Returns the extracted string.
* @note Uses native `String.prototype.substr()`
* @example
* v.substr('infinite loop', 9);
* // => 'loop'
*
* v.substr('dreams', 2, 2);
* // => 'ea'
*/
function substr(subject, start, length) {
return coerce_to_string.coerceToString(subject).substr(start, length);
}
module.exports = substr;