@technobuddha/library
Version:
A large library of useful functions
23 lines (22 loc) • 932 B
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.chop = void 0;
var constants_1 = require("../constants");
var isFinite_1 = __importDefault(require("lodash/isFinite"));
/**
* Break a string into equal sized segments of characters
*
* @param input The string to break apart
* @param length The length of each segment
* @returns Array of segments
*/
function chop(input, length, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.truncate, truncate = _c === void 0 ? false : _c;
// eslint-disable-next-line @typescript-eslint/prefer-regexp-exec
return length > 0 && isFinite_1.default(length) ? input.match(new RegExp(".{" + (truncate ? constants_1.empty : '1,') + length + "}", 'gu')) : [input];
}
exports.chop = chop;
exports.default = chop;