From 6fe4d80f181b3c20578bb321c39978f23d40a5be Mon Sep 17 00:00:00 2001 From: juraj kocan Date: Fri, 30 Jun 2017 17:38:56 +0200 Subject: [PATCH 1/5] types for osmosis node module --- types/osmosis/index.d.ts | 62 ++++++++++++++++++++++++++++++++++ types/osmosis/osmosis-tests.ts | 42 +++++++++++++++++++++++ types/osmosis/tsconfig.json | 22 ++++++++++++ types/osmosis/tslint.json | 1 + 4 files changed, 127 insertions(+) create mode 100644 types/osmosis/index.d.ts create mode 100644 types/osmosis/osmosis-tests.ts create mode 100644 types/osmosis/tsconfig.json create mode 100644 types/osmosis/tslint.json diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts new file mode 100644 index 0000000000..3d5a80a5e2 --- /dev/null +++ b/types/osmosis/index.d.ts @@ -0,0 +1,62 @@ +// Type definitions for osmosis 1.1 +// Project: https://github.com/rchipka/node-osmosis#readme +// Definitions by: Juraj +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export declare interface IOsmosis { + /** + * define domain where osmosis is parsing data from + */ + get: (url: string) => IOsmosis, + + /** + * set scrapped data as result, + * 1. string, after find function set data by selector as value with this string as key + * 2. object, define any json object + */ + set: (json: string | Object) => IOsmosis, + + /** + * find DOM by selector + */ + find: (selector: string) => IOsmosis, + + /** + * follw links, founded href or src + * @param selector '@href' or '@src' + * @default '@href' + */ + follow: (selector: string) => IOsmosis, + + /** + * paginate followed page + */ + paginate: (selector: string) => IOsmosis + + /** + * passing string to your function + * log data + */ + log: (callback: (param: string) => any) => IOsmosis, + + /** + * passing string to your function + * debug data + */ + debug: (callback: (param: string) => any) => IOsmosis, + + /** + * passing string to your function + * error data + */ + error: (callback: (param: string) => any) => IOsmosis, + + /** + * passing string to your function + * result data, osmosis finished + */ + data: (callback: (param: string) => any) => IOsmosis +} + +export declare const osmosis: IOsmosis + diff --git a/types/osmosis/osmosis-tests.ts b/types/osmosis/osmosis-tests.ts new file mode 100644 index 0000000000..0882bb14f7 --- /dev/null +++ b/types/osmosis/osmosis-tests.ts @@ -0,0 +1,42 @@ +import { osmosis } from 'osmosis'; + +const logFunction = (log: string) => { + const myLog = log; +}; + +const debugFunction = (debug: string) => { + const myDebug = debug; +}; + +const errorFunction = (error: string) => { + const myError = error; +}; + +// example is from https://github.com/rchipka/node-osmosis#example + +osmosis + .get('www.craigslist.org/about/sites') + .find('h1 + div a') + .set('location') + .follow('@href') + .find('header + div + div li > a') + .set('category') + .follow('@href') + .paginate('.totallink + a.button.next:first') + .find('p > a') + .follow('@href') + .set({ + title: 'section > h2', + description: '#postingbody', + subcategory: 'div.breadbox > span[4]', + date: 'time@datetime', + latitude: '#map@data-latitude', + longitude: '#map@data-longitude', + images: ['img@src'] + }) + .data((listing: any) => { + // do something with listing data + }) + .log(logFunction) + .error(errorFunction) + .debug(debugFunction); diff --git a/types/osmosis/tsconfig.json b/types/osmosis/tsconfig.json new file mode 100644 index 0000000000..c6c1cd0b81 --- /dev/null +++ b/types/osmosis/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "osmosis-tests.ts" + ] +} diff --git a/types/osmosis/tslint.json b/types/osmosis/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/osmosis/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From efaaa3c6af0aec10a7ad8d4639ceb967f754f24b Mon Sep 17 00:00:00 2001 From: juraj kocan Date: Fri, 30 Jun 2017 18:20:11 +0200 Subject: [PATCH 2/5] repair linter errors --- types/osmosis/index.d.ts | 33 +++++++++++++-------------------- types/osmosis/tslint.json | 4 +++- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts index 3d5a80a5e2..ee5f2700ea 100644 --- a/types/osmosis/index.d.ts +++ b/types/osmosis/index.d.ts @@ -1,62 +1,55 @@ -// Type definitions for osmosis 1.1 -// Project: https://github.com/rchipka/node-osmosis#readme -// Definitions by: Juraj -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -export declare interface IOsmosis { +export interface Osmosis { /** * define domain where osmosis is parsing data from */ - get: (url: string) => IOsmosis, + get(url: string): Osmosis; /** * set scrapped data as result, * 1. string, after find function set data by selector as value with this string as key * 2. object, define any json object */ - set: (json: string | Object) => IOsmosis, + set(json: string | {}): Osmosis; /** * find DOM by selector */ - find: (selector: string) => IOsmosis, + find(selector: string): Osmosis; /** * follw links, founded href or src - * @param selector '@href' or '@src' - * @default '@href' + * @param selector '@href' or '@src', default '@href' */ - follow: (selector: string) => IOsmosis, + follow(selector: string): Osmosis; /** - * paginate followed page + * paginate followed url */ - paginate: (selector: string) => IOsmosis + paginate(selector: string): Osmosis; /** * passing string to your function * log data */ - log: (callback: (param: string) => any) => IOsmosis, + log(callback: (param: string) => any): Osmosis; /** * passing string to your function * debug data */ - debug: (callback: (param: string) => any) => IOsmosis, + debug(callback: (param: string) => any): Osmosis; /** * passing string to your function * error data */ - error: (callback: (param: string) => any) => IOsmosis, + error(callback: (param: string) => any): Osmosis; /** * passing string to your function * result data, osmosis finished */ - data: (callback: (param: string) => any) => IOsmosis + data(callback: (param: string) => any): Osmosis; } -export declare const osmosis: IOsmosis - +export const osmosis: Osmosis; diff --git a/types/osmosis/tslint.json b/types/osmosis/tslint.json index 3db14f85ea..4c3a548997 100644 --- a/types/osmosis/tslint.json +++ b/types/osmosis/tslint.json @@ -1 +1,3 @@ -{ "extends": "dtslint/dt.json" } +{ + "extends": "dtslint/dtslint.json" +} From 061a5f686ca3b29025fbfeb20c830e469ffe797e Mon Sep 17 00:00:00 2001 From: juraj kocan Date: Fri, 30 Jun 2017 18:38:21 +0200 Subject: [PATCH 3/5] add basic comment --- types/osmosis/index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts index ee5f2700ea..e76db57828 100644 --- a/types/osmosis/index.d.ts +++ b/types/osmosis/index.d.ts @@ -1,3 +1,8 @@ +// Type definitions for osmosis 1.1.4 +// Project: https://github.com/rchipka/node-osmosis +// Definitions by: Mohamed Hegazy +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + export interface Osmosis { /** * define domain where osmosis is parsing data from From c8cbb580d0fa95905ad2d3d8c5e93c14a966d995 Mon Sep 17 00:00:00 2001 From: juraj kocan Date: Fri, 30 Jun 2017 19:17:11 +0200 Subject: [PATCH 4/5] test osmosis fix --- types/osmosis/index.d.ts | 2 +- types/osmosis/tslint.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts index e76db57828..bce44f8ad3 100644 --- a/types/osmosis/index.d.ts +++ b/types/osmosis/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for osmosis 1.1.4 +// Type definitions for osmosis 1.0 // Project: https://github.com/rchipka/node-osmosis // Definitions by: Mohamed Hegazy // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/osmosis/tslint.json b/types/osmosis/tslint.json index 4c3a548997..f93cf8562a 100644 --- a/types/osmosis/tslint.json +++ b/types/osmosis/tslint.json @@ -1,3 +1,3 @@ { - "extends": "dtslint/dtslint.json" + "extends": "dtslint/dt.json" } From 778c92ccd550a0c26c819ab9be0c4f1a2b256a45 Mon Sep 17 00:00:00 2001 From: juraj kocan Date: Thu, 13 Jul 2017 14:59:05 +0200 Subject: [PATCH 5/5] Fix bad author name --- types/osmosis/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts index bce44f8ad3..cb4d197f58 100644 --- a/types/osmosis/index.d.ts +++ b/types/osmosis/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for osmosis 1.0 // Project: https://github.com/rchipka/node-osmosis -// Definitions by: Mohamed Hegazy +// Definitions by: Juraj Kočan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped export interface Osmosis {