UNPKG

voca

Version:

The ultimate JavaScript string library

33 lines (28 loc) 944 B
'use strict'; 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 up to `end` position. The character at `end` position is not * included. * * @function substring * @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} [end=subject.length] The position to end extraction. * @return {string} Returns the extracted string. * @note Uses native `String.prototype.substring()` * @example * v.substring('beach', 1); * // => 'each' * * v.substring('ocean', 1, 3); * // => 'ea' */ function substring(subject, start, end) { return coerce_to_string.coerceToString(subject).substring(start, end); } module.exports = substring;