lmfresneda / mention-hashtag

Extract mentions (@mention) or hashtags (#hashtag) from any text

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add TypeScript type definitions

francisbrito opened this issue · comments

They would be useful for those of us using TS.

Here's the current definition I'm using:

declare module 'mention-hashtag' {
  export enum ExtractionType {
    MENTION = '@',
    HASH_TAG = '#',
    ALL = 'all',
  }
  export type ExtractionOptions = { type: ExtractionType; unique: boolean; symbol: boolean };
  export type ExtractionResult = { mentions: string[]; hashtags: string[] };

  function extract(text: string, options: ExtractionType.ALL): ExtractionResult;
  function extract(
    text: string,
    options: ExtractionOptions | ExtractionType.MENTION | ExtractionType.HASH_TAG,
  ): string[];

  export default extract;
}

I'm not sure if its the best approach, but it does the work. Are you OK with a PR for this?

Of course! Thanks!

They would be useful for those of us using TS.

Here's the current definition I'm using:

declare module 'mention-hashtag' {
  export enum ExtractionType {
    MENTION = '@',
    HASH_TAG = '#',
    ALL = 'all',
  }
  export type ExtractionOptions = { type: ExtractionType; unique: boolean; symbol: boolean };
  export type ExtractionResult = { mentions: string[]; hashtags: string[] };

  function extract(text: string, options: ExtractionType.ALL): ExtractionResult;
  function extract(
    text: string,
    options: ExtractionOptions | ExtractionType.MENTION | ExtractionType.HASH_TAG,
  ): string[];

  export default extract;
}

I'm not sure if its the best approach, but it does the work. Are you OK with a PR for this?

been a couple of years, but do you want to do that PR?

@mattbodman It's been a while since I last used this package, but, sure, I can do it