UNPKG

voca

Version:

The ultimate JavaScript string library

36 lines (31 loc) 1.05 kB
'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 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 coerce_to_string.coerceToString(subject).slice(start, end); } module.exports = slice;