UNPKG

@awayjs/core

Version:
50 lines (49 loc) 2.07 kB
import { __extends } from "tslib"; import { ConflictStrategyBase } from './ConflictStrategyBase'; var NumSuffixConflictStrategy = /** @class */ (function (_super) { __extends(NumSuffixConflictStrategy, _super); function NumSuffixConflictStrategy(separator) { if (separator === void 0) { separator = '.'; } var _this = _super.call(this) || this; _this._separator = separator; _this._next_suffix = {}; return _this; } NumSuffixConflictStrategy.prototype.resolveConflict = function (changedAsset, oldAsset, assetsDictionary, precedence) { var new_name; var base; var suffix; var orig = changedAsset.adaptee.name; if (orig.indexOf(this._separator) >= 0) { // Name has an ocurrence of the separator, so get base name and suffix, // unless suffix is non-numerical, in which case revert to zero and // use entire name as base base = orig.substring(0, orig.lastIndexOf(this._separator)); suffix = parseInt(orig.substring(base.length - 1)); if (isNaN(suffix)) { base = orig; suffix = 0; } } else { base = orig; suffix = 0; } if (suffix == 0 && this._next_suffix.hasOwnProperty(base)) { suffix = this._next_suffix[base]; } // Find the first suffixed name that does // not collide with other names. do { suffix++; new_name = base.concat(this._separator, suffix.toString()); } while (assetsDictionary.hasOwnProperty(new_name)); this._next_suffix[base] = suffix; this._pUpdateNames(oldAsset.adaptee.assetNamespace, new_name, oldAsset, changedAsset, assetsDictionary, precedence); }; NumSuffixConflictStrategy.prototype.create = function () { return new NumSuffixConflictStrategy(this._separator); }; return NumSuffixConflictStrategy; }(ConflictStrategyBase)); export { NumSuffixConflictStrategy };