Skip to content

Commit 912eaf5

Browse files
committed
Export all Autolinker interfaces from index.ts
1 parent fac28a4 commit 912eaf5

File tree

9 files changed

+62
-32
lines changed

9 files changed

+62
-32
lines changed

gulpfile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ gulp.task( 'do-build-src', gulp.series(
5959
'build-src-add-header-to-umd',
6060
'build-src-minify-umd',
6161
'build-src-check-minfied-size'
62-
), )
62+
) );
6363

6464
// Build example private tasks
6565
gulp.task( 'clean-example-output', cleanExampleOutputTask );
@@ -99,6 +99,7 @@ gulp.task( 'do-test', gulp.series(
9999
'run-integration-tests'
100100
) );
101101
gulp.task( 'do-unit-tests', gulp.series( 'build-unit-tests', 'run-unit-tests' ) ); // just runs the unit tests without the integration tests
102+
gulp.task( 'do-integration-tests', gulp.series( 'build-integration-tests', 'run-integration-tests' ) ); // just runs the integration tests without the unit tests
102103

103104

104105
// Main Tasks
@@ -123,6 +124,7 @@ gulp.task( 'doc', gulp.series( 'build-src', 'do-doc' ) );
123124
gulp.task( 'serve', gulp.series( 'build-src', 'build-example', serveTask ) );
124125
gulp.task( 'test', gulp.series( 'build-src', 'build-example', 'clean-tests', 'do-test' ) );
125126
gulp.task( 'test-unit', gulp.series( 'clean-unit-tests', 'do-unit-tests' ) ); // just runs the unit tests without the integration tests
127+
gulp.task( 'test-integration', gulp.series( 'build-src', 'clean-integration-tests', 'do-integration-tests' ) ); // just runs the integration tests without the unit tests
126128
gulp.task( 'update-tld-regex', updateTldRegex );
127129

