voca
Version:
The ultimate JavaScript string library
31 lines (27 loc) • 910 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 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 coerceToString(subject).substring(start, end);
}
export default substring;