UNPKG

@angular-package/wrapper

Version:

Wrap the text with the opening and closing chars.

172 lines (168 loc) 6.53 kB
import { __classPrivateFieldSet, __classPrivateFieldGet } from 'tslib'; var _Wrap_closing, _Wrap_opening, _Wrap_text; class Wrap extends String { constructor(opening, closing, text = '') { super(`${opening}${text}${closing}`); _Wrap_closing.set(this, void 0); _Wrap_opening.set(this, void 0); _Wrap_text.set(this, void 0); __classPrivateFieldSet(this, _Wrap_closing, String(closing), "f"); __classPrivateFieldSet(this, _Wrap_text, String(text), "f"); __classPrivateFieldSet(this, _Wrap_opening, String(opening), "f"); } get closing() { return __classPrivateFieldGet(this, _Wrap_closing, "f"); } get opening() { return __classPrivateFieldGet(this, _Wrap_opening, "f"); } get text() { return __classPrivateFieldGet(this, _Wrap_text, "f"); } get [(_Wrap_closing = new WeakMap(), _Wrap_opening = new WeakMap(), _Wrap_text = new WeakMap(), Symbol.toStringTag)]() { return 'Wrap'; } static hasClosing(text, closing) { return (typeof text === 'string' && text.length >= 1 && typeof closing === 'string' && closing.length >= 1 && text.slice(-closing.length) === closing); } static hasOpening(text, opening) { return (typeof text === 'string' && text.length >= 1 && typeof opening === 'string' && opening.length >= 1 && text.slice(0, opening.length) === opening); } static isWrap(value, opening, closing, text) { return typeof value === 'object' && value instanceof this ? (typeof opening === 'string' ? opening === value.opening : true) && (typeof closing === 'string' ? closing === value.closing : true) && (typeof text === 'string' ? text === value.text : true) : false; } getClosing() { return __classPrivateFieldGet(this, _Wrap_closing, "f"); } getOpening() { return __classPrivateFieldGet(this, _Wrap_opening, "f"); } getText() { return __classPrivateFieldGet(this, _Wrap_text, "f"); } hasClosing(closing) { return (__classPrivateFieldGet(this, _Wrap_closing, "f").length >= 1 && (typeof closing === 'string' ? __classPrivateFieldGet(this, _Wrap_closing, "f") === closing : true)); } hasOpening(opening) { return (__classPrivateFieldGet(this, _Wrap_opening, "f").length >= 1 && (typeof opening === 'string' ? __classPrivateFieldGet(this, _Wrap_opening, "f") === opening : true)); } hasText(text) { return (__classPrivateFieldGet(this, _Wrap_text, "f").length >= 1 && (typeof text === 'string' ? __classPrivateFieldGet(this, _Wrap_text, "f") === text : true)); } isWrapped(opening = __classPrivateFieldGet(this, _Wrap_opening, "f"), closing = __classPrivateFieldGet(this, _Wrap_closing, "f")) { return this.hasOpening(opening) && this.hasClosing(closing); } replaceClosing(closing) { return `${__classPrivateFieldGet(this, _Wrap_opening, "f")}${__classPrivateFieldGet(this, _Wrap_text, "f")}${closing}`; } replaceOpening(opening) { return `${opening}${__classPrivateFieldGet(this, _Wrap_text, "f")}${__classPrivateFieldGet(this, _Wrap_closing, "f")}`; } replaceText(text) { return `${__classPrivateFieldGet(this, _Wrap_opening, "f")}${text}${__classPrivateFieldGet(this, _Wrap_closing, "f")}`; } toString() { return super.toString(); } valueOf() { return super.valueOf(); } } class Wrapper extends Wrap { get [Symbol.toStringTag]() { return 'Wrapper'; } static define(opening, closing, text) { return new this(opening, closing, text); } static isWrapper(value, opening, closing, text) { return (typeof value === 'object' && value instanceof this && super.isWrap(value, opening, closing, text)); } static replaceClosing(text, closing, replaceValue) { return this.hasClosing(text, closing) ? text.slice(0, -closing.length) + replaceValue : text; } static replaceOpening(text, opening, replaceValue) { return this.hasOpening(text, opening) ? text.replace(opening, String(replaceValue)) : text; } static unwrap(text, opening, closing) { return ((text = this.replaceClosing(text, closing, '')), (text = this.replaceOpening(text, opening, '')), text); } constructor(opening, closing, text = '') { super(opening, closing, text); } isClosingIn(text) { return Wrapper.hasClosing(text, this.closing); } isOpeningIn(text) { return Wrapper.hasOpening(text, this.opening); } replaceClosingIn(text, replaceValue) { return Wrapper.replaceClosing(text, this.closing, replaceValue); } replaceOpeningIn(text, replaceValue) { return Wrapper.replaceOpening(text, this.opening, replaceValue); } removeWrapIn(text) { return ((text = this.replaceClosingIn(text, '')), (text = this.replaceOpeningIn(text, '')), text); } textReplaceClosing(closing) { return Wrapper.replaceClosing(this.text, this.closing, closing); } textReplaceOpening(opening) { return Wrapper.replaceOpening(this.text, this.opening, opening); } textUnwrap(opening = this.opening, closing = this.closing) { return Wrapper.unwrap(this.text, opening, closing); } textWrap(opening, closing) { return new Wrap(opening, closing, this.text).valueOf(); } toArray() { return [this.opening, this.text, this.closing]; } toWrap() { return new Wrap(this.opening, this.closing, this.text); } unwrap() { return this.text; } unwrapText(opening = this.opening, closing = this.closing) { return `${this.opening}${Wrapper.unwrap(this.text, opening, closing)}${this.closing}`; } wrap(opening = this.opening, closing = this.closing) { return new Wrap(opening, closing, this.valueOf()).valueOf(); } wrapOn(text) { return new Wrap(this.opening, this.closing, text).valueOf(); } wrapText(opening, closing) { return `${this.opening}${this.textWrap(opening, closing)}${this.closing}`; } } export { Wrap, Wrapper }; //# sourceMappingURL=angular-package-wrapper.mjs.map