voca
Version:
The ultimate JavaScript string library
30 lines (26 loc) • 945 B
JavaScript
import './internal/is_nil.js';
import './is_string.js';
import { c as coerceToString } from './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 coerceToString(subject).substr(start, length);
}
export default substr;