From 4abecf320041051aac04a31e58a0eeae8092f224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Tue, 23 Jun 2020 17:09:28 +0200 Subject: [PATCH] feat(github-slugger): new type definition (#45647) - definition file - tests https://www.npmjs.com/package/github-slugger https://github.com/Flet/github-slugger#readme Thanks! --- types/github-slugger/github-slugger-tests.ts | 26 +++++++++++++++++ types/github-slugger/index.d.ts | 30 ++++++++++++++++++++ types/github-slugger/tsconfig.json | 23 +++++++++++++++ types/github-slugger/tslint.json | 1 + 4 files changed, 80 insertions(+) create mode 100644 types/github-slugger/github-slugger-tests.ts create mode 100644 types/github-slugger/index.d.ts create mode 100644 types/github-slugger/tsconfig.json create mode 100644 types/github-slugger/tslint.json diff --git a/types/github-slugger/github-slugger-tests.ts b/types/github-slugger/github-slugger-tests.ts new file mode 100644 index 0000000000..53ea9fcd77 --- /dev/null +++ b/types/github-slugger/github-slugger-tests.ts @@ -0,0 +1,26 @@ +import GithubSlugger = require('github-slugger'); + +const slugger = new GithubSlugger(); +const slug = GithubSlugger.slug; + +slugger.slug('foo'); // $ExpectType string +// returns 'foo' + +slugger.slug('foo'); // $ExpectType string +// returns 'foo-1' + +slugger.slug('bar'); // $ExpectType string +// returns 'bar' + +slugger.slug('foo'); // $ExpectType string +// returns 'foo-2' + +slugger.reset(); // $ExpectType void + +slugger.slug('foo'); // $ExpectType string +// returns 'foo' +slug('foo bar baz'); // $ExpectType string +// returns 'foo-bar-baz' + +slug('foo bar baz'); // $ExpectType string +// returns the same slug 'foo-bar-baz' because it does not keep track diff --git a/types/github-slugger/index.d.ts b/types/github-slugger/index.d.ts new file mode 100644 index 0000000000..3313c8a0e9 --- /dev/null +++ b/types/github-slugger/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for github-slugger 1.3 +// Project: https://github.com/Flet/github-slugger +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/** + * Generate a slug just like GitHub does for markdown headings. + * It also ensures slugs are unique in the same way GitHub does it. The overall goal of this package is to emulate the way GitHub handles generating markdown heading anchors as close as possible + */ +declare class BananaSlug { + /** + * + * @param value string of text to slugify + * @param [maintainCase=false] Keep the current case, otherwise make all lowercase + */ + static slug(value: string | unknown, maintainCase?: boolean): string; + + /** + * + * @param value string of text to slugify + * @param [maintainCase=false] Keep the current case, otherwise make all lowercase + */ + slug(value: string, maintainCase?: boolean): string; + /** + * Forget all previous slugs + */ + reset(): void; +} + +export = BananaSlug; diff --git a/types/github-slugger/tsconfig.json b/types/github-slugger/tsconfig.json new file mode 100644 index 0000000000..fd45612dbf --- /dev/null +++ b/types/github-slugger/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "github-slugger-tests.ts" + ] +} diff --git a/types/github-slugger/tslint.json b/types/github-slugger/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/github-slugger/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }