[negative-index] Add types (#63239)

This commit is contained in:
Dimitri B
2022-11-14 17:54:26 +01:00
committed by GitHub
parent 9b7014fd54
commit b4a0d04424
4 changed files with 55 additions and 0 deletions

28
types/negative-index/index.d.ts vendored Normal file
View File

@@ -0,0 +1,28 @@
// Type definitions for negative-index 1.0
// Project: https://github.com/dy/negative-index#readme
// Definitions by: BendingBender <https://github.com/BendingBender>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export = negativeIndex;
/**
* Convert negative index to positive starting from the end. Same way
* [Array.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)
* arguments work.
*
* @example
* import idx = require('negative-index');
*
* idx(-5, 8); // 3
* idx(5, 8); // 5
*
* @example
* // Works well for normalizing real numbers offset, like time etc:
*
* import normOffset = require('negative-index');
*
* const time = -.15, duration = 2.45;
*
* normOffset(time, duration); // 2.3
*/
declare function negativeIndex(index: number, length: number): number;

View File

@@ -0,0 +1,3 @@
import idx = require('negative-index');
idx(5, 8); // $ExpectType number

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",
"negative-index-tests.ts"
]
}

View File

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