Skip to content

chore: typescript #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
"stream-to-it": "^0.2.0"
},
"devDependencies": {
"@types/chai": "^4.2.11",
"@types/chai-as-promised": "^7.1.2",
"@types/dirty-chai": "^2.0.2",
"@types/fs-extra": "^8.1.0",
"@types/it-all": "^1.0.0",
"@types/node": "^13.9.3",
"@types/node-fetch": "^2.5.5",
"aegir": "^21.4.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
Expand Down
12 changes: 12 additions & 0 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare const IS_TEST: boolean;
declare const IS_ELECTRON: any;
declare const IS_ELECTRON_MAIN: boolean;
declare const IS_ELECTRON_RENDERER: boolean;
declare const IS_NODE: boolean;
/**
* Detects browser main thread **NOT** web worker or service worker
*/
declare const IS_BROWSER: boolean;
declare const IS_WEBWORKER: boolean;
declare const IS_ENV_WITH_DOM: boolean;
export { IS_TEST as isTest, IS_ELECTRON as isElectron, IS_ELECTRON_MAIN as isElectronMain, IS_ELECTRON_RENDERER as isElectronRenderer, IS_NODE as isNode, IS_BROWSER as isBrowser, IS_WEBWORKER as isWebWorker, IS_ENV_WITH_DOM as isEnvWithDom };
2 changes: 2 additions & 0 deletions src/files/format-mode.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export = formatMode;
declare function formatMode(mode: number, isDirectory: boolean): string;
13 changes: 13 additions & 0 deletions src/files/format-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const S_IROTH = parseInt('4', 8) // others have read permission
const S_IWOTH = parseInt('2', 8) // others have write permission
const S_IXOTH = parseInt('1', 8) // others have execute permission

/**
*
* @param {number} mode
* @param {number} perm
* @param {string} type
* @param {string[]} output
*/
function checkPermission (mode, perm, type, output) {
if ((mode & perm) === perm) {
output.push(type)
Expand All @@ -24,6 +31,12 @@ function checkPermission (mode, perm, type, output) {
}
}

/**
*
* @param {number} mode
* @param {boolean} isDirectory
* @returns {string}
*/
function formatMode (mode, isDirectory) {
const output = []

Expand Down
2 changes: 2 additions & 0 deletions src/files/format-mtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export = formatMtime;
declare function formatMtime(mtime: { secs: number, nsecs: number }): string;
24 changes: 24 additions & 0 deletions src/files/glob-source.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference types="node" />
import { ReadStream } from "fs";
/**
* Create an async iterator that yields paths that match requested file paths.
*
* @param {Iterable|AsyncIterable|String} paths File system path(s) to glob from
* @param {Object} [options] Optional options
* @param {Boolean} [options.recursive] Recursively glob all paths in directories
* @param {Boolean} [options.hidden] Include .dot files in matched paths
* @param {Array<String>} [options.ignore] Glob paths to ignore
* @param {Boolean} [options.followSymlinks] follow symlinks
* @param {Boolean} [options.preserveMode] preserve mode
* @param {Boolean} [options.preserveMtime] preserve mtime
* @param {Boolean} [options.mode] mode to use - if preserveMode is true this will be ignored
* @param {Boolean} [options.mtime] mtime to use - if preserveMtime is true this will be ignored
* @yields {{ path: String, content: AsyncIterator<Buffer> }} File objects in the form `{ path: String, content: AsyncIterator<Buffer> }`
*/
declare function globSource(paths: Iterable<string> | AsyncIterable<string> | string, options: any): AsyncGenerator<{
path: string;
content?: ReadStream;
mode: number;
mtime: number;
}>;
export = globSource;
6 changes: 6 additions & 0 deletions src/files/normalise-input.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare function _exports(input: any): AsyncGenerator<{
path: string;
mode: number;
mtime: number;
}>;
export = _exports;
5 changes: 5 additions & 0 deletions src/files/url-source.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare function _exports(url: any, options: any): AsyncGenerator<{
path: string;
content: AsyncGenerator<Uint8Array>;
}>;
export = _exports;
2 changes: 2 additions & 0 deletions src/globalthis.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare const _exports: typeof globalThis;
export = _exports;
141 changes: 141 additions & 0 deletions src/http.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
export = HTTP;
/**
* @typedef {Object} APIOptions - creates a new type named 'SpecialType'
* @prop {any} [body] - Request body
* @prop {string} [method] - GET, POST, PUT, DELETE, etc.
* @prop {string} [base] - The base URL to use in case url is a relative URL
* @prop {Headers|Record<string, string>} [headers] - Request header.
* @prop {number} [timeout] - Amount of time until request should timeout in ms.
* @prop {AbortSignal} [signal] - Signal to abort the request.
* @prop {URLSearchParams|Object} [searchParams] - URL search param.
* @prop {string} [credentials]
* @prop {boolean} [throwHttpErrors]
* @prop {function(URLSearchParams): URLSearchParams } [transformSearchParams]
* @prop {function(any): any} [transform] - When iterating the response body, transform each chunk with this function.
* @prop {function(Response): Promise<void>} [handleError] - Handle errors
*/
declare class HTTP {
/**
*
* @param {APIOptions} options
*/
constructor(options?: APIOptions);
/** @type {APIOptions} */
opts: APIOptions;
abortController: any;
/**
* Fetch
*
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
fetch(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
post(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
get(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
put(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
delete(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<Response>}
*/
options(resource: string | Request | URL, options?: APIOptions): Promise<Response>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {Promise<ReadableStream<Uint8Array>>}
*/
stream(resource: string | Request | URL, options?: APIOptions): Promise<ReadableStream<Uint8Array>>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {AsyncGenerator<Uint8Array, void, any>}
*/
iterator(resource: string | Request | URL, options?: APIOptions): AsyncGenerator<Uint8Array, void, any>;
/**
* @param {string | URL | Request} resource
* @param {APIOptions} options
* @returns {AsyncGenerator<Object, void, any>}
*/
ndjson(resource: string | Request | URL, options?: APIOptions): AsyncGenerator<any, void, any>;
}
declare namespace HTTP {
export { HTTPError, TimeoutError, ndjson, streamToAsyncIterator, post, get, put, _delete as delete, options, APIOptions };
}
/**
* - creates a new type named 'SpecialType'
*/
type APIOptions = {
/**
* - Request body
*/
body?: any;
/**
* - GET, POST, PUT, DELETE, etc.
*/
method?: string;
/**
* - The base URL to use in case url is a relative URL
*/
base?: string;
/**
* - Request header.
*/
headers?: Record<string, string> | Headers;
/**
* - Amount of time until request should timeout in ms.
*/
timeout?: number;
/**
* - Signal to abort the request.
*/
signal?: AbortSignal;
/**
* - URL search param.
*/
searchParams?: any;
credentials?: string;
throwHttpErrors?: boolean;
transformSearchParams?: (arg0: URLSearchParams) => URLSearchParams;
/**
* - When iterating the response body, transform each chunk with this function.
*/
transform?: (arg0: any) => any;
/**
* - Handle errors
*/
handleError?: (arg0: Response) => Promise<void>;
};
declare class HTTPError extends Error {
constructor(response: any);
response: any;
}
declare class TimeoutError extends Error {
}
declare function ndjson(source: AsyncGenerator<Uint8Array, void, any>): AsyncGenerator<any, void, any>;
declare function streamToAsyncIterator(source: any): any;
declare function post(resource: string | Request | URL, options: APIOptions): Promise<Response>;
declare function get(resource: string | Request | URL, options: APIOptions): Promise<Response>;
declare function put(resource: string | Request | URL, options: APIOptions): Promise<Response>;
declare function options(resource: string | Request | URL, options: APIOptions): Promise<Response>;
1 change: 1 addition & 0 deletions src/supports.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const supportsFileReader: boolean;
4 changes: 4 additions & 0 deletions src/text-encoder.browser.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TextDecoder } from 'util'

declare const _exports: typeof TextDecoder;
export = _exports;
4 changes: 4 additions & 0 deletions src/text-encoder.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TextDecoder } from 'util'

declare const _exports: typeof TextDecoder;
export = _exports;
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "ESNext",
"declaration": true,
"emitDeclarationOnly": true,
"allowJs": true
}
}