Merge pull request #17660 from jurajkocan/master

Adding new type for osmosis module
This commit is contained in:
Ryan Cavanaugh
2017-07-13 09:59:23 -07:00
committed by GitHub
4 changed files with 127 additions and 0 deletions

60
types/osmosis/index.d.ts vendored Normal file
View File

@@ -0,0 +1,60 @@
// Type definitions for osmosis 1.0
// Project: https://github.com/rchipka/node-osmosis
// Definitions by: Juraj Kočan <https://github.com/jurajkocan>
// 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;

View File

@@ -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);

View File

@@ -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"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}