🤖 Merge PR #46019 feat(is-secret): new type definition by @peterblazejewicz

This is a redo of staled #45475
The original PR author is listed here as the owner.
This commit redos details of original PR as per comments
- use default exports as per DT template and Don't/Do's
- use default `tslint.json` without non essential overrides

/cc @wrumsby

https://github.com/watson/is-secret#readme

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz) 2020-07-12 21:37:22 +02:00 committed by GitHub
parent b5490c2e82
commit 56c9ebef90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 0 deletions

23
types/is-secret/index.d.ts vendored Normal file
View File

@ -0,0 +1,23 @@
// Type definitions for is-secret 1.2
// Project: https://github.com/watson/is-secret#readme
// Definitions by: Walter Rumsby <https://github.com/wrumsby>
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* A distributed maintained collection of patterns that indicate that something probably is secret.
* This is useful if you want to filter sensitive values in a data set.
* This module uses a very simple algorithm that will not catch everything. Use at your own risk.
*/
/**
* Validates the given string against a list of key names known to typically indicate secret data.
* Returns `true` if the string is considered secret. Otherwise `false`.
*/
export function key(str: string): boolean;
/**
* Validates the given string against a list of patterns that indicates secret data.
* Returns `true` if the string is considered secret. Otherwise `false`.
*/
export function value(str: string): boolean;

View File

@ -0,0 +1,20 @@
import isSecret = require('is-secret');
interface Data {
username: string;
password: string;
card: string;
}
const data: Data = {
username: 'watson',
password: 'f8bY2fg8',
card: '1234 1234 1234 1234', // credit card number
};
if (isSecret.key('password') || isSecret.value(data.password)) {
data.password = '********';
}
isSecret.key('secret-key'); // $ExpectType boolean
isSecret.value('secret-value'); // $ExpectType boolean

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",
"is-secret-tests.ts"
]
}

View File

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