feat(pre-suf): new type definition (#43866)

- declaration file
- tests

https://github.com/kaelzhang/node-pre-suf

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-04-14 00:27:17 +02:00 committed by GitHub
parent 275fd285c4
commit a0a52a6a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 0 deletions

27
types/pre-suf/index.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for pre-suf 1.1
// Project: https://github.com/kaelzhang/node-pre-suf#readme
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Manipulate strings with prefixes and suffixes.
*/
/**
* Ensures that the new string will have prefix at the beginning of str.
* If str does not begin with prefix, prefix will be added to the beggining of str.
*/
export function ensureLeading(str: string, prefix: string): string;
/**
* Removes the leading prefix of str.
*/
export function removeLeading(str: string, prefix: string): string;
/**
* Ensures that the new string will have suffix at the end of str.
* If str does not end with suffix, suffix will be added at the end of str.
*/
export function ensureEnding(str: string, suffix: string): string;
/**
* Removes the ending suffix of str.
*/
export function removeEnding(str: string, suffix: string): string;

View File

@ -0,0 +1,14 @@
import presuf = require('pre-suf');
presuf.ensureLeading('a', '/'); // $ExpectType string
presuf.removeLeading('a', '/'); // $ExpectType string
presuf.ensureEnding('a', '/'); // $ExpectType string
presuf.removeEnding('/a/ab/a', '/a'); // $ExpectType string
// $ExpectError
presuf.ensureLeading();
// $ExpectError
presuf.removeLeading();
// $ExpectError
presuf.ensureEnding();
// $ExpectError
presuf.removeEnding();

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",
"pre-suf-tests.ts"
]
}

View File

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