diff --git a/types/osmosis/index.d.ts b/types/osmosis/index.d.ts new file mode 100644 index 0000000000..cb4d197f58 --- /dev/null +++ b/types/osmosis/index.d.ts @@ -0,0 +1,60 @@ +// Type definitions for osmosis 1.0 +// Project: https://github.com/rchipka/node-osmosis +// Definitions by: Juraj Kočan +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface Osmosis { + /** + * define domain where osmosis is parsing data from + */ + 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 | {}): Osmosis; + + /** + * find DOM by selector + */ + find(selector: string): Osmosis; + + /** + * follw links, founded href or src + * @param selector '@href' or '@src', default '@href' + */ + follow(selector: string): Osmosis; + + /** + * paginate followed url + */ + paginate(selector: string): Osmosis; + + /** + * passing string to your function + * log data + */ + log(callback: (param: string) => any): Osmosis; + + /** + * passing string to your function + * debug data + */ + debug(callback: (param: string) => any): Osmosis; + + /** + * passing string to your function + * error data + */ + error(callback: (param: string) => any): Osmosis; + + /** + * passing string to your function + * result data, osmosis finished + */ + data(callback: (param: string) => any): Osmosis; +} + +export const osmosis: Osmosis; 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..f93cf8562a --- /dev/null +++ b/types/osmosis/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}