@altostra/core
Version:
Core library for shared types and logic
1 lines • 3.67 kB
JavaScript
"use strict";var _UnicodeSubsetAlphabet_start,_UnicodeSubsetAlphabet_end,__classPrivateFieldSet=this&&this.__classPrivateFieldSet||function(e,t,i,s,a){if("m"===s)throw new TypeError("Private method is not writable");if("a"===s&&!a)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===s?a.call(e,i):a?a.value=i:t.set(e,i),i},__classPrivateFieldGet=this&&this.__classPrivateFieldGet||function(e,t,i,s){if("a"===i&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!s:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?s:"a"===i?s.call(e):s?s.value:t.get(e)};Object.defineProperty(exports,"__esModule",{value:!0}),exports.UnicodeSubsetAlphabet=void 0;const Errors_1=require("../Errors"),UNICODE_MAX=1114111,UTF16_SURROGATES_START=55296,UTF16_SURROGATES_END=57343,UTF16_SURROGATES_COUNT=2048;class UnicodeSubsetAlphabet{constructor({start:e=0,end:t=1114111}={}){if(_UnicodeSubsetAlphabet_start.set(this,void 0),_UnicodeSubsetAlphabet_end.set(this,void 0),"number"==typeof e)__classPrivateFieldSet(this,_UnicodeSubsetAlphabet_start,e,"f");else{if(0===e.length)throw Errors_1.AltoError.create("Invalid start string",{data:{start:e}});__classPrivateFieldSet(this,_UnicodeSubsetAlphabet_start,e.codePointAt(0),"f")}if("number"==typeof t)__classPrivateFieldSet(this,_UnicodeSubsetAlphabet_end,t,"f");else{if(0===t.length)throw Errors_1.AltoError.create("Invalid end string",{data:{end:t}});__classPrivateFieldSet(this,_UnicodeSubsetAlphabet_end,t.codePointAt(0),"f")}if(__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f")>__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f"))throw Errors_1.AltoError.create("Invalid parameters. Start must be smaller than end",{data:{start:e,end:t}});const i=__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f")-__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f")+1-diffFromCodepoint(__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f")-__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"),__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"));this.length=i}getAt(e){const t=(e+=__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"))<55296?0:2048;return String.fromCodePoint(e+t)}indexOf(e){const t=e.codePointAt(0),i=(t>57343?t-2048:t)-__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f");return i<0||i>__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f")?-1:i}*[(_UnicodeSubsetAlphabet_start=new WeakMap,_UnicodeSubsetAlphabet_end=new WeakMap,Symbol.iterator)](){const e=Math.min(__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f")+1,55296);for(let t=Math.min(__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"),55296);t<e;t++)yield String.fromCodePoint(t);for(let e=Math.max(__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"),57344);e<=__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f");e++)yield String.fromCodePoint(e)}has(e){const t=e.codePointAt(0),i=t-diffFromCodepoint(t,__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f"));return i>=__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_start,"f")&&i<=__classPrivateFieldGet(this,_UnicodeSubsetAlphabet_end,"f")}}function diffFromCodepoint(e,t){const i=e+t;return i<55296?0:Math.min(i,57344)-55296}exports.UnicodeSubsetAlphabet=UnicodeSubsetAlphabet,UnicodeSubsetAlphabet.unicode=new UnicodeSubsetAlphabet,UnicodeSubsetAlphabet.ascii=new UnicodeSubsetAlphabet({end:127});