stitch-compute
Version:
compute stitch adjustments for knitting
46 lines (45 loc) • 1.89 kB
JavaScript
/*
* Copyright (C) 2021 Christian Garbs <mitch@cgarbs.de>
* Licensed under GNU GPL v3 or later.
*
* This file is part of stitch-compute.
*
* stitch-compute is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* stitch-compute is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stitch-compute. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.GroupFormatter = void 0;
var string_replacer_1 = require("./string-replacer");
var GroupFormatter = /** @class */ (function () {
function GroupFormatter(template) {
this.template = template;
this.replacer = new string_replacer_1.StringReplacer();
this.check(template);
}
GroupFormatter.prototype.format = function (repetitions, content) {
return this.replacer.format(this.template, repetitions, content);
};
GroupFormatter.prototype.check = function (format) {
var numCount = (format.match(/%d/g) || []).length;
var stringCount = (format.match(/%s/g) || []).length;
if (numCount !== 1) {
throw new Error('formatter does not contain exactly one %d placeholder, but ' + numCount);
}
if (stringCount !== 1) {
throw new Error('formatter does not contain exactly one %s placeholder, but ' + stringCount);
}
};
return GroupFormatter;
}());
exports.GroupFormatter = GroupFormatter;
;