unist-util-is now has native typings (#38577)

This commit is contained in:
Christian Murphy
2019-09-25 14:09:16 -07:00
committed by Michael Crane
parent 129abd98db
commit f8aff22606
5 changed files with 6 additions and 86 deletions
+6
View File
@@ -3738,6 +3738,12 @@
"sourceRepoURL": "https://github.com/sindresorhus/unique-string",
"asOfVersion": "2.0.0"
},
{
"libraryName": "unist-util-is",
"typingsPackageName": "unist-util-is",
"sourceRepoURL": "https://github.com/syntax-tree/unist-util-is",
"asOfVersion": "4.0.0"
},
{
"libraryName": "Universal Router",
"typingsPackageName": "universal-router",
-36
View File
@@ -1,36 +0,0 @@
// Type definitions for unist-util-is 2.1
// Project: https://github.com/syntax-tree/unist-util-is#readme
// Definitions by: Junyoung Choi <https://github.com/rokt33r>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.0
/// <reference types='node' />
import * as Unist from 'unist';
declare namespace unistUtilIs {
/**
* @param node Node to test
* @param index Position of node in parent
* @param parent Parent of node
*/
type TestFunction = (node: unknown, index?: number, parent?: Unist.Parent) => boolean | void;
type Test = TestFunction | Partial<Unist.Node> | string | null;
}
/**
* Unist utility to check if a node passes a test.
*
* @param test When not given, checks if `node` is a `Node`.
* When `string`, works like passing `function (node) {return node.type === test}`.
* When `array`, checks any one of the subtests pass.
* When `object`, checks that all keys in test are in node, and that they have (strictly) equal values
* @param node Node to check. `false` is returned
* @param index Position of `node` in `parent`
* @param parent Parent of `node`
* @param context Context object to invoke `test` with
* @returns Whether test passed and `node` is a `Node` (object with `type` set to non-empty `string`).
*/
declare function unistUtilIs(test: unistUtilIs.Test | unistUtilIs.Test[], node: unknown, index?: number, parent?: Unist.Parent, context?: any): boolean;
export = unistUtilIs;
-23
View File
@@ -1,23 +0,0 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"unist-util-is-tests.ts"
]
}
-1
View File
@@ -1 +0,0 @@
{ "extends": "dtslint/dt.json" }
@@ -1,26 +0,0 @@
import is = require('unist-util-is');
const node = {type: 'strong'};
const parent = {type: 'paragraph', children: [node]};
function test(node: unknown, n?: number) {
return n === 5;
}
is(null, {children: []});
is(null, node);
is('strong', node);
is('emphasis', node);
is(node, node);
is({type: 'paragraph'}, parent);
is({type: 'strong'}, parent);
is(test, node);
is(test, node, 4, parent);
is(test, node, 5, parent);
function testFunc(node: unknown) {}
is(testFunc, node);
const wrongTestFunc: is.TestFunction = (node: unknown, n: string) => {}; // $ExpectError