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!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-06-23 17:09:28 +02:00 committed by GitHub
parent 25348af784
commit 4abecf3200
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 0 deletions

View File

@ -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

30
types/github-slugger/index.d.ts vendored Normal file
View File

@ -0,0 +1,30 @@
// Type definitions for github-slugger 1.3
// Project: https://github.com/Flet/github-slugger
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// 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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }