mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Merge pull request #17674 from surenkov/master
Add jsonp npm package typings
This commit is contained in:
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
// Type definitions for jsonp 0.2
|
||||
// Project: https://github.com/LearnBoost/jsonp
|
||||
// Definitions by: Savva Surenkov <https://github.com/surenkov>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = jsonp;
|
||||
|
||||
declare function jsonp(url: string, options?: Options, cb?: RequestCallback): CancelFn;
|
||||
declare function jsonp(url: string, callback?: RequestCallback): CancelFn;
|
||||
|
||||
type CancelFn = () => void;
|
||||
type RequestCallback = (error: Error | null, data: any) => void;
|
||||
|
||||
interface Options {
|
||||
param?: string;
|
||||
prefix?: string;
|
||||
name?: string;
|
||||
timeout?: number;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import jsonp = require('jsonp');
|
||||
|
||||
/**
|
||||
* Dummy response callback.
|
||||
*/
|
||||
const print = (err: Error | null, data: any) =>
|
||||
console.log(err !== null ? err.message : data);
|
||||
|
||||
/**
|
||||
* Tests jsonp request with default parameters.
|
||||
*/
|
||||
const cancel1 = jsonp('https://jsonplaceholder.typicode.com/posts/1', print);
|
||||
cancel1();
|
||||
|
||||
/**
|
||||
* Tests parametrized jsonp request.
|
||||
*/
|
||||
const cancel2 = jsonp(
|
||||
'https://jsonplaceholder.typicode.com/posts/1',
|
||||
{
|
||||
param: 'cb',
|
||||
timeout: 40000,
|
||||
prefix: '_jsonp',
|
||||
name: 'func',
|
||||
},
|
||||
print,
|
||||
);
|
||||
cancel2();
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"jsonp-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"ban-types": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user