UNPKG

@msay2/tspoet

Version:

TSPoet is a mean to create TypeScript source files.

133 lines 4.82 kB
"use strict"; /** * @ Author: Yoann Meclot. MSay2 * @ Created on: 2021-06-14 17:49:33 * @ Modified on: 2021-06-14 17:55:12 */ /** * Copyright (c) 2020-2021 MSay2 (Yoann Meclot) - @msay2/tspoet * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, privateMap, value) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to set private field on non-instance"); } privateMap.set(receiver, value); return value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, privateMap) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to get private field on non-instance"); } return privateMap.get(receiver); }; var _mAscending; Object.defineProperty(exports, "__esModule", { value: true }); exports.ImportablesNamesComparator = void 0; const Utils_js_1 = require("./Utils.js"); class ImportablesNamesComparator { constructor(ascending) { _mAscending.set(this, void 0); __classPrivateFieldSet(this, _mAscending, ascending); } static descending() { return new ImportablesNamesComparator(1); } static ascending() { return new ImportablesNamesComparator(-1); } compare(o1, o2) { return __classPrivateFieldGet(this, _mAscending) * this.compareName(o1.asType().getName(), o2.asType().getName()); } compareName(name1, name2) { let i; let i2; let i3; let char1; let char2; let length1 = name1.length; let length2 = name2.length; let i4 = 0; if (length2 < length1) { i2 = length2; i = 0; } else { i2 = length1; i = 0; } while (i < i2) { let charAt1 = name1.charCodeAt(i); let charAt2 = name2.charCodeAt(i); let i5 = charAt1 - charAt2; if (i5 != 0) { let f1 = this.find(charAt1); let f2 = this.find(charAt2); i3 = f1 - f2; char1 = f1; char2 = f2; } else { i3 = i5; char1 = charAt1; char2 = charAt2; } if (char1 <= Utils_js_1.UCharacter.getChar('9') && char2 <= Utils_js_1.UCharacter.getChar('9') && char1 >= Utils_js_1.UCharacter.getChar('0') && char2 >= Utils_js_1.UCharacter.getChar('0')) { if (i4 != 0) i3 = i4; let is = (length2 - i) < 2; if ((length1 - i) < 2) { if (!is) return -1; return i3; } else if (is) return 1; else { let isDigit = this.isDigit(name2.charCodeAt(i + 1)); if (this.isDigit(name1.charCodeAt(i + 1))) { if (isDigit && i3 != 0) return i3; if (!isDigit) return -1; } else if (isDigit) return 1; } } else if (i3 != 0) return i3; else i3 = 0; i++; i4 = i3; } return length1 - length2; } isDigit(char) { return char > Utils_js_1.UCharacter.getChar('9') || char < Utils_js_1.UCharacter.getChar('0'); } find(char) { let space = Utils_js_1.UCharacter.getChar(' '); let dot = Utils_js_1.UCharacter.getChar('.'); if (char == space) return dot; if (char == dot) return space; return char < 128 ? (Utils_js_1.UCharacter.getChar('A') > char || char > Utils_js_1.UCharacter.getChar('Z')) ? char : (char + space) : Utils_js_1.UCharacter.toLowerCase(char); } } exports.ImportablesNamesComparator = ImportablesNamesComparator; _mAscending = new WeakMap(); //# sourceMappingURL=ImportablesNamesComparator.js.map