mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-12 19:59:02 +08:00
Merge pull request #17660 from jurajkocan/master
Adding new type for osmosis module
This commit is contained in:
60
types/osmosis/index.d.ts
vendored
Normal file
60
types/osmosis/index.d.ts
vendored
Normal 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;
|
||||
42
types/osmosis/osmosis-tests.ts
Normal file
42
types/osmosis/osmosis-tests.ts
Normal 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);
|
||||
22
types/osmosis/tsconfig.json
Normal file
22
types/osmosis/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/osmosis/tslint.json
Normal file
3
types/osmosis/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user