UNPKG

sequency

Version:

Functional sequences for processing iterable data in JavaScript

59 lines 2.23 kB
Object.defineProperty(exports, "__esModule", { value: true }); exports.JoinToString = void 0; var defaults = { value: "", separator: ", ", prefix: "", postfix: "", limit: -1, truncated: "...", transform: undefined }; var JoinToString = /** @class */ (function () { function JoinToString() { } /** * Joins all elements of the sequence into a string with the given configuration. * * @param {JoinConfig<T>} config * @returns {string} */ JoinToString.prototype.joinToString = function (config) { if (config === void 0) { config = defaults; } var _a = config.value, value = _a === void 0 ? defaults.value : _a, _b = config.separator, separator = _b === void 0 ? defaults.separator : _b, _c = config.prefix, prefix = _c === void 0 ? defaults.prefix : _c, _d = config.postfix, postfix = _d === void 0 ? defaults.postfix : _d, _e = config.limit, limit = _e === void 0 ? defaults.limit : _e, _f = config.truncated, truncated = _f === void 0 ? defaults.truncated : _f, _g = config.transform, transform = _g === void 0 ? defaults.transform : _g; var result = "".concat(value).concat(prefix); var count = 0; for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) { count++; if (count > 1) { result += separator; } if (limit < 0 || count <= limit) { result += transform != null ? transform(item.value) : String(item.value); } else { break; } } if (limit >= 0 && count > limit) { result += truncated; } result += postfix; return result; }; /** * Joins all elements of the sequence into a string with the given configuration. * * @param {JoinConfig<T>} config * @returns {string} */ JoinToString.prototype.joinTo = function (config) { if (config === void 0) { config = defaults; } return this.joinToString(config); }; return JoinToString; }()); exports.JoinToString = JoinToString; //# sourceMappingURL=joinToString.js.map