128130
gulp.task( 'default', gulp.series( 'build-all', 'do-doc', 'do-test' ) );

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"serve": "gulp serve",
2222
"test": "gulp test",
2323
"test-unit": "gulp test-unit",
24+
"test-integration": "gulp test-integration",
2425
"update-tld-regex": "gulp update-tld-regex"
2526
},
2627
"repository": {

src/anchor-tag-builder.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Match } from "./match/match";
22
import { HtmlTag } from "./html-tag";
3-
import { TruncateConfig } from "./autolinker";
3+
import { TruncateConfigObj } from "./autolinker";
44
import { truncateSmart } from "./truncate/truncate-smart";
55
import { truncateMiddle } from "./truncate/truncate-middle";
66
import { truncateEnd } from "./truncate/truncate-end";
@@ -43,7 +43,7 @@ export class AnchorTagBuilder {
4343
* @cfg {Object} truncate
4444
* @inheritdoc Autolinker#truncate
4545
*/
46-
private readonly truncate: TruncateConfig = {}; // default value just to get the above doc comment in the ES5 output and documentation generator
46+
private readonly truncate: TruncateConfigObj = {}; // default value just to get the above doc comment in the ES5 output and documentation generator
4747

4848
/**
4949
* @cfg {String} className
@@ -200,6 +200,6 @@ export class AnchorTagBuilder {
200200

201201
export interface AnchorTagBuilderCfg {
202202
newWindow?: boolean;
203-
truncate?: TruncateConfig;
203+
truncate?: TruncateConfigObj;
204204
className?: string
205205
}

src/autolinker.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export default class Autolinker {
280280
* in the given text. Ex: `google.com`, `asdf.org/?page=1`, etc. `false`
281281
* to prevent these types of matches.
282282
*/
283-
private readonly urls: UrlsConfig = {}; // default value just to get the above doc comment in the ES5 output and documentation generator
283+
private readonly urls: UrlsConfigObj = {}; // default value just to get the above doc comment in the ES5 output and documentation generator
284284

285285
/**
286286
* @cfg {Boolean} [email=true]
@@ -310,7 +310,7 @@ export default class Autolinker {
310310
*
311311
* Pass `false` to skip auto-linking of hashtags.
312312
*/
313-
private readonly hashtag: false | HashtagServices = false; // default value just to get the above doc comment in the ES5 output and documentation generator
313+
private readonly hashtag: HashtagConfig = false; // default value just to get the above doc comment in the ES5 output and documentation generator
314314

315315
/**
316316
* @cfg {String/Boolean} [mention=false]
@@ -324,7 +324,7 @@ export default class Autolinker {
324324
*
325325
* Defaults to `false` to skip auto-linking of mentions.
326326
*/
327-
private readonly mention: false | MentionServices = false; // default value just to get the above doc comment in the ES5 output and documentation generator
327+
private readonly mention: MentionConfig = false; // default value just to get the above doc comment in the ES5 output and documentation generator
328328

329329
/**
330330
* @cfg {Boolean} [newWindow=true]
@@ -366,7 +366,7 @@ export default class Autolinker {
366366
* `'www.google.com'` will be displayed as `'google.com'`. `false` to not
367367
* strip the `'www'`.
368368
*/
369-
private readonly stripPrefix: StripPrefixConfig = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
369+
private readonly stripPrefix: Required<StripPrefixConfigObj> = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
370370

371371
/**
372372
* @cfg {Boolean} [stripTrailingSlash=true]
@@ -437,7 +437,7 @@ export default class Autolinker {
437437
* 'yahoo.com/some..to/a/file'. For more details, see
438438
* {@link Autolinker.truncate.TruncateSmart}.
439439
*/
440-
private readonly truncate: TruncateConfig = { length: 0, location : 'end' }; // default value just to get the above doc comment in the ES5 output and documentation generator
440+
private readonly truncate: Required<TruncateConfigObj> = { length: 0, location : 'end' }; // default value just to get the above doc comment in the ES5 output and documentation generator
441441

442442
/**
443443
* @cfg {String} className
@@ -474,7 +474,7 @@ export default class Autolinker {
474474
* is currently processing. See {@link Autolinker.match.Match} subclasses
475475
* for details.
476476
*/
477-
private readonly replaceFn: null | ( ( match: Match ) => ReplaceFnReturn ) = null; // default value just to get the above doc comment in the ES5 output and documentation generator
477+
private readonly replaceFn: ReplaceFn | null = null; // default value just to get the above doc comment in the ES5 output and documentation generator
478478

479479
/**
480480
* @cfg {Object} context
@@ -554,7 +554,9 @@ export default class Autolinker {
554554
* @param {Boolean/Object} urls
555555
* @return {Object}
556556
*/
557-
private normalizeUrlsCfg( urls: boolean | UrlsConfig | undefined ): UrlsConfig {
557+
private normalizeUrlsCfg(
558+
urls: UrlsConfig | undefined
559+
): Required<UrlsConfigObj> {
558560
if( urls == null ) urls = true; // default to `true`
559561

560562
if( typeof urls === 'boolean' ) {
@@ -580,7 +582,9 @@ export default class Autolinker {
580582
* @param {Boolean/Object} stripPrefix
581583
* @return {Object}
582584
*/
583-
private normalizeStripPrefixCfg( stripPrefix: boolean | StripPrefixConfig | undefined ) {
585+
private normalizeStripPrefixCfg(
586+
stripPrefix: StripPrefixConfig | undefined
587+
): Required<StripPrefixConfigObj> {
584588
if( stripPrefix == null ) stripPrefix = true; // default to `true`
585589

586590
if( typeof stripPrefix === 'boolean' ) {
@@ -605,7 +609,9 @@ export default class Autolinker {
605609
* @param {Number/Object} truncate
606610
* @return {Object}
607611
*/
608-
private normalizeTruncateCfg( truncate: number | TruncateConfig | undefined ): TruncateConfig {
612+
private normalizeTruncateCfg(
613+
truncate: TruncateConfig | undefined
614+
): Required<TruncateConfigObj> {
609615
if( typeof truncate === 'number' ) {
610616
return { length: truncate, location: 'end' };
611617

@@ -957,40 +963,47 @@ export default class Autolinker {
957963

958964

959965
export interface AutolinkerConfig {
960-
urls?: boolean | UrlsConfig;
966+
urls?: UrlsConfig;
961967
email?: boolean;
962968
phone?: boolean;
963-
hashtag?: false | HashtagServices;
964-
mention?: false | MentionServices;
969+
hashtag?: HashtagConfig;
970+
mention?: MentionConfig;
965971
newWindow?: boolean;
966-
stripPrefix?: boolean | StripPrefixConfig;
972+
stripPrefix?: StripPrefixConfig;
967973
stripTrailingSlash?: boolean;
968-
truncate?: number | TruncateConfig;
974+
truncate?: TruncateConfig;
969975
className?: string;
970-
replaceFn?: ( match: Match ) => ReplaceFnReturn | null;
976+
replaceFn?: ReplaceFn | null;
971977
context?: any;
972978
decodePercentEncoding?: boolean;
973979
}
974980

975-
export interface UrlsConfig {
981+
export type UrlsConfig = boolean | UrlsConfigObj;
982+
export interface UrlsConfigObj {
976983
schemeMatches?: boolean;
977984
wwwMatches?: boolean;
978985
tldMatches?: boolean;
979986
}
980987

981988
export type UrlMatchTypeOptions = 'scheme' | 'www' | 'tld';
982989

983-
export interface StripPrefixConfig {
984-
scheme : boolean;
985-
www : boolean;
990+
export type StripPrefixConfig = boolean | StripPrefixConfigObj;
991+
export interface StripPrefixConfigObj {
992+
scheme? : boolean;
993+
www? : boolean;
986994
}
987995

988-
export interface TruncateConfig {
996+
export type TruncateConfig = number | TruncateConfigObj;
997+
export interface TruncateConfigObj {
989998
length?: number;
990999
location?: "end" | "middle" | "smart";
9911000
}
9921001

1002+
export type HashtagConfig = false | HashtagServices;
9931003
export type HashtagServices = 'twitter' | 'facebook' | 'instagram';
1004+
1005+
export type MentionConfig = false | MentionServices;
9941006
export type MentionServices = 'twitter' | 'instagram' | 'soundcloud';
9951007

1008+
export type ReplaceFn = ( match: Match ) => ReplaceFnReturn;
9961009
export type ReplaceFnReturn = boolean | string | HtmlTag | null | undefined | void;

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
export { default } from './autolinker';
77
export { default as Autolinker } from './autolinker';
88

9+
export * from './autolinker';
910
export * from './anchor-tag-builder';
1011
export * from './html-tag';
1112
export * from './match/index';

src/match/url-match.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Match, MatchConfig } from "./match";
2-
import { StripPrefixConfig, UrlMatchTypeOptions } from "../autolinker";
2+
import { StripPrefixConfigObj, UrlMatchTypeOptions } from "../autolinker";
33

44
/**
55
* @class Autolinker.match.Url
@@ -50,7 +50,7 @@ export class UrlMatch extends Match {
5050
*
5151
* The Object form of {@link Autolinker#cfg-stripPrefix}.
5252
*/
53-
private readonly stripPrefix: StripPrefixConfig = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
53+
private readonly stripPrefix: Required<StripPrefixConfigObj> = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
5454

5555
/**
5656
* @cfg {Boolean} stripTrailingSlash (required)
@@ -302,7 +302,7 @@ export interface UrlMatchConfig extends MatchConfig {
302302
urlMatchType: UrlMatchTypeOptions;
303303
protocolUrlMatch: boolean;
304304
protocolRelativeMatch: boolean;
305-
stripPrefix: StripPrefixConfig;
305+
stripPrefix: Required<StripPrefixConfigObj>;
306306
stripTrailingSlash: boolean;
307307
decodePercentEncoding: boolean;
308308
}

src/matcher/url-matcher.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Matcher, MatcherConfig } from "./matcher";
22
import { alphaNumericCharsStr, alphaNumericAndMarksCharsStr, getDomainNameStr } from "../regex-lib";
3-
import { StripPrefixConfig, UrlMatchTypeOptions } from "../autolinker";
3+
import { StripPrefixConfigObj, UrlMatchTypeOptions } from "../autolinker";
44
import { tldRegex } from "./tld-regex";
55
import { UrlMatch } from "../match/url-match";
66
import { UrlMatchValidator } from "./url-match-validator";
@@ -21,7 +21,7 @@ export class UrlMatcher extends Matcher {
2121
*
2222
* The Object form of {@link Autolinker#cfg-stripPrefix}.
2323
*/
24-
protected stripPrefix: StripPrefixConfig = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
24+
protected stripPrefix: Required<StripPrefixConfigObj> = { scheme: true, www: true }; // default value just to get the above doc comment in the ES5 output and documentation generator
2525

2626
/**
2727
* @cfg {Boolean} stripTrailingSlash (required)
@@ -331,7 +331,7 @@ export class UrlMatcher extends Matcher {
331331
}
332332

333333
export interface UrlMatcherConfig extends MatcherConfig {
334-
stripPrefix: StripPrefixConfig;
334+
stripPrefix: Required<StripPrefixConfigObj>;
335335
stripTrailingSlash: boolean;
336336
decodePercentEncoding: boolean;
337337
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Autolinker, { AutolinkerConfig } from 'autolinker';
2+
3+
describe( 'test Autolinker with TypeScript in Node', () => {
4+
5+
it( 'should run using the AutolinkerConfig interface import', () => {
6+
var options: AutolinkerConfig = { newWindow: false }; // Note: Testing that the AutolinkerConfig interface can be imported
7+
var linkedStr = Autolinker.link( 'Go to google.com', options );
8+
9+
expect( linkedStr ).toBe( `Go to <a href="http://google.com">google.com</a>` );
10+
} );
11+
12+
} );
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import Autolinker from 'autolinker';
1+
import Autolinker, { AutolinkerConfig } from 'autolinker';
22

33
document.addEventListener( 'DOMContentLoaded', () => {
44
var resultEl = document.getElementById( 'result' )!;
55

6-
var linkedStr = Autolinker.link( 'Go to google.com', { newWindow: false } );
6+
var options: AutolinkerConfig = { newWindow: false }; // Note: Testing that the AutolinkerConfig interface can be imported
7+
var linkedStr = Autolinker.link( 'Go to google.com', options );
78
resultEl.innerHTML = linkedStr;
89
} );

0 commit comments

Comments
 (0)