refactor(client): use ReadonlyArray for getter return types
This commit is contained in:
parent
61778dba8e
commit
d8cd13fd60
14 changed files with 17 additions and 17 deletions
|
@ -36,5 +36,5 @@ export interface IMessageEntityParser {
|
||||||
* @param text Plain text
|
* @param text Plain text
|
||||||
* @param entities Message entities that should be added to the text
|
* @param entities Message entities that should be added to the text
|
||||||
*/
|
*/
|
||||||
unparse(text: string, entities: MessageEntity[]): string
|
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export class TermsOfService {
|
||||||
/**
|
/**
|
||||||
* Terms of Service entities text
|
* Terms of Service entities text
|
||||||
*/
|
*/
|
||||||
get entities(): MessageEntity[] {
|
get entities(): ReadonlyArray<MessageEntity> {
|
||||||
if (!this._entities) {
|
if (!this._entities) {
|
||||||
this._entities = this.tos.entities
|
this._entities = this.tos.entities
|
||||||
.map((it) => MessageEntity._parse(it))
|
.map((it) => MessageEntity._parse(it))
|
||||||
|
|
|
@ -71,7 +71,7 @@ export class RawDocument extends FileLocation {
|
||||||
*
|
*
|
||||||
* If there are no thumbnails, the array will be empty.
|
* If there are no thumbnails, the array will be empty.
|
||||||
*/
|
*/
|
||||||
get thumbnails(): Thumbnail[] {
|
get thumbnails(): ReadonlyArray<Thumbnail> {
|
||||||
if (!this._thumbnails) {
|
if (!this._thumbnails) {
|
||||||
this._thumbnails = this.doc.thumbs
|
this._thumbnails = this.doc.thumbs
|
||||||
? this.doc.thumbs.map(
|
? this.doc.thumbs.map(
|
||||||
|
|
|
@ -84,7 +84,7 @@ export class Photo extends FileLocation {
|
||||||
* **Note**: This list will also contain the largest thumbnail that is
|
* **Note**: This list will also contain the largest thumbnail that is
|
||||||
* represented by the current object.
|
* represented by the current object.
|
||||||
*/
|
*/
|
||||||
get thumbnails(): Thumbnail[] {
|
get thumbnails(): ReadonlyArray<Thumbnail> {
|
||||||
if (!this._thumbnails) {
|
if (!this._thumbnails) {
|
||||||
this._thumbnails = this.raw.sizes.map(
|
this._thumbnails = this.raw.sizes.map(
|
||||||
(sz) => new Thumbnail(this.client, this.raw, sz)
|
(sz) => new Thumbnail(this.client, this.raw, sz)
|
||||||
|
|
|
@ -74,7 +74,7 @@ export class Poll {
|
||||||
/**
|
/**
|
||||||
* List of answers in this poll
|
* List of answers in this poll
|
||||||
*/
|
*/
|
||||||
get answers(): Poll.PollAnswer[] {
|
get answers(): ReadonlyArray<Poll.PollAnswer> {
|
||||||
if (!this._answers) {
|
if (!this._answers) {
|
||||||
const results = this.results?.results
|
const results = this.results?.results
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ export class Poll {
|
||||||
* Format entities for {@link solution}, only available
|
* Format entities for {@link solution}, only available
|
||||||
* in case you have already answered
|
* in case you have already answered
|
||||||
*/
|
*/
|
||||||
get solutionEntities(): MessageEntity[] | null {
|
get solutionEntities(): ReadonlyArray<MessageEntity> | null {
|
||||||
if (!this.results) return null
|
if (!this.results) return null
|
||||||
|
|
||||||
if (!this._entities) {
|
if (!this._entities) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ export class DraftMessage {
|
||||||
/**
|
/**
|
||||||
* Message text entities (may be empty)
|
* Message text entities (may be empty)
|
||||||
*/
|
*/
|
||||||
get entities(): MessageEntity[] {
|
get entities(): ReadonlyArray<MessageEntity> {
|
||||||
if (!this._entities) {
|
if (!this._entities) {
|
||||||
this._entities = []
|
this._entities = []
|
||||||
if (this.raw.entities?.length) {
|
if (this.raw.entities?.length) {
|
||||||
|
|
|
@ -362,7 +362,7 @@ export class Message {
|
||||||
/**
|
/**
|
||||||
* Message text/caption entities (may be empty)
|
* Message text/caption entities (may be empty)
|
||||||
*/
|
*/
|
||||||
get entities(): MessageEntity[] {
|
get entities(): ReadonlyArray<MessageEntity> {
|
||||||
if (this._emptyError) throw this._emptyError
|
if (this._emptyError) throw this._emptyError
|
||||||
|
|
||||||
if (!this._entities) {
|
if (!this._entities) {
|
||||||
|
|
|
@ -133,7 +133,7 @@ export class StickerSet {
|
||||||
* @throws MtCuteEmptyError
|
* @throws MtCuteEmptyError
|
||||||
* In case this object does not contain info about stickers (i.e. {@link isFull} = false)
|
* In case this object does not contain info about stickers (i.e. {@link isFull} = false)
|
||||||
*/
|
*/
|
||||||
get stickers(): StickerSet.StickerInfo[] {
|
get stickers(): ReadonlyArray<StickerSet.StickerInfo> {
|
||||||
if (!this.isFull) throw new MtCuteEmptyError()
|
if (!this.isFull) throw new MtCuteEmptyError()
|
||||||
|
|
||||||
if (!this._stickers) {
|
if (!this._stickers) {
|
||||||
|
|
|
@ -76,7 +76,7 @@ export class ChatPreview {
|
||||||
* and members that are inside your contacts list are
|
* and members that are inside your contacts list are
|
||||||
* ordered before others.
|
* ordered before others.
|
||||||
*/
|
*/
|
||||||
get someMembers(): User[] {
|
get someMembers(): ReadonlyArray<User> {
|
||||||
if (!this._someMembers) {
|
if (!this._someMembers) {
|
||||||
this._someMembers = this.invite.participants
|
this._someMembers = this.invite.participants
|
||||||
? this.invite.participants.map(
|
? this.invite.participants.map(
|
||||||
|
|
|
@ -355,7 +355,7 @@ export class Chat {
|
||||||
* The list of reasons why this chat might be unavailable to some users.
|
* The list of reasons why this chat might be unavailable to some users.
|
||||||
* This field is available only in case {@link isRestricted} is `true`
|
* This field is available only in case {@link isRestricted} is `true`
|
||||||
*/
|
*/
|
||||||
get restrictions(): tl.RawRestrictionReason[] | null {
|
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
|
||||||
return 'restrictionReason' in this.peer
|
return 'restrictionReason' in this.peer
|
||||||
? this.peer.restrictionReason ?? null
|
? this.peer.restrictionReason ?? null
|
||||||
: null
|
: null
|
||||||
|
|
|
@ -246,7 +246,7 @@ export class User {
|
||||||
* The list of reasons why this bot might be unavailable to some users.
|
* The list of reasons why this bot might be unavailable to some users.
|
||||||
* This field is available only in case *isRestricted* is `true`
|
* This field is available only in case *isRestricted* is `true`
|
||||||
*/
|
*/
|
||||||
get restrictions(): tl.RawRestrictionReason[] | null {
|
get restrictions(): ReadonlyArray<tl.RawRestrictionReason> | null {
|
||||||
return this._user.restrictionReason ?? null
|
return this._user.restrictionReason ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ export class PollVoteUpdate {
|
||||||
* This might break at any time, but seems to be consistent for now.
|
* This might break at any time, but seems to be consistent for now.
|
||||||
* To get chosen answer indexes derived as before, use {@link chosenIndexesAuto}.
|
* To get chosen answer indexes derived as before, use {@link chosenIndexesAuto}.
|
||||||
*/
|
*/
|
||||||
get chosen(): Buffer[] {
|
get chosen(): ReadonlyArray<Buffer> {
|
||||||
return this.raw.options
|
return this.raw.options
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ export class PollVoteUpdate {
|
||||||
*
|
*
|
||||||
* If something does not add up, {@link MtCuteUnsupportedError} is thrown
|
* If something does not add up, {@link MtCuteUnsupportedError} is thrown
|
||||||
*/
|
*/
|
||||||
get chosenIndexesAuto(): number[] {
|
get chosenIndexesAuto(): ReadonlyArray<number> {
|
||||||
return this.raw.options.map((buf) => {
|
return this.raw.options.map((buf) => {
|
||||||
if (buf.length > 1)
|
if (buf.length > 1)
|
||||||
throw new MtCuteUnsupportedError('option had >1 byte')
|
throw new MtCuteUnsupportedError('option had >1 byte')
|
||||||
|
|
|
@ -169,14 +169,14 @@ export class HtmlMessageEntityParser implements IMessageEntityParser {
|
||||||
return [plainText, entities]
|
return [plainText, entities]
|
||||||
}
|
}
|
||||||
|
|
||||||
unparse(text: string, entities: MessageEntity[]): string {
|
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string {
|
||||||
return this._unparse(text, entities)
|
return this._unparse(text, entities)
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal function that uses recursion to correctly process nested & overlapping entities
|
// internal function that uses recursion to correctly process nested & overlapping entities
|
||||||
private _unparse(
|
private _unparse(
|
||||||
text: string,
|
text: string,
|
||||||
entities: MessageEntity[],
|
entities: ReadonlyArray<MessageEntity>,
|
||||||
entitiesOffset = 0,
|
entitiesOffset = 0,
|
||||||
offset = 0,
|
offset = 0,
|
||||||
length = text.length
|
length = text.length
|
||||||
|
|
|
@ -244,7 +244,7 @@ export class MarkdownMessageEntityParser implements IMessageEntityParser {
|
||||||
return [result, entities]
|
return [result, entities]
|
||||||
}
|
}
|
||||||
|
|
||||||
unparse(text: string, entities: MessageEntity[]): string {
|
unparse(text: string, entities: ReadonlyArray<MessageEntity>): string {
|
||||||
// keep track of positions of inserted escape symbols
|
// keep track of positions of inserted escape symbols
|
||||||
const escaped: number[] = []
|
const escaped: number[] = []
|
||||||
text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {
|
text = text.replace(TO_BE_ESCAPED, (s, pos: number) => {
|
||||||
|
|
Loading…
Reference in a new issue