@technobuddha/library
Version:
A large library of useful functions
24 lines (23 loc) • 883 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.delimited = void 0;
var constants_1 = require("../constants");
/**
* Return a field from a delimited string
*
* @param input The delimited string
* @param delimiter The delimiter string
* @param index The position of the desired field, 0 is the first field, negative numbers count backwards from the end (default 0)
* @param count The number of fields to return (default 1)
*/
function delimited(input, delimiter, index, count) {
if (index === void 0) { index = 0; }
if (count === void 0) { count = 1; }
if (count <= 0)
return constants_1.empty;
var splits = input.split(delimiter);
var start = index < 0 ? splits.length + index : index;
return splits.slice(start, start + count).join(delimiter);
}
exports.delimited = delimited;
exports.default = delimited;