UNPKG

stitch-compute

Version:

compute stitch adjustments for knitting

42 lines (41 loc) 1.65 kB
"use strict"; /* * 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.NumberFormatter = void 0; var string_replacer_1 = require("./string-replacer"); var NumberFormatter = /** @class */ (function () { function NumberFormatter(template) { this.template = template; this.replacer = new string_replacer_1.StringReplacer(); this.check(template); } NumberFormatter.prototype.format = function (value) { return this.replacer.format(this.template, value); }; NumberFormatter.prototype.check = function (format) { var count = (format.match(/%d/g) || []).length; if (count !== 1) { throw new Error('formatter does not contain exactly one %d placeholder, but ' + count); } }; return NumberFormatter; }()); exports.NumberFormatter = NumberFormatter;