mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
[negative-index] Add types (#63239)
This commit is contained in:
28
types/negative-index/index.d.ts
vendored
Normal file
28
types/negative-index/index.d.ts
vendored
Normal 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;
|
||||
3
types/negative-index/negative-index-tests.ts
Normal file
3
types/negative-index/negative-index-tests.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import idx = require('negative-index');
|
||||
|
||||
idx(5, 8); // $ExpectType number
|
||||
23
types/negative-index/tsconfig.json
Normal file
23
types/negative-index/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/negative-index/tslint.json
Normal file
1
types/negative-index/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "@definitelytyped/dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user