UNPKG

voca

Version:

The ultimate JavaScript string library

34 lines (30 loc) 1.01 kB
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 slice * @static * @since 1.0.0 * @memberOf Chop * @param {string} [subject=''] The string to extract from. * @param {number} start The position to start extraction. If negative use `subject.length + start`. * @param {number} [end=subject.length] The position to end extraction. If negative use `subject.length + end`. * @return {string} Returns the extracted string. * @note Uses native `String.prototype.slice()` * @example * v.slice('miami', 1); * // => 'iami' * * v.slice('florida', -4); * // => 'rida' * * v.slice('florida', 1, 4); * // => "lor" */ function slice(subject, start, end) { return coerceToString(subject).slice(start, end); } export default slice;