-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7114 from TerriaJS/ambient-types
Provide ambient types or TSify some js[x] files.
- Loading branch information
Showing
92 changed files
with
659 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
declare class ConsoleAnalytics { | ||
start: ( | ||
configParameters: Partial<{ | ||
enableConsoleAnalytics: boolean; | ||
googleAnalyticsKey: any; | ||
googleAnalyticsOptions: any; | ||
}> | ||
) => void; | ||
logEvent: ( | ||
category: string, | ||
action: string, | ||
label?: string, | ||
value?: number | ||
) => void; | ||
} | ||
|
||
export default ConsoleAnalytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,14 @@ | ||
"use strict"; | ||
|
||
var DataUri = { | ||
export default { | ||
/** | ||
* Turn a file with the supplied type and stringified data into a data uri that can be set as the href of an anchor tag. | ||
* @param {String} type Data type, eg. 'json' or 'csv'. | ||
* @param {String} dataString The data. | ||
* @return {String} A string that can be used to in an anchor tag's 'href' attribute to represent downloadable data. | ||
*/ | ||
make: function (type, dataString) { | ||
make: function (type: string, dataString: string): string | undefined { | ||
if (dataString) { | ||
// Using attachment/* mime type makes safari download as attachment. text/* works on Chrome (as does attachment). | ||
return "data:attachment/" + type + "," + encodeURIComponent(dataString); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = DataUri; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
declare class ServerConfig { | ||
config: unknown; | ||
init(serverConfigUrl: string): Promise<unknown>; | ||
} | ||
|
||
export default ServerConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import defined from "terriajs-cesium/Source/Core/defined"; | ||
|
||
/** | ||
* Determins is a given string contains any of a number of possible strings. | ||
* | ||
* @param s The string to test. | ||
* @param possibleStrings The possible strings to test `s` for. | ||
* @return true if `s` contains any of the strings in `possibleStrings`; otherwise, false. | ||
*/ | ||
const containsAny = function (s: string, possibleStrings: string[]) { | ||
if (!defined(s)) { | ||
return false; | ||
} | ||
|
||
for (let i = 0; i < possibleStrings.length; ++i) { | ||
if (s.indexOf(possibleStrings[i]) >= 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
}; | ||
|
||
export default containsAny; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Resource from "terriajs-cesium/Source/Core/Resource"; | ||
|
||
async function loadText(urlOrResource: string | Resource): Promise<string> { | ||
const resource = (Resource as any).createIfNeeded(urlOrResource) as Resource; | ||
const response = resource.fetchText(); | ||
if (response === undefined) { | ||
throw new Error("Request throttled"); | ||
} | ||
return response; | ||
} | ||
|
||
export default loadText; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Resource from "terriajs-cesium/Source/Core/Resource"; | ||
|
||
interface Options extends Resource.ConstructorOptions { | ||
responseType?: string; | ||
headers?: any; | ||
overrideMimeType?: string; | ||
method?: "GET" | "POST" | "PUT"; | ||
data?: any; | ||
} | ||
|
||
declare function loadWithXhr(options: Options): Promise<any>; | ||
|
||
export default loadWithXhr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,4 @@ Object.defineProperties(loadWithXhr, { | |
} | ||
}); | ||
|
||
module.exports = loadWithXhr; | ||
export default loadWithXhr; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import defaultValue from "terriajs-cesium/Source/Core/defaultValue"; | ||
import getTimestamp from "terriajs-cesium/Source/Core/getTimestamp"; | ||
|
||
interface Options { | ||
pollInterval?: number; | ||
timeout?: number; | ||
} | ||
|
||
const pollToPromise = function (f: () => boolean, options: Options) { | ||
options = defaultValue(options, (defaultValue as any).EMPTY_OBJECT); | ||
|
||
const pollInterval = defaultValue(options.pollInterval, 1); | ||
const timeout = defaultValue(options.timeout, 5000); | ||
|
||
return new Promise<void>((resolve, reject) => { | ||
const startTimestamp = getTimestamp(); | ||
const endTimestamp = startTimestamp + timeout; | ||
|
||
function poller() { | ||
if (f()) { | ||
resolve(); | ||
} else { | ||
if (getTimestamp() > endTimestamp) { | ||
reject(); | ||
} else { | ||
setTimeout(poller, pollInterval); | ||
} | ||
} | ||
} | ||
|
||
poller(); | ||
}); | ||
}; | ||
|
||
export default pollToPromise; |
Oops, something went wrong.