diff --git a/README.md b/README.md
index c38d901f..7a25cb3b 100644
--- a/README.md
+++ b/README.md
@@ -14,7 +14,7 @@ So, this utility attempts to handle everything. It:
- Will properly handle URLs with query parameters or a named anchor (i.e. hash)
- Will autolink email addresses.
- Will autolink phone numbers.
-- Will autolink mentions (Twitter, Instagram, Soundcloud).
+- Will autolink mentions (Twitter, Instagram, Soundcloud, TikTok).
- Will autolink hashtags.
- Will properly handle HTML input. The utility will not change the `href`
attribute inside anchor (<a>) tags (or any other tag/attribute),
@@ -161,12 +161,12 @@ These include:
- [mention](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-mention) : string
A string for the service name to have mentions (@username) auto-linked to. Supported
- values at this time are 'twitter', 'soundcloud' and 'instagram'. Pass `false` to skip
+ values at this time are 'twitter', 'soundcloud', 'instagram' and 'tiktok'. Pass `false` to skip
auto-linking of mentions. Defaults to `false`.
- [hashtag](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-hashtag) : boolean/string
A string for the service name to have hashtags auto-linked to. Supported
- values at this time are 'twitter', 'facebook' and 'instagram'. Pass `false` to skip
+ values at this time are 'twitter', 'facebook', 'instagram' and 'tiktok'. Pass `false` to skip
auto-linking of hashtags. Defaults to `false`.
- [stripPrefix](http://gregjacobs.github.io/Autolinker.js/api/#!/api/Autolinker-cfg-stripPrefix) : boolean
diff --git a/docs/api/source/hashtag-match.html b/docs/api/source/hashtag-match.html
index d2c2950e..8979cfa9 100644
--- a/docs/api/source/hashtag-match.html
+++ b/docs/api/source/hashtag-match.html
@@ -96,6 +96,8 @@
return 'https://www.facebook.com/hashtag/' + hashtag;
case 'instagram':
return 'https://instagram.com/explore/tags/' + hashtag;
+ case 'tiktok':
+ return 'https://www.tiktok.com/tag/' + hashtag;
default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
throw new Error('Unknown service name to point hashtag to: ' + serviceName);
}
diff --git a/docs/api/source/mention-match.html b/docs/api/source/mention-match.html
index 360a7e26..9d99f08e 100644
--- a/docs/api/source/mention-match.html
+++ b/docs/api/source/mention-match.html
@@ -93,6 +93,8 @@
return 'https://instagram.com/' + this.mention;
case 'soundcloud':
return 'https://soundcloud.com/' + this.mention;
+ case 'instagram':
+ return 'https://www.tiktok.com/@' + this.mention;
default: // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
throw new Error('Unknown service name to point mention to: ' + this.serviceName);
}
diff --git a/src/autolinker.ts b/src/autolinker.ts
index 26069ea1..bdee2875 100644
--- a/src/autolinker.ts
+++ b/src/autolinker.ts
@@ -1028,10 +1028,10 @@ export interface TruncateConfigObj {
}
export type HashtagConfig = false | HashtagServices;
-export type HashtagServices = 'twitter' | 'facebook' | 'instagram';
+export type HashtagServices = 'twitter' | 'facebook' | 'instagram' | 'tiktok';
export type MentionConfig = false | MentionServices;
-export type MentionServices = 'twitter' | 'instagram' | 'soundcloud';
+export type MentionServices = 'twitter' | 'instagram' | 'soundcloud' | 'tiktok';
export type ReplaceFn = ( match: Match ) => ReplaceFnReturn;
export type ReplaceFnReturn = boolean | string | HtmlTag | null | undefined | void;
\ No newline at end of file
diff --git a/src/match/hashtag-match.ts b/src/match/hashtag-match.ts
index 991c122a..da443f62 100644
--- a/src/match/hashtag-match.ts
+++ b/src/match/hashtag-match.ts
@@ -89,6 +89,8 @@ export class HashtagMatch extends Match {
return 'https://www.facebook.com/hashtag/' + hashtag;
case 'instagram' :
return 'https://instagram.com/explore/tags/' + hashtag;
+ case 'tiktok' :
+ return 'https://www.tiktok.com/tag/' + hashtag;
default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
throw new Error( 'Unknown service name to point hashtag to: ' + serviceName );
diff --git a/src/match/mention-match.ts b/src/match/mention-match.ts
index f35fe148..87467656 100644
--- a/src/match/mention-match.ts
+++ b/src/match/mention-match.ts
@@ -85,6 +85,8 @@ export class MentionMatch extends Match {
return 'https://instagram.com/' + this.mention;
case 'soundcloud' :
return 'https://soundcloud.com/' + this.mention;
+ case 'tiktok' :
+ return 'https://www.tiktok.com/@' + this.mention;
default : // Shouldn't happen because Autolinker's constructor should block any invalid values, but just in case.
throw new Error( 'Unknown service name to point mention to: ' + this.serviceName );
diff --git a/tests/autolinker-hashtag.spec.ts b/tests/autolinker-hashtag.spec.ts
index 7502e03a..3ab267e0 100644
--- a/tests/autolinker-hashtag.spec.ts
+++ b/tests/autolinker-hashtag.spec.ts
@@ -6,11 +6,13 @@ describe( `Autolinker Hashtag Matching -`, () => {
const twitterAutolinker = new Autolinker( { hashtag: 'twitter', newWindow: false } );
const facebookAutolinker = new Autolinker( { hashtag: 'facebook', newWindow: false } );
const instagramAutolinker = new Autolinker( { hashtag: 'instagram', newWindow: false } );
+ const tiktokAutolinker = new Autolinker( { hashtag: 'tiktok', newWindow: false } );
const services = [
{ serviceName: 'twitter', urlPrefix: 'https://twitter.com/hashtag', autolinker: twitterAutolinker },
{ serviceName: 'instagram', urlPrefix: 'https://instagram.com/explore/tags', autolinker: instagramAutolinker },
{ serviceName: 'facebook', urlPrefix: 'https://www.facebook.com/hashtag', autolinker: facebookAutolinker },
+ { serviceName: 'tiktok', urlPrefix: 'https://www.tiktok.com/tag', autolinker: tiktokAutolinker },
];
diff --git a/tests/autolinker-mention.spec.ts b/tests/autolinker-mention.spec.ts
index e50d1a49..a38b04f4 100644
--- a/tests/autolinker-mention.spec.ts
+++ b/tests/autolinker-mention.spec.ts
@@ -5,11 +5,13 @@ describe( "Autolinker Mention Matching -", () => {
const twitterAutolinker = new Autolinker( { mention: 'twitter', newWindow: false } )
const instagramAutolinker = new Autolinker( { mention: 'instagram', newWindow: false } );
const soundcloudAutolinker = new Autolinker( { mention: 'soundcloud', newWindow: false } );
+ const tiktokAutolinker = new Autolinker( { mention: 'soundcloud', newWindow: false } );
const services = [
{ serviceName: 'twitter', urlPrefix: 'https://twitter.com', autolinker: twitterAutolinker },
{ serviceName: 'instagram', urlPrefix: 'https://instagram.com', autolinker: instagramAutolinker },
{ serviceName: 'soundcloud', urlPrefix: 'https://soundcloud.com', autolinker: soundcloudAutolinker },
+ { serviceName: 'tiktok', urlPrefix: 'https://www.tiktok.com/@', autolinker: tiktokAutolinker },
];
it( `should not autolink mentions by default`, () => {
@@ -215,6 +217,25 @@ describe( "Autolinker Mention Matching -", () => {
} );
+ describe( 'tiktok-specific tests', () => {
+
+ it( 'should link a tiktok mention that is up to 24 characters long', () => {
+ const aUsername = _.repeat( 'a', 24 );
+ const bUsername = _.repeat( 'b', 25 ); // too long - don't link
+
+ const result = tiktokAutolinker.link( `@${aUsername} and @${bUsername}` );
+ expect( result ).toBe( `@${aUsername} and @${bUsername}` );
+ } );
+
+
+ it( `should link a tiktok mention that has a period in it`, () => {
+ const result = tiktokAutolinker.link( `Hello @asdf.defg` );
+
+ expect( result ).toBe( `Hello @asdf.defg` );
+ } );
+
+ } );
+
it( `should NOT automatically link a username that is actually part of an
email address when email address linking is turned on
diff --git a/tests/autolinker.spec.ts b/tests/autolinker.spec.ts
index b99848b9..e5c35a95 100644
--- a/tests/autolinker.spec.ts
+++ b/tests/autolinker.spec.ts
@@ -917,6 +917,9 @@ describe( "Autolinker", function() {
result = Autolinker.link( "hi from @iggypopschest", { newWindow: false, mention: 'instagram', className: 'myLink' } );
expect( result ).toBe( 'hi from @iggypopschest' );
+
+ result = Autolinker.link( "hi from @iggypopschest", { newWindow: false, mention: 'tiktok', className: 'myLink' } );
+ expect( result ).toBe( 'hi from @iggypopschest' );
} );
} );