mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1008,12 +1008,6 @@
|
||||
"sourceRepoURL": "https://github.com/blakeembrey/param-case",
|
||||
"asOfVersion": "1.1.2"
|
||||
},
|
||||
{
|
||||
"libraryName": "parse5",
|
||||
"typingsPackageName": "parse5",
|
||||
"sourceRepoURL": "https://github.com/inikulin/parse5",
|
||||
"asOfVersion": "3.0.0"
|
||||
},
|
||||
{
|
||||
"libraryName": "pascal-case",
|
||||
"typingsPackageName": "pascal-case",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"axios": "^0.16.2"
|
||||
"axios": "*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as JQuery from 'jquery';
|
||||
import * as Marionette from 'backbone.marionette';
|
||||
import * as Backbone from 'backbone';
|
||||
|
||||
@@ -9,6 +10,10 @@ class DestroyWarn extends Marionette.Behavior {
|
||||
message: 'you are destroying!'
|
||||
};
|
||||
|
||||
ui = {
|
||||
destroy: '.foo'
|
||||
};
|
||||
|
||||
// behaviors have events that are bound to the views DOM
|
||||
events = {
|
||||
'click @ui.destroy': 'warnBeforeDestroy'
|
||||
@@ -258,12 +263,18 @@ function RegionTests() {
|
||||
});
|
||||
}
|
||||
|
||||
function BehaviorTest() {
|
||||
const b = new DestroyWarn();
|
||||
const uiHandle: JQuery = b.getUI('destroy');
|
||||
}
|
||||
|
||||
function ViewTests() {
|
||||
const v = new MyView(new MyModel());
|
||||
const isDestroyed: boolean = v.isDestroyed();
|
||||
const isRendered: boolean = v.isRendered();
|
||||
const isAttached: boolean = v.isAttached();
|
||||
const vv: Marionette.View<Backbone.Model> = v.delegateEntityEvents();
|
||||
const uiHandle: JQuery = v.getUI('destroy');
|
||||
}
|
||||
|
||||
function CollectionViewTests() {
|
||||
|
||||
Vendored
+10
@@ -1143,6 +1143,11 @@ export class View<TModel extends Backbone.Model> extends Backbone.View<TModel> i
|
||||
* throughout the view with the ui attribute.
|
||||
*/
|
||||
ui: any;
|
||||
|
||||
/**
|
||||
* Get handle on UI element defined in ui hash
|
||||
*/
|
||||
getUI(ui: string): JQuery;
|
||||
}
|
||||
|
||||
export interface CollectionViewOptions<
|
||||
@@ -1561,6 +1566,11 @@ export class Behavior extends Object {
|
||||
*/
|
||||
ui: any;
|
||||
|
||||
/**
|
||||
* Get handle on UI element defined in ui hash
|
||||
*/
|
||||
getUI(ui: string): JQuery;
|
||||
|
||||
/**
|
||||
* Any triggers you define on the Behavior will be triggered in response to the appropriate event on the view.
|
||||
*/
|
||||
|
||||
+267
-1
@@ -1,4 +1,7 @@
|
||||
import * as Bleno from 'bleno';
|
||||
// can also import these types as if they were exported from the module
|
||||
// tslint:disable-next-line:no-duplicate-imports
|
||||
import { Characteristic, Descriptor, PrimaryService } from 'bleno';
|
||||
|
||||
export class EchoCharacteristic extends Bleno.Characteristic {
|
||||
_value: any;
|
||||
@@ -46,7 +49,7 @@ Bleno.on('stateChange', (state: string) => {
|
||||
});
|
||||
|
||||
const characteristic = new EchoCharacteristic();
|
||||
Bleno.on('advertisingStart', (error: string) => {
|
||||
Bleno.on('advertisingStart', (error?: Error | null) => {
|
||||
if (!error) {
|
||||
Bleno.setServices(
|
||||
[new Bleno.PrimaryService({uuid: 'ec00', characteristics: [ characteristic ] })],
|
||||
@@ -54,3 +57,266 @@ Bleno.on('advertisingStart', (error: string) => {
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
const SERVICE_UUID = '87B1E448-1C07-4957-B7D3-017DF4EE3863';
|
||||
const CONTROL_CHAR_UUID = '87B1E448-1C07-4957-B7D3-017DF4EE3864';
|
||||
const STATUS_CHAR_UUID = '87B1E448-1C07-4957-B7D3-017DF4EE3866';
|
||||
|
||||
class StatusCharacteristic extends Characteristic {
|
||||
constructor() {
|
||||
super({
|
||||
uuid: 'STATUS_CHAR_UUID',
|
||||
properties: ['read'],
|
||||
descriptors: [
|
||||
new Descriptor({
|
||||
uuid: '2901',
|
||||
value: Buffer.from('Status'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
onReadRequest(
|
||||
offset: number,
|
||||
callback: (result: number, data?: Buffer) => void
|
||||
) {
|
||||
try {
|
||||
const data = Buffer.from('status ok');
|
||||
callback(Characteristic.RESULT_SUCCESS, data.slice(offset));
|
||||
} catch (error) {
|
||||
callback(Characteristic.RESULT_UNLIKELY_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ControlCharacteristic extends Characteristic {
|
||||
private readonly callback: (data: Buffer) => void;
|
||||
|
||||
constructor(onWriteRequestCb: (data: Buffer) => void) {
|
||||
super({
|
||||
uuid: CONTROL_CHAR_UUID,
|
||||
properties: ['write'],
|
||||
descriptors: [
|
||||
new Descriptor({
|
||||
uuid: '2901',
|
||||
value: Buffer.from('test characteristic'),
|
||||
}),
|
||||
],
|
||||
});
|
||||
this.callback = onWriteRequestCb;
|
||||
}
|
||||
|
||||
onWriteRequest(
|
||||
data: Buffer,
|
||||
offset: number,
|
||||
withoutResponse: any,
|
||||
callback: (result: number) => void
|
||||
): void {
|
||||
if (offset > 0) {
|
||||
this.callback(data.slice(offset));
|
||||
} else {
|
||||
this.callback(data);
|
||||
}
|
||||
callback(this.RESULT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
export class BluetoothController {
|
||||
private isAdvertising: boolean;
|
||||
|
||||
constructor() {
|
||||
this.isAdvertising = false;
|
||||
this.setup();
|
||||
}
|
||||
|
||||
toString(): string {
|
||||
return '<Control>';
|
||||
}
|
||||
|
||||
dispose(callback: () => void) {
|
||||
if (this.isAdvertising) {
|
||||
Bleno.stopAdvertising(callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
private setup() {
|
||||
Bleno.on('stateChange', (state: string) => {
|
||||
console.log('bluetooth', `stateChange: ${state}, address = ${Bleno.address}`);
|
||||
|
||||
if (state === 'poweredOn') {
|
||||
Bleno.startAdvertising('device', [SERVICE_UUID]);
|
||||
} else {
|
||||
Bleno.stopAdvertising();
|
||||
}
|
||||
});
|
||||
|
||||
Bleno.on('accept', (clientAddress: string) => {
|
||||
console.log('bluetooth', `accept, client: ${clientAddress}`);
|
||||
Bleno.updateRssi();
|
||||
});
|
||||
|
||||
Bleno.on('disconnect', (clientAddress: string) => {
|
||||
console.log('bluetooth', `disconnect, client: ${clientAddress}`);
|
||||
});
|
||||
|
||||
Bleno.on('rssiUpdate', (rssi: number) => {
|
||||
console.log('bluetooth', `rssiUpdate: ${rssi}`);
|
||||
});
|
||||
|
||||
Bleno.on('mtuChange', (mtu: number) => {
|
||||
console.log('bluetooth', `mtuChange: ${mtu}`);
|
||||
});
|
||||
|
||||
Bleno.on('advertisingStart', (error?: Error | null) => {
|
||||
console.log('bluetooth', `advertisingStart: ${error ? error : 'success'}`);
|
||||
if (!error) {
|
||||
this.isAdvertising = true;
|
||||
Bleno.setServices([
|
||||
new PrimaryService({
|
||||
uuid: SERVICE_UUID,
|
||||
characteristics: [
|
||||
new ControlCharacteristic((data) => {
|
||||
this.onWriteRequest(data);
|
||||
}),
|
||||
new StatusCharacteristic(),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Bleno.on('advertisingStop', () => {
|
||||
this.isAdvertising = false;
|
||||
console.log('bluetooth', 'advertisingStop');
|
||||
});
|
||||
|
||||
Bleno.on('servicesSet', (error?: Error | null) => {
|
||||
console.log('bluetooth', `servicesSet: ${error ? error : 'success'}`);
|
||||
});
|
||||
}
|
||||
|
||||
private onWriteRequest(data: Buffer) {
|
||||
console.log(data.toString('hex'));
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// code from bleno's README
|
||||
//
|
||||
|
||||
// tslint:disable-next-line:no-duplicate-imports
|
||||
import * as bleno from 'bleno';
|
||||
|
||||
function test1() {
|
||||
const name = 'name';
|
||||
const serviceUuids = ['fffffffffffffffffffffffffffffff0'];
|
||||
|
||||
bleno.startAdvertising(name);
|
||||
bleno.startAdvertising(name, serviceUuids);
|
||||
bleno.startAdvertising(name, serviceUuids, (error) => {});
|
||||
}
|
||||
|
||||
function test2() {
|
||||
const uuid = 'e2c56db5dffb48d2b060d0f5a71096e0';
|
||||
const major = 0; // 0x0000 - 0xffff
|
||||
const minor = 0; // 0x0000 - 0xffff
|
||||
const measuredPower = -59; // -128 - 127
|
||||
|
||||
bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower);
|
||||
bleno.startAdvertisingIBeacon(uuid, major, minor, measuredPower, (error) => {});
|
||||
}
|
||||
|
||||
function test3() {
|
||||
const scanData = new Buffer(''); // maximum 31 bytes
|
||||
const advertisementData = new Buffer(''); // maximum 31 bytes
|
||||
|
||||
bleno.startAdvertisingWithEIRData(advertisementData);
|
||||
bleno.startAdvertisingWithEIRData(advertisementData, (error) => {});
|
||||
bleno.startAdvertisingWithEIRData(advertisementData, scanData, (error) => {});
|
||||
}
|
||||
|
||||
function test4() {
|
||||
bleno.stopAdvertising();
|
||||
bleno.stopAdvertising(() => {});
|
||||
}
|
||||
|
||||
function test5() {
|
||||
const service = new PrimaryService({uuid: '0000'});
|
||||
const services = [
|
||||
service
|
||||
];
|
||||
|
||||
bleno.setServices(services);
|
||||
bleno.setServices(services, (error) => {});
|
||||
}
|
||||
|
||||
function test6() {
|
||||
bleno.disconnect(); // Linux only
|
||||
}
|
||||
|
||||
function test7() {
|
||||
bleno.updateRssi(); // not available in OS X 10.9
|
||||
bleno.updateRssi((error, rssi) => {}); // not available in OS X 10.9
|
||||
}
|
||||
|
||||
function test8() {
|
||||
const PrimaryService = bleno.PrimaryService;
|
||||
|
||||
const primaryService = new PrimaryService({
|
||||
uuid: 'fffffffffffffffffffffffffffffff0', // or 'fff0' for 16-bit
|
||||
characteristics: [
|
||||
// see Characteristic for data type
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
function test9() {
|
||||
const Characteristic = bleno.Characteristic;
|
||||
|
||||
const characteristic = new Characteristic({
|
||||
uuid: 'fffffffffffffffffffffffffffffff1', // or 'fff1' for 16-bit
|
||||
properties: ['read'], // can be a combination of 'read', 'write', 'writeWithoutResponse', 'notify', 'indicate'
|
||||
secure: ['notify'], // enable security for properties, can be a combination of 'read', 'write', 'writeWithoutResponse', 'notify', 'indicate'
|
||||
value: null, // optional static value, must be of type Buffer - for read only characteristics
|
||||
descriptors: [
|
||||
// see Descriptor for data type
|
||||
new Descriptor({uuid: '0000'})
|
||||
],
|
||||
onReadRequest: null, // optional read request handler, function(offset, callback) { ... }
|
||||
onWriteRequest: null, // optional write request handler, function(data, offset, withoutResponse, callback) { ...}
|
||||
onSubscribe: null, // optional notify/indicate subscribe handler, function(maxValueSize, updateValueCallback) { ...}
|
||||
onUnsubscribe: null, // optional notify/indicate unsubscribe handler, function() { ...}
|
||||
onNotify: null, // optional notify sent handler, function() { ...}
|
||||
onIndicate: null // optional indicate confirmation received handler, function() { ...}
|
||||
});
|
||||
}
|
||||
|
||||
function test10() {
|
||||
Characteristic.RESULT_SUCCESS;
|
||||
Characteristic.RESULT_INVALID_OFFSET;
|
||||
Characteristic.RESULT_INVALID_ATTRIBUTE_LENGTH;
|
||||
Characteristic.RESULT_UNLIKELY_ERROR;
|
||||
}
|
||||
|
||||
function test11() {
|
||||
const Descriptor = bleno.Descriptor;
|
||||
|
||||
const descriptor = new Descriptor({
|
||||
uuid: '2901',
|
||||
value: 'value' // static value, must be of type Buffer or string if set
|
||||
});
|
||||
}
|
||||
|
||||
function test12() {
|
||||
bleno.on('stateChange', (state: string) => {});
|
||||
bleno.on('advertisingStart', (error?: Error | null) => {});
|
||||
bleno.on('advertisingStartError', (error: Error) => {});
|
||||
bleno.on('advertisingStop', () => {});
|
||||
bleno.on('servicesSet', (error?: Error | null) => {});
|
||||
bleno.on('servicesSetError', (error: Error) => {});
|
||||
bleno.on('accept', (clientAddress) => {}); // not available on OS X 10.9
|
||||
bleno.on('disconnect', (clientAddress) => {}); // Linux only
|
||||
bleno.on('rssiUpdate', (rssi) => {}); // not available on OS X 10.9
|
||||
}
|
||||
|
||||
Vendored
+102
-81
@@ -3,126 +3,147 @@
|
||||
// Definitions by: Manuel Francisco Naranjo <naranjo.manuel@gmail.com>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export class Characteristic {
|
||||
uuid: any;
|
||||
properties: any;
|
||||
secure: any;
|
||||
value: any;
|
||||
descriptors: any;
|
||||
/// <reference types="node" />
|
||||
|
||||
constructor(options: any);
|
||||
type State = 'poweredOn' | 'poweredOff' | 'unauthorized' | 'unsupported' | 'unknown' | 'resetting';
|
||||
|
||||
type Property = 'read' | 'write' | 'indicate' | 'notify' | 'writeWithoutResponse';
|
||||
|
||||
interface CharacteristicOptions {
|
||||
uuid: string;
|
||||
properties?: ReadonlyArray<Property> | null;
|
||||
secure?: ReadonlyArray<Property> | null;
|
||||
value?: Buffer | null;
|
||||
descriptors?: ReadonlyArray<Descriptor> | null;
|
||||
onIndicate?: (() => void) | null;
|
||||
onNotify?: (() => void) | null;
|
||||
onReadRequest?: ((
|
||||
offset: number,
|
||||
callback: (result: number, data?: Buffer) => void
|
||||
) => void) | null;
|
||||
onSubscribe?: ((maxValueSize: number, updateValueCallback: any) => void) | null;
|
||||
onUnsubscribe?: (() => void) | null;
|
||||
onWriteRequest?: ((
|
||||
data: Buffer,
|
||||
offset: number,
|
||||
withoutResponse: boolean,
|
||||
callback: (result: number) => void
|
||||
) => void) | null;
|
||||
}
|
||||
|
||||
declare class Characteristic {
|
||||
uuid: string;
|
||||
properties: ReadonlyArray<Property>;
|
||||
secure: ReadonlyArray<Property>;
|
||||
value: Buffer | null;
|
||||
descriptors: ReadonlyArray<Descriptor>;
|
||||
|
||||
constructor(options: CharacteristicOptions);
|
||||
|
||||
onIndicate(): void;
|
||||
|
||||
onNotify(): void;
|
||||
|
||||
onReadRequest(offset: any, callback: any): void;
|
||||
onReadRequest(offset: number, callback: (result: number, data?: Buffer) => void): void;
|
||||
|
||||
onSubscribe(maxValueSize: any, updateValueCallback: any): void;
|
||||
onSubscribe(maxValueSize: number, updateValueCallback: any): void;
|
||||
|
||||
onUnsubscribe(): void;
|
||||
|
||||
onWriteRequest(data: any, offset: any, withoutResponse: any, callback: any): void;
|
||||
onWriteRequest(data: Buffer, offset: number, withoutResponse: boolean, callback: (result: number) => void): void;
|
||||
|
||||
toString(): any;
|
||||
toString(): string;
|
||||
|
||||
static RESULT_ATTR_NOT_LONG: number;
|
||||
readonly RESULT_ATTR_NOT_LONG: number;
|
||||
|
||||
static RESULT_INVALID_ATTRIBUTE_LENGTH: number;
|
||||
readonly RESULT_INVALID_ATTRIBUTE_LENGTH: number;
|
||||
|
||||
static RESULT_INVALID_OFFSET: number;
|
||||
readonly RESULT_INVALID_OFFSET: number;
|
||||
|
||||
static RESULT_SUCCESS: number;
|
||||
readonly RESULT_SUCCESS: number;
|
||||
|
||||
static RESULT_UNLIKELY_ERROR: number;
|
||||
readonly RESULT_UNLIKELY_ERROR: number;
|
||||
|
||||
static readonly RESULT_ATTR_NOT_LONG: number;
|
||||
|
||||
static readonly RESULT_INVALID_ATTRIBUTE_LENGTH: number;
|
||||
|
||||
static readonly RESULT_INVALID_OFFSET: number;
|
||||
|
||||
static readonly RESULT_SUCCESS: number;
|
||||
|
||||
static readonly RESULT_UNLIKELY_ERROR: number;
|
||||
}
|
||||
|
||||
export class Descriptor {
|
||||
uuid: any;
|
||||
value: any;
|
||||
|
||||
constructor(options: any);
|
||||
|
||||
toString(): any;
|
||||
interface DescriptorOptions {
|
||||
uuid: string;
|
||||
value?: Buffer | string | null;
|
||||
}
|
||||
|
||||
export class PrimaryService {
|
||||
uuid: any;
|
||||
characteristics: any;
|
||||
declare class Descriptor {
|
||||
uuid: string;
|
||||
value: Buffer;
|
||||
|
||||
constructor(options: any);
|
||||
constructor(options: DescriptorOptions);
|
||||
|
||||
toString(): any;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export const address: string;
|
||||
interface PrimaryServiceOptions {
|
||||
uuid: string;
|
||||
characteristics?: ReadonlyArray<Characteristic> | null;
|
||||
}
|
||||
|
||||
export const domain: any;
|
||||
declare class PrimaryService {
|
||||
uuid: string;
|
||||
characteristics: ReadonlyArray<Characteristic>;
|
||||
|
||||
export const mtu: number;
|
||||
constructor(options: PrimaryServiceOptions);
|
||||
|
||||
export const platform: string;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export const rssi: number;
|
||||
interface Bleno extends NodeJS.EventEmitter {
|
||||
readonly Characteristic: typeof Characteristic;
|
||||
readonly Descriptor: typeof Descriptor;
|
||||
readonly PrimaryService: typeof PrimaryService;
|
||||
|
||||
export const state: string;
|
||||
readonly address: string;
|
||||
|
||||
export function addListener(type: any, listener: any): any;
|
||||
readonly mtu: number;
|
||||
|
||||
export function disconnect(): void;
|
||||
readonly platform: string;
|
||||
|
||||
export function emit(type: any, ...args: any[]): any;
|
||||
readonly rssi: number;
|
||||
|
||||
export function eventNames(): any;
|
||||
readonly state: State;
|
||||
|
||||
export function getMaxListeners(): any;
|
||||
disconnect(): void;
|
||||
|
||||
export function listenerCount(type: any): any;
|
||||
setServices(services: ReadonlyArray<PrimaryService>, callback?: (arg: Error | undefined | null) => void): void;
|
||||
|
||||
export function listeners(type: any): any;
|
||||
startAdvertising(name: string, serviceUuids?: ReadonlyArray<string>, callback?: (arg: Error | undefined | null) => void): void;
|
||||
|
||||
export function on(type: any, listener: any): any;
|
||||
startAdvertisingIBeacon(uuid: string, major: number, minor: number, measuredPower: number, callback?: (arg: Error | undefined | null) => void): void;
|
||||
|
||||
export function onAccept(clientAddress: any): void;
|
||||
startAdvertisingWithEIRData(advertisementData: Buffer, callback?: (arg: Error | undefined | null) => void): void;
|
||||
startAdvertisingWithEIRData(advertisementData: Buffer, scanData: Buffer, callback?: (arg: Error | undefined | null) => void): void;
|
||||
|
||||
export function onAddressChange(address: any): void;
|
||||
stopAdvertising(callback?: () => void): void;
|
||||
|
||||
export function onAdvertisingStart(error: any): void;
|
||||
updateRssi(callback?: (err: null, rssi: number) => void): void;
|
||||
|
||||
export function onAdvertisingStop(): void;
|
||||
on(event: 'stateChange', cb: (state: State) => void): this;
|
||||
on(event: 'accept', cb: (address: string) => void): this;
|
||||
on(event: 'mtuChange', cb: (mtu: number) => void): this;
|
||||
on(event: 'disconnect', cb: (clientAddress: string) => void): this;
|
||||
on(event: 'advertisingStart', cb: (err?: Error | null) => void): this;
|
||||
on(event: 'advertisingStartError', cb: (err: Error) => void): this;
|
||||
on(event: 'advertisingStop', cb: () => void): this;
|
||||
on(event: 'servicesSet', cb: (err?: Error | null) => void): this;
|
||||
on(event: 'servicesSetError', cb: (err: Error) => void): this;
|
||||
on(event: 'rssiUpdate', cb: (rssi: number) => void): this;
|
||||
}
|
||||
|
||||
export function onDisconnect(clientAddress: any): void;
|
||||
|
||||
export function onMtuChange(mtu: any): void;
|
||||
|
||||
export function onPlatform(platform: any): void;
|
||||
|
||||
export function onRssiUpdate(rssi: any): void;
|
||||
|
||||
export function onServicesSet(error: any): void;
|
||||
|
||||
export function onStateChange(state: any): void;
|
||||
|
||||
export function once(type: any, listener: any): any;
|
||||
|
||||
export function prependListener(type: any, listener: any): any;
|
||||
|
||||
export function prependOnceListener(type: any, listener: any): any;
|
||||
|
||||
export function removeAllListeners(type: any, ...args: any[]): any;
|
||||
|
||||
export function removeListener(type: any, listener: any): any;
|
||||
|
||||
export function setMaxListeners(n: any): any;
|
||||
|
||||
export function setServices(services: any, callback: any): void;
|
||||
|
||||
export function startAdvertising(name: any, serviceUuids: any, callback: any): void;
|
||||
|
||||
export function startAdvertisingIBeacon(uuid: any, major: any, minor: any, measuredPower: any, callback: any): void;
|
||||
|
||||
export function startAdvertisingWithEIRData(advertisementData: any, scanData: any, callback: any): void;
|
||||
|
||||
export function stopAdvertising(callback: any): void;
|
||||
|
||||
export function updateRssi(callback: any): void;
|
||||
declare const bleno: Bleno;
|
||||
export = bleno;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"dt-header": false
|
||||
"dt-header": false,
|
||||
"unified-signatures": false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import Application from '@ember/application';
|
||||
import EmberResolver from 'ember-resolver';
|
||||
|
||||
const MyResolver = EmberResolver.extend({
|
||||
pluralizedTypes: {
|
||||
sheep: 'sheep'
|
||||
}
|
||||
});
|
||||
|
||||
const App = Application.extend({
|
||||
Resolver: MyResolver
|
||||
});
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// Type definitions for ember-resolver 4.5
|
||||
// Project: https://github.com/ember-cli/ember-resolver#readme
|
||||
// Definitions by: Dan Freeman <https://github.com/dfreeman>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="ember" />
|
||||
|
||||
import Resolver from '@ember/application/resolver';
|
||||
|
||||
/**
|
||||
* An Ember `Resolver` implementation used by ember-cli.
|
||||
*/
|
||||
export default class EmberResolver extends Resolver {}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ember-resolver-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -11,7 +11,7 @@ app.use(session({
|
||||
secret: 'keyboard cat',
|
||||
name: 'connect.sid',
|
||||
store: new session.MemoryStore(),
|
||||
cookie: { path: '/', httpOnly: true, secure: false },
|
||||
cookie: { path: '/', httpOnly: true, secure: false, sameSite: true },
|
||||
genid: (req: express.Request): string => '',
|
||||
rolling: false,
|
||||
resave: true,
|
||||
|
||||
Vendored
+1
@@ -32,6 +32,7 @@ declare global {
|
||||
httpOnly: boolean;
|
||||
domain?: string;
|
||||
expires: Date | boolean;
|
||||
sameSite?: boolean | string;
|
||||
}
|
||||
|
||||
interface SessionCookie extends SessionCookieData {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import gitBranch = require('git-branch');
|
||||
|
||||
gitBranch()
|
||||
.then((name) => {});
|
||||
|
||||
gitBranch('cwd')
|
||||
.then((name) => {});
|
||||
|
||||
gitBranch.sync();
|
||||
gitBranch.sync('cwd');
|
||||
|
||||
gitBranch((err, name) => {});
|
||||
|
||||
gitBranch('cwd', (err, name) => {});
|
||||
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// Type definitions for git-branch 2.0
|
||||
// Project: https://github.com/jonschlinkert/git-branch
|
||||
// Definitions by: Ryan Clark <https://github.com/rynclark>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
export = GitBranch;
|
||||
|
||||
declare function GitBranch(cwd?: string): Promise<string>;
|
||||
declare function GitBranch(cwd?: string, callback?: (err: null | string, name: string) => void): void;
|
||||
declare function GitBranch(callback?: (err: null | string, name: string) => void): void;
|
||||
|
||||
declare namespace GitBranch {
|
||||
function sync(cwd?: string): string;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"git-branch-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+2
-2
@@ -7,7 +7,7 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { EventEmitter } from 'events';
|
||||
import { MarkupData } from 'parse5';
|
||||
import { ElementLocation } from 'parse5';
|
||||
import * as tough from 'tough-cookie';
|
||||
import { Script } from 'vm';
|
||||
|
||||
@@ -32,7 +32,7 @@ export class JSDOM {
|
||||
/**
|
||||
* The nodeLocation() method will find where a DOM node is within the source document, returning the parse5 location info for the node.
|
||||
*/
|
||||
nodeLocation(node: Node): MarkupData.ElementLocation | null;
|
||||
nodeLocation(node: Node): ElementLocation | null;
|
||||
|
||||
/**
|
||||
* The built-in vm module of Node.js allows you to create Script instances,
|
||||
|
||||
Vendored
+1
-1
@@ -4311,7 +4311,7 @@ declare namespace kendo.ui {
|
||||
scrollable?: boolean | GridScrollable;
|
||||
selectable?: boolean|string;
|
||||
sortable?: boolean | GridSortable;
|
||||
toolbar?: GridToolbarItem[];
|
||||
toolbar?: string|Function|(string|GridToolbarItem)[];
|
||||
beforeEdit?(e: GridBeforeEditEvent): void;
|
||||
cancel?(e: GridCancelEvent): void;
|
||||
cellClose?(e: GridCellCloseEvent): void;
|
||||
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
// Type definitions for koa-static-cache 5.1
|
||||
// Project: https://github.com/koajs/static-cache#readme
|
||||
// Definitions by: JounQin <https://github.com/JounQin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/**
|
||||
* Static server for koa.
|
||||
*/
|
||||
|
||||
import { Middleware } from 'koa';
|
||||
|
||||
declare namespace staticCache {
|
||||
interface Files {
|
||||
[path: string]: Options;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
dir?: string;
|
||||
maxAge?: number;
|
||||
cacheControl?: string;
|
||||
buffer?: boolean;
|
||||
gzip?: boolean;
|
||||
usePrecompiledGzip?: boolean;
|
||||
alias?: {};
|
||||
prefix?: string;
|
||||
dynamic?: boolean;
|
||||
filter?: ((path: string) => boolean) | string[];
|
||||
preload?: boolean;
|
||||
files?: Files;
|
||||
}
|
||||
}
|
||||
|
||||
declare function staticCache(
|
||||
dir: string | staticCache.Options,
|
||||
options?: staticCache.Options | staticCache.Files,
|
||||
files?: staticCache.Files
|
||||
): Middleware;
|
||||
|
||||
export = staticCache;
|
||||
@@ -0,0 +1,46 @@
|
||||
import Koa = require('koa');
|
||||
import staticCache = require('koa-static-cache');
|
||||
|
||||
const app = new Koa();
|
||||
|
||||
app.use(staticCache('.'));
|
||||
|
||||
app.use(
|
||||
staticCache('.', {
|
||||
maxAge: 0,
|
||||
filter: ['']
|
||||
})
|
||||
);
|
||||
|
||||
const files: staticCache.Files = {};
|
||||
|
||||
app.use(
|
||||
staticCache(
|
||||
'.',
|
||||
{
|
||||
maxAge: 0,
|
||||
filter: path => !!path
|
||||
},
|
||||
files
|
||||
)
|
||||
);
|
||||
|
||||
files['/service-worker.js'].maxAge = 0;
|
||||
|
||||
app.use(
|
||||
staticCache({
|
||||
dir: '.',
|
||||
maxAge: 0,
|
||||
files
|
||||
})
|
||||
);
|
||||
|
||||
app.use(
|
||||
staticCache(
|
||||
{
|
||||
dir: '.',
|
||||
maxAge: 0
|
||||
},
|
||||
files
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"koa-static-cache-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+1
-1
@@ -40,7 +40,7 @@ declare namespace LRU {
|
||||
* `max` like-sized things. The item is passed as the first argument,
|
||||
* and the key is passed as the second argument.
|
||||
*/
|
||||
length?(value: V): number;
|
||||
length?(value: V, key?: K): number;
|
||||
|
||||
/**
|
||||
* Function that is called on items when they are dropped from the cache.
|
||||
|
||||
Vendored
+553
@@ -0,0 +1,553 @@
|
||||
// Type definitions for motor-hat 2.0
|
||||
// Project: http://www.github.com/jcane86/motor-hat
|
||||
// Definitions by: Yevgen Muntyan <https://github.com/muntyan>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export type Direction = 'fwd' | 'back';
|
||||
|
||||
type Callback = (err?: Error, result?: any) => void;
|
||||
|
||||
export interface PinDefinitionObject {
|
||||
/**
|
||||
* Pin number of the PWM output
|
||||
*/
|
||||
PWM: number;
|
||||
|
||||
/**
|
||||
* Pin number of the first coil output
|
||||
*/
|
||||
IN1: number;
|
||||
|
||||
/**
|
||||
* Pin number of the second coil output
|
||||
*/
|
||||
IN2: number;
|
||||
}
|
||||
|
||||
export type PinDefinition = PinDefinitionObject | number[];
|
||||
|
||||
export interface DCOptions {
|
||||
/**
|
||||
* PWM Interface Object
|
||||
*/
|
||||
pwm: object;
|
||||
|
||||
/**
|
||||
* Pin definition for the motor
|
||||
*/
|
||||
pins: PinDefinition;
|
||||
|
||||
speed?: number;
|
||||
frequency?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* DC Controller Object
|
||||
*/
|
||||
export interface DC {
|
||||
/**
|
||||
* Initialize the DC controller instance.
|
||||
* Synchronous overload.
|
||||
*/
|
||||
init(): this;
|
||||
|
||||
/**
|
||||
* Initialize the DC controller instance.
|
||||
* Asynchronous overload.
|
||||
*
|
||||
* @param cb Node style callback for asynch initialization
|
||||
*/
|
||||
init(cb: Callback): void;
|
||||
|
||||
/**
|
||||
* Starts the motor in the desired direction.
|
||||
*
|
||||
* @param dir Direction of movement.
|
||||
* @param cb Node style callback. Gets called with cb(err, result) after completion.
|
||||
*/
|
||||
run(dir: Direction, cb: Callback): void;
|
||||
|
||||
/**
|
||||
* Starts the motor in the desired direction.
|
||||
*
|
||||
* @param dir Direction of movement.
|
||||
*/
|
||||
runSync(dir: Direction): void;
|
||||
|
||||
/**
|
||||
* Stops the motor.
|
||||
* Doesn't actually brake the motor, just stops applying voltage to it.
|
||||
*
|
||||
* @param cb Node style callback. Gets called with cb(err, result) after completion.
|
||||
*/
|
||||
stop(cb: Callback): void;
|
||||
|
||||
/**
|
||||
* Stops the motor.
|
||||
* Doesn't actually brake the motor, just stops applying voltage to it.
|
||||
*/
|
||||
stopSync(): void;
|
||||
|
||||
/**
|
||||
* Sets DC motor speed.
|
||||
* The speed can be set as a percentage, from 0% to 100%. To change the actual top speed,
|
||||
* the actual voltage supplied to the motor needs to be controlled by hardware (get a higher
|
||||
* voltage source).
|
||||
*
|
||||
* @param speed Relative speed. 0% to 100%.
|
||||
* @param cb Node style callback. Gets called with cb(err, result) after completion.
|
||||
*/
|
||||
setSpeed(speed: number, cb: Callback): void;
|
||||
|
||||
/**
|
||||
* Sets DC motor speed.
|
||||
* The speed can be set as a percentage, from 0% to 100%. To change the actual top speed,
|
||||
* the actual voltage supplied to the motor needs to be controlled by hardware (get a higher
|
||||
* voltage source).
|
||||
*
|
||||
* @param speed Relative speed. 0% to 100%.
|
||||
*/
|
||||
setSpeedSync(speed: number): void;
|
||||
|
||||
/**
|
||||
* Sets the PWM frequency for the DC motor.
|
||||
* This setting affects the frequency at which the PWM chip will work to command the DC motor.
|
||||
*
|
||||
* @param freq PWM Frequency in Hz.
|
||||
* @param cb Node style callback. Gets called with cb(err, result) after completion.
|
||||
*/
|
||||
setFrequency(freq: number, cb: Callback): void;
|
||||
|
||||
/**
|
||||
* Sets the PWM frequency for the DC motor.
|
||||
* This setting affects the frequency at which the PWM chip will work to command the DC motor.
|
||||
*
|
||||
* @param freq PWM Frequency in Hz.
|
||||
*/
|
||||
setFrequencySync(freq: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Servo controller initialization options
|
||||
*/
|
||||
export interface ServoOptions {
|
||||
/**
|
||||
* PWM Interface Object
|
||||
*/
|
||||
pwm: object;
|
||||
|
||||
/**
|
||||
* Servo controller pin. Which pin (0 to 15) is the servo connected to?
|
||||
*/
|
||||
pin: number;
|
||||
|
||||
/**
|
||||
* Duration in ms of pulse at position 0
|
||||
*/
|
||||
min?: number;
|
||||
|
||||
/**
|
||||
* Duration in ms of pulse at position 100
|
||||
*/
|
||||
max?: number;
|
||||
|
||||
/**
|
||||
* PWM Controller frequency for the servo
|
||||
*/
|
||||
freq?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Servo Controller Object
|
||||
*/
|
||||
export interface Servo {
|
||||
/**
|
||||
* Move Servo to desired position.
|
||||
*
|
||||
* @param pos Relative position (0% to 100%).
|
||||
*/
|
||||
moveTo(pos: number): void;
|
||||
|
||||
/**
|
||||
* Calibrate the limits for the servolib
|
||||
*
|
||||
* @param freq The update freq in Hz
|
||||
* @param min The min. pulse in ms
|
||||
* @param max The max. pulse in ms
|
||||
*/
|
||||
calibrate(freq: number, min: number, max: number): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stepper controller initialization options
|
||||
*/
|
||||
export interface StepperOptions {
|
||||
/**
|
||||
* PWM Interface Object
|
||||
*/
|
||||
pwm: object;
|
||||
|
||||
/**
|
||||
* Pin definition for the motor
|
||||
*/
|
||||
pins: {
|
||||
/**
|
||||
* Pin definition for winding 1 of the stepper
|
||||
*/
|
||||
W1: PinDefinition;
|
||||
|
||||
/**
|
||||
* Pin definition for winding 2 of the stepper
|
||||
*/
|
||||
W2: PinDefinition;
|
||||
};
|
||||
|
||||
/**
|
||||
* Steps per revolution of the stepper motor
|
||||
*/
|
||||
steps?: number;
|
||||
|
||||
/**
|
||||
* number of microsteps per step
|
||||
*/
|
||||
microsteps?: 8 | 16;
|
||||
|
||||
/**
|
||||
* PWM Controller frequency for the stepper
|
||||
*/
|
||||
frequency?: number;
|
||||
|
||||
/**
|
||||
* Stepping style
|
||||
*/
|
||||
style?: 'single' | 'double' | 'interleaved' | 'microstep';
|
||||
|
||||
current?: number;
|
||||
|
||||
/**
|
||||
* Pulses per second
|
||||
*/
|
||||
pps?: number;
|
||||
|
||||
/**
|
||||
* Revolutions per minute
|
||||
*/
|
||||
rpm?: number;
|
||||
|
||||
/**
|
||||
* Steps per second
|
||||
*/
|
||||
sps?: number;
|
||||
}
|
||||
|
||||
export interface StepResult {
|
||||
/**
|
||||
* Performed steps
|
||||
*/
|
||||
steps: number;
|
||||
|
||||
/**
|
||||
* Direction of steps performed
|
||||
*/
|
||||
dir: Direction;
|
||||
|
||||
/**
|
||||
* Time in ms taken to perform the steps
|
||||
*/
|
||||
duration: number;
|
||||
|
||||
/**
|
||||
* Number of steps retried
|
||||
*/
|
||||
retried: number;
|
||||
}
|
||||
|
||||
export interface StepSyncResult {
|
||||
/**
|
||||
* Performed steps
|
||||
*/
|
||||
steps: number;
|
||||
|
||||
/**
|
||||
* Direction of steps performed
|
||||
*/
|
||||
dir: Direction;
|
||||
|
||||
/**
|
||||
* Time in ms taken to perform the steps
|
||||
*/
|
||||
duration: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stepper motor speed for step().
|
||||
*/
|
||||
export interface StepperSpeed {
|
||||
/**
|
||||
* Speed in steps per second
|
||||
*/
|
||||
sps?: number;
|
||||
|
||||
/**
|
||||
* Speed in pulses per second (pulses can be steps, microsteps, etc)
|
||||
*/
|
||||
pps?: number;
|
||||
|
||||
/**
|
||||
* Speed in revolutions per minute
|
||||
*/
|
||||
rpm?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stepper motor controller
|
||||
*/
|
||||
export interface Stepper {
|
||||
readonly options: StepperOptions;
|
||||
|
||||
/**
|
||||
* Initialize the Stepeper controller instance.
|
||||
* Synchronous overload.
|
||||
*
|
||||
* @returns Returns init'd Stepper controller object (self)
|
||||
*/
|
||||
init(): this;
|
||||
|
||||
/**
|
||||
* Initialize the Stepeper controller instance.
|
||||
* Synchronous overload.
|
||||
*
|
||||
* @param cb Node style callback for asynch initialization
|
||||
*/
|
||||
init(cb: (err: null, self: Stepper) => void): void;
|
||||
|
||||
/**
|
||||
* Perform arbitrary number of steps asynchronously.
|
||||
* Configuration as stepping style, speed, etc should have been set previously.
|
||||
*
|
||||
* @param dir Direction of movement
|
||||
* @param steps Number of steps.
|
||||
* @param cb Node style callback. cb(err, result).
|
||||
*/
|
||||
step(
|
||||
dir: Direction,
|
||||
steps: number,
|
||||
cb: (err?: Error, result?: StepResult) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Perform arbitrary number of steps synchronously.
|
||||
* Configuration as stepping style, speed, etc should have been set previously.
|
||||
*
|
||||
* @param dir Direction of movement
|
||||
* @param steps Number of steps.
|
||||
* @returns The result of the action.
|
||||
*/
|
||||
stepSync(dir: Direction, steps: number): StepSyncResult;
|
||||
|
||||
/**
|
||||
* Perform one step asynchronously.
|
||||
* Configuration as stepping style, speed, etc should have been set previously.
|
||||
*
|
||||
* @param dir Direction of movement
|
||||
* @param cb Node style callback. cb(err, result).
|
||||
*/
|
||||
oneStep(dir: Direction, cb: (err?: Error, result?: any) => void): void;
|
||||
|
||||
/**
|
||||
* Perform one step synchronously.
|
||||
* Configuration as stepping style, speed, etc should have been set previously.
|
||||
*
|
||||
* @param dir Direction of movement
|
||||
*/
|
||||
oneStepSync(dir: Direction): void;
|
||||
|
||||
/**
|
||||
* Release the stepper motor asynchronously.
|
||||
*
|
||||
* Stops applying current to the motor coils.
|
||||
*
|
||||
* @param cb Node style callback
|
||||
*/
|
||||
release(cb: (err?: Error, result?: any) => void): void;
|
||||
|
||||
/**
|
||||
* Release the stepper motor synchronously.
|
||||
* Stops applying current to the motor coils.
|
||||
*/
|
||||
releaseSync(): void;
|
||||
|
||||
/**
|
||||
* Set the current rate at which to supply the steps.
|
||||
* Provide a number from 0 to 1 and the current will be reduced proportionally
|
||||
*
|
||||
* @param current Current rate, from 0 to 1.
|
||||
*/
|
||||
setCurrent(current: number): void;
|
||||
|
||||
/**
|
||||
* Set stepping style.
|
||||
*
|
||||
* @param style Stepping style.
|
||||
*/
|
||||
setStyle(style: 'single' | 'double' | 'interleaved' | 'microstep'): void;
|
||||
|
||||
/**
|
||||
* Set PWM Controller working frequency asynchronously.
|
||||
*
|
||||
* @param freq PWM frequency.
|
||||
* @param cb Node style callback. cb(err, result).
|
||||
*/
|
||||
setFrequency(freq: number, cb: (err?: Error, result?: any) => void): void;
|
||||
|
||||
/**
|
||||
* Set PWM Controller working frequency synchronously.
|
||||
*
|
||||
* @param freq PWM frequency.
|
||||
*/
|
||||
setFrequencySync(freq: number): void;
|
||||
|
||||
/**
|
||||
* Set desired number of microsteps per step.
|
||||
* (Used for microstepping)
|
||||
*
|
||||
* @param ms Microsteps per step
|
||||
*/
|
||||
setMicrosteps(ms: 8 | 16): void;
|
||||
|
||||
/**
|
||||
* Set number of steps per revolution for motor.
|
||||
*
|
||||
* @param steps Number of steps per revolution for stepper motor.
|
||||
*/
|
||||
setSteps(steps: number): void;
|
||||
|
||||
/**
|
||||
* Set motor speed for step().
|
||||
*/
|
||||
setSpeed(speed: StepperSpeed): void;
|
||||
}
|
||||
|
||||
export interface MotorPins {
|
||||
readonly PWM: number;
|
||||
readonly IN2: number;
|
||||
readonly IN1: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* motorHat controller
|
||||
*
|
||||
* Needs to be initialized with init().
|
||||
*/
|
||||
export interface MotorHat {
|
||||
readonly pins: {
|
||||
M1: MotorPins;
|
||||
M2: MotorPins;
|
||||
M3: MotorPins;
|
||||
M4: MotorPins;
|
||||
};
|
||||
|
||||
/**
|
||||
* Array of initialized Servo controllers
|
||||
*/
|
||||
readonly servos: ReadonlyArray<Servo>;
|
||||
|
||||
/**
|
||||
* Array of initialized Stepper controllers
|
||||
*/
|
||||
readonly steppers: ReadonlyArray<Stepper>;
|
||||
|
||||
/**
|
||||
* Array of initialized DC controllers
|
||||
*/
|
||||
readonly dcs: ReadonlyArray<DC>;
|
||||
|
||||
/**
|
||||
* Creates a servo motor controller.
|
||||
* Pass in an options object to generate an uninitialized ServoLib object.
|
||||
*/
|
||||
servo(opts: ServoOptions): Servo;
|
||||
|
||||
/**
|
||||
* Creates a stepper motor controller.
|
||||
* Pass in an options object to generate an uninitialized StepperLib object.
|
||||
*/
|
||||
stepper(opts: StepperOptions): Stepper;
|
||||
|
||||
/**
|
||||
* Creates a new DC motor controller
|
||||
* Pass in an options object to generate an uninitialized DCLib object
|
||||
*/
|
||||
dc(opts: DCOptions): DC;
|
||||
|
||||
/**
|
||||
* Initialize the motorHat library instance.
|
||||
* Synchronous overload.
|
||||
*
|
||||
* Instantiates the individual Motor/Servo/Stepper controllers and initializes them.
|
||||
*
|
||||
* @returns Returns initialized motorHat object (self)
|
||||
*/
|
||||
init(): MotorHat;
|
||||
|
||||
/**
|
||||
* Initialize the motorHat library instance.
|
||||
* Asynchronous overload.
|
||||
*
|
||||
* Instantiates the individual Motor/Servo/Stepper controllers and initializes them.
|
||||
* Returns initialized motorHat object (self) in second parameter to callback if callback
|
||||
* provided, to enable chaining.
|
||||
*
|
||||
* @param cb Node style callback for asynch initialization
|
||||
*/
|
||||
init(cb: Callback): void;
|
||||
}
|
||||
|
||||
export type Motor = 'M1' | 'M2' | 'M3' | 'M4';
|
||||
|
||||
export interface MotorHatOptions {
|
||||
/**
|
||||
* i2c address of the PWM chip on the MotorHat.
|
||||
*
|
||||
* * 0x6F for knockoff HATs.
|
||||
*
|
||||
* * 0x60 for official AdaFruit HATs??
|
||||
*/
|
||||
address?: number;
|
||||
|
||||
/**
|
||||
* i2c driver devfile number. Varies by RaspBerry version.
|
||||
* Should be automatically detected.
|
||||
*/
|
||||
busnum?: number;
|
||||
|
||||
/**
|
||||
* Definition of the stepper motors connected to the HAT.
|
||||
* At most 2 steppers, each motor is represented by either an object of the form
|
||||
* { W1: winding, W2: winding }. Each winding should be one of following: 'M1', 'M2', 'M3',
|
||||
* 'M4' depending on the port the stepper is connected to. Correct example: { W1: 'M3', W2: 'M1' }
|
||||
*/
|
||||
steppers?: ReadonlyArray<{ W1: Motor; W2: Motor }>;
|
||||
|
||||
/**
|
||||
* Definition of the DC motors connected to the HAT.
|
||||
* At most 4 DCs, each should be one of following: 'M1', 'M2', 'M3', 'M4' depending on
|
||||
* port the motor is connected to.
|
||||
*/
|
||||
dcs?: ReadonlyArray<Motor>;
|
||||
|
||||
/**
|
||||
* Definition of the servos connected to the HAT.
|
||||
* List of the channels that have servos connected to them. 0 to 15.
|
||||
*/
|
||||
servos?: ReadonlyArray<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new MotorHat controller
|
||||
*
|
||||
* Pass in an options object to generate an uninitialized MotorHat object.
|
||||
*/
|
||||
declare function motorhat(options: MotorHatOptions): MotorHat;
|
||||
export default motorhat;
|
||||
@@ -0,0 +1,15 @@
|
||||
import createMotorHat, { DC, Motor, MotorHat } from 'motor-hat';
|
||||
|
||||
function test() {
|
||||
const motors: Motor[] = ['M1', 'M2'];
|
||||
const motorHat: MotorHat = createMotorHat({
|
||||
dcs: motors,
|
||||
servos: [1, 2, 3],
|
||||
steppers: [{ W1: 'M3', W2: 'M1' }],
|
||||
address: 0x60,
|
||||
}).init();
|
||||
const dcL: DC = motorHat.dcs[0];
|
||||
const dcR: DC = motorHat.dcs[1];
|
||||
dcL.run('fwd', () => {});
|
||||
dcR.setSpeed(50, (err) => {});
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"motor-hat-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+270
@@ -0,0 +1,270 @@
|
||||
// Type definitions for nuka-carousel 4.2
|
||||
// Project: https://github.com/FormidableLabs/nuka-carousel
|
||||
// Definitions by: Roman Charugin <https://github.com/Romic>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
export default class Carousel extends React.Component<CarouselProps, CarouselState> {}
|
||||
|
||||
export type CellAlignProp = 'left' | 'center' | 'right';
|
||||
|
||||
export type HeightModeProp = 'first' | 'current' | 'max';
|
||||
|
||||
export type SlidesToScrollProp = number | 'auto';
|
||||
|
||||
export type SlideWidthProp = string | number;
|
||||
|
||||
export interface SlideRenderControlProps {
|
||||
/**
|
||||
* Current slide index
|
||||
*/
|
||||
currentSlide: number;
|
||||
/**
|
||||
* Total amount of slides
|
||||
*/
|
||||
slideCount: number;
|
||||
/**
|
||||
* Current frame width (px)
|
||||
*/
|
||||
frameWidth: number;
|
||||
/**
|
||||
* Current slide width (px)
|
||||
*/
|
||||
slideWidth: number;
|
||||
/**
|
||||
* Slides to scroll at once
|
||||
*/
|
||||
slidesToScroll: number;
|
||||
/**
|
||||
* Space between slides, as an integer, but reflected as px
|
||||
*/
|
||||
cellSpacing: number;
|
||||
/**
|
||||
* Slides to show at once
|
||||
*/
|
||||
slidesToShow: number;
|
||||
/**
|
||||
* Infinite mode enabled
|
||||
*/
|
||||
wrapAround: boolean;
|
||||
/**
|
||||
* Go to the next slide method
|
||||
*/
|
||||
nextSlide: () => void;
|
||||
/**
|
||||
* Go to the previous slide method
|
||||
*/
|
||||
previousSlide: () => void;
|
||||
/**
|
||||
* Go to X slide method
|
||||
* @param index Slide's index to go
|
||||
*/
|
||||
goToSlide: (index: number) => void;
|
||||
}
|
||||
|
||||
export type RenderControl = (props: SlideRenderControlProps) => JSX.Element;
|
||||
|
||||
export interface CarouselProps {
|
||||
/**
|
||||
* Hook to be called after a slide is changed
|
||||
* @param prevSlide Index of the previous slide
|
||||
*/
|
||||
afterSlide?: (prevSlide: number) => void;
|
||||
/**
|
||||
* Autoplay mode active
|
||||
* @default false
|
||||
*/
|
||||
autoplay?: boolean;
|
||||
/**
|
||||
* Interval for autoplay iteration (ms)
|
||||
* @default 3000
|
||||
*/
|
||||
autoplayInterval?: number;
|
||||
/**
|
||||
* Hook to be called before a slide is changed
|
||||
* @param currentSlide Index of the current slide
|
||||
* @param endSlide Index of the last slide
|
||||
*/
|
||||
beforeSlide?: (currentSlide: number, endSlide: number) => void;
|
||||
/**
|
||||
* When displaying more than one slide,
|
||||
* sets which position to anchor the current slide to
|
||||
*/
|
||||
cellAlign?: CellAlignProp;
|
||||
/**
|
||||
* Space between slides, as an integer, but reflected as px
|
||||
*/
|
||||
cellSpacing?: number;
|
||||
/**
|
||||
* Additional className
|
||||
*/
|
||||
className?: string;
|
||||
/**
|
||||
* Enable mouse swipe/dragging
|
||||
*/
|
||||
dragging?: boolean;
|
||||
/**
|
||||
* Animation easing function
|
||||
* @see https://github.com/d3/d3-ease
|
||||
*/
|
||||
easing?: string;
|
||||
/**
|
||||
* Animation easing function when swipe exceeds edge
|
||||
* @see https://github.com/d3/d3-ease
|
||||
*/
|
||||
edgeEasing?: string;
|
||||
/**
|
||||
* Used to set overflow style property on slider frame
|
||||
* @default 'hidden'
|
||||
*/
|
||||
frameOverflow?: string;
|
||||
/**
|
||||
* Used to set the margin of the slider frame.
|
||||
* Accepts any string dimension value such as "0px 20px" or "500px"
|
||||
* @example '0px 20px'
|
||||
* @example '500px'
|
||||
*/
|
||||
framePadding?: string;
|
||||
/**
|
||||
* Change the height of the slides based either on the first slide,
|
||||
* the current slide, or the maximum height of all slides.
|
||||
*/
|
||||
heightMode?: HeightModeProp;
|
||||
/**
|
||||
* Initial height of the slides (px)
|
||||
*/
|
||||
initialSlideHeight?: number;
|
||||
/**
|
||||
* Initial width of the slides (px)
|
||||
*/
|
||||
initialSlideWidth?: number;
|
||||
/**
|
||||
* Window onResize callback
|
||||
*/
|
||||
onResize?: () => void;
|
||||
/**
|
||||
* Function for rendering top left control
|
||||
*/
|
||||
renderTopLeftControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering top center control
|
||||
*/
|
||||
renderTopCenterControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering top right control
|
||||
*/
|
||||
renderTopRightControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering center left control
|
||||
*/
|
||||
renderCenterLeftControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering center center control
|
||||
*/
|
||||
renderCenterCenterControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering center right control
|
||||
*/
|
||||
renderCenterRightControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering bottom left control
|
||||
*/
|
||||
renderBottomLeftControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering bottom center control
|
||||
*/
|
||||
renderBottomCenterControls?: RenderControl;
|
||||
/**
|
||||
* Function for rendering bottom right control
|
||||
*/
|
||||
renderBottomRightControls?: RenderControl;
|
||||
/**
|
||||
* Manually set the index of the slide to be shown
|
||||
*/
|
||||
slideIndex?: number;
|
||||
/**
|
||||
* Slides to scroll at once. Set to "auto"
|
||||
* to always scroll the current number of visible slides
|
||||
*/
|
||||
slidesToScroll?: SlidesToScrollProp;
|
||||
/**
|
||||
* Slides to show at once
|
||||
*/
|
||||
slidesToShow?: number;
|
||||
/**
|
||||
* Manually set slideWidth
|
||||
* @example '20px'
|
||||
* @example 0.8
|
||||
*/
|
||||
slideWidth?: SlideWidthProp;
|
||||
/**
|
||||
* Animation duration
|
||||
*/
|
||||
speed?: number;
|
||||
/**
|
||||
* Enable touch swipe/dragging
|
||||
*/
|
||||
swiping?: boolean;
|
||||
/**
|
||||
* Enable the slides to transition vertically
|
||||
*/
|
||||
vertical?: boolean;
|
||||
/**
|
||||
* Used to hardcode the slider width
|
||||
* @example '80%'
|
||||
* @example '500px'
|
||||
*/
|
||||
width?: string;
|
||||
/**
|
||||
* Sets infinite wrapAround mode
|
||||
* @default false
|
||||
*/
|
||||
wrapAround?: boolean;
|
||||
}
|
||||
|
||||
export interface CarouselState {
|
||||
/**
|
||||
* Current slide index
|
||||
*/
|
||||
currentSlide: number;
|
||||
/**
|
||||
* Is dragging enabled
|
||||
*/
|
||||
dragging: boolean;
|
||||
/**
|
||||
* Current frame width
|
||||
*/
|
||||
frameWidth: number;
|
||||
/**
|
||||
* Current left value
|
||||
*/
|
||||
left: number;
|
||||
/**
|
||||
* Total amount of slides
|
||||
*/
|
||||
slideCount: number;
|
||||
/**
|
||||
* Slides to scroll at once
|
||||
*/
|
||||
slidesToScroll: number;
|
||||
/**
|
||||
* Current slide width
|
||||
*/
|
||||
slideWidth: SlideWidthProp;
|
||||
/**
|
||||
* Current top value
|
||||
*/
|
||||
top: number;
|
||||
/**
|
||||
* Easing function name
|
||||
*/
|
||||
easing: string;
|
||||
/**
|
||||
* Is infinite mode enabled
|
||||
*/
|
||||
isWrappingAround: boolean;
|
||||
wrapToIndex: boolean;
|
||||
resetWrapAroundPosition: boolean;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import * as React from 'react';
|
||||
import { render } from 'react-dom';
|
||||
|
||||
import Carousel, { CarouselProps } from 'nuka-carousel';
|
||||
|
||||
const props: CarouselProps = {
|
||||
afterSlide: () => {},
|
||||
autoplay: true,
|
||||
autoplayInterval: 5000,
|
||||
beforeSlide: () => {},
|
||||
cellAlign: 'center',
|
||||
cellSpacing: 500,
|
||||
dragging: true,
|
||||
easing: 'easePoly',
|
||||
edgeEasing: 'easePolyInOut',
|
||||
framePadding: '100px',
|
||||
heightMode: 'max',
|
||||
initialSlideHeight: 200,
|
||||
initialSlideWidth: 500,
|
||||
onResize: () => {},
|
||||
renderTopLeftControls: () => <button />,
|
||||
renderTopCenterControls: () => <button />,
|
||||
renderTopRightControls: () => <button />,
|
||||
renderCenterLeftControls: () => <button />,
|
||||
renderCenterCenterControls: () => <button />,
|
||||
renderCenterRightControls: () => <button />,
|
||||
renderBottomLeftControls: () => <button />,
|
||||
renderBottomCenterControls: () => <button />,
|
||||
renderBottomRightControls: () => <button />,
|
||||
slideIndex: 2,
|
||||
slidesToScroll: 'auto',
|
||||
slidesToShow: 1,
|
||||
slideWidth: 0.8,
|
||||
speed: 2000,
|
||||
swiping: true,
|
||||
vertical: false,
|
||||
width: '500px',
|
||||
wrapAround: false
|
||||
};
|
||||
|
||||
class CarouselComponent extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Carousel {...props}>
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide1" />
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide2" />
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide3" />
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide4" />
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide5" />
|
||||
<img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide6" />
|
||||
</Carousel>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"nuka-carousel-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Vendored
+12
-2
@@ -12,9 +12,19 @@ declare namespace OktaVuePlugin {
|
||||
issuer: string;
|
||||
client_id: string;
|
||||
redirect_uri: string;
|
||||
scope: string;
|
||||
scope?: string;
|
||||
response_type?: string;
|
||||
}
|
||||
|
||||
interface OktaOpenIDOptions {
|
||||
sessionToken?: string;
|
||||
responseMode?: string;
|
||||
responseType?: string | string[];
|
||||
scopes?: string[];
|
||||
state?: string;
|
||||
nonce?: string;
|
||||
}
|
||||
|
||||
function install(vm: VueConstructor, options: OktaVueOptions): PluginFunction<VueConstructor>;
|
||||
function handleCallback(): VueConstructor;
|
||||
}
|
||||
@@ -24,7 +34,7 @@ export default OktaVuePlugin;
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$auth: {
|
||||
loginRedirect(): void;
|
||||
loginRedirect(fromUri?: string, additionalParams?: OktaVuePlugin.OktaOpenIDOptions): void;
|
||||
logout(): Promise<void>;
|
||||
isAuthenticated(): Promise<boolean>;
|
||||
handleAuthentication(): Promise<void>;
|
||||
|
||||
@@ -46,5 +46,15 @@ const component = Vue.extend({
|
||||
redirect() {
|
||||
this.$auth.loginRedirect();
|
||||
},
|
||||
profileRedirect() {
|
||||
this.$auth.loginRedirect('/profile', {
|
||||
sessionToken: 'string',
|
||||
responseMode: 'string',
|
||||
responseType: 'string',
|
||||
scopes: ['string1', 'string2'],
|
||||
state: 'string',
|
||||
nonce: 'string',
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
// Type definitions for parse5-htmlparser2-tree-adapter 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import * as parse5 from "parse5";
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter Node interface.
|
||||
*/
|
||||
export interface Node {
|
||||
/**
|
||||
* The type of the node. E.g. {@link Document} will have `type` equal to 'root'`.
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* [DOM spec](https://dom.spec.whatwg.org/#dom-node-nodetype)-compatible node {@link type}.
|
||||
*/
|
||||
nodeType: number;
|
||||
/**
|
||||
* Parent node.
|
||||
*/
|
||||
parent: ParentNode;
|
||||
/**
|
||||
* Same as {@link parent}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
parentNode: ParentNode;
|
||||
/**
|
||||
* Previous sibling.
|
||||
*/
|
||||
prev: Node;
|
||||
/**
|
||||
* Same as {@link prev}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
previousSibling: Node;
|
||||
/**
|
||||
* Next sibling.
|
||||
*/
|
||||
next: Node;
|
||||
/**
|
||||
* Same as {@link next}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
nextSibling: Node;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter ParentNode interface.
|
||||
*/
|
||||
export interface ParentNode extends Node {
|
||||
/**
|
||||
* Child nodes.
|
||||
*/
|
||||
children: Node[];
|
||||
/**
|
||||
* Same as {@link children}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
childNodes: Node[];
|
||||
/**
|
||||
* First child of the node.
|
||||
*/
|
||||
firstChild: Node;
|
||||
/**
|
||||
* Last child of the node.
|
||||
*/
|
||||
lastChild: Node;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter DocumentType interface.
|
||||
*/
|
||||
export interface DocumentType extends Node {
|
||||
/**
|
||||
* The type of the node.
|
||||
*/
|
||||
type: "directive";
|
||||
/**
|
||||
* Node name.
|
||||
*/
|
||||
name: "!doctype";
|
||||
/**
|
||||
* Serialized doctype {@link name}, {@link publicId} and {@link systemId}.
|
||||
*/
|
||||
data: string;
|
||||
/**
|
||||
* Document type name.
|
||||
*/
|
||||
"x-name": string;
|
||||
/**
|
||||
* Document type public identifier.
|
||||
*/
|
||||
"x-publicId": string;
|
||||
/**
|
||||
* Document type system identifier.
|
||||
*/
|
||||
"x-systemId": string;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter Document interface.
|
||||
*/
|
||||
export interface Document extends ParentNode {
|
||||
/**
|
||||
* The type of the node.
|
||||
*/
|
||||
type: "root";
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
name: "root";
|
||||
/**
|
||||
* [Document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks).
|
||||
*/
|
||||
"x-mode": parse5.DocumentMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter DocumentFragment interface.
|
||||
*/
|
||||
export interface DocumentFragment extends ParentNode {
|
||||
/**
|
||||
* The type of the node.
|
||||
*/
|
||||
type: "root";
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
name: "root";
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter Element interface.
|
||||
*/
|
||||
export interface Element extends ParentNode {
|
||||
/**
|
||||
* The name of the node. Equals to element {@link tagName}.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Element tag name.
|
||||
*/
|
||||
tagName: string;
|
||||
/**
|
||||
* Element namespace.
|
||||
*/
|
||||
namespace: string;
|
||||
/**
|
||||
* Element attributes.
|
||||
*/
|
||||
attribs: { [name: string]: string };
|
||||
/**
|
||||
* Element attribute namespaces.
|
||||
*/
|
||||
"x-attribsNamespace": { [name: string]: string };
|
||||
/**
|
||||
* Element attribute namespace-related prefixes.
|
||||
*/
|
||||
"x-attribsPrefix": { [name: string]: string };
|
||||
/**
|
||||
* Element source code location info. Available if location info is enabled via ParserOptions.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.ElementLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter CommentNode interface.
|
||||
*/
|
||||
export interface CommentNode extends Node {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
name: "comment";
|
||||
/**
|
||||
* Comment text.
|
||||
*/
|
||||
data: string;
|
||||
/**
|
||||
* Same as {@link data}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
nodeValue: string;
|
||||
/**
|
||||
* Comment source code location info. Available if location info is enabled via ParserOptions.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
/**
|
||||
* htmlparser2 tree adapter TextNode interface.
|
||||
*/
|
||||
export interface TextNode extends Node {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
name: "text";
|
||||
/**
|
||||
* Text content.
|
||||
*/
|
||||
data: string;
|
||||
/**
|
||||
* Same as {@link data}. [DOM spec](https://dom.spec.whatwg.org)-compatible alias.
|
||||
*/
|
||||
nodeValue: string;
|
||||
/**
|
||||
* Comment source code location info. Available if location info is enabled via ParserOptions.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
declare const treeAdapter: parse5.TreeAdapter;
|
||||
export default treeAdapter;
|
||||
@@ -0,0 +1,70 @@
|
||||
import { parse } from "parse5";
|
||||
import treeAdapter, {
|
||||
Node,
|
||||
ParentNode,
|
||||
Document,
|
||||
DocumentType,
|
||||
Element,
|
||||
TextNode,
|
||||
CommentNode
|
||||
} from "parse5-htmlparser2-tree-adapter";
|
||||
|
||||
// htmlparser2 AST
|
||||
const htmlparser2Document = parse("<html>", {
|
||||
treeAdapter
|
||||
}) as Document;
|
||||
|
||||
htmlparser2Document; // $ExpectType Document
|
||||
htmlparser2Document.name; // $ExpectType "root"
|
||||
htmlparser2Document.type; // $ExpectType "root"
|
||||
htmlparser2Document["x-mode"]; // $ExpectType DocumentMode
|
||||
|
||||
const htmlparser2Node = htmlparser2Document as Node;
|
||||
|
||||
htmlparser2Node.next; // $ExpectType Node
|
||||
htmlparser2Node.nextSibling; // $ExpectType Node
|
||||
htmlparser2Node.nodeType; // $ExpectType number
|
||||
htmlparser2Node.parent; // $ExpectType ParentNode
|
||||
htmlparser2Node.parentNode; // $ExpectType ParentNode
|
||||
htmlparser2Node.prev; // $ExpectType Node
|
||||
htmlparser2Node.previousSibling; // $ExpectType Node
|
||||
htmlparser2Node.type; // $ExpectType string
|
||||
|
||||
const htmlparser2ParentNode = htmlparser2Document as ParentNode;
|
||||
|
||||
htmlparser2ParentNode; // $ExpectType ParentNode
|
||||
htmlparser2ParentNode.childNodes[0]; // $ExpectType Node
|
||||
htmlparser2ParentNode.children[0]; // $ExpectType Node
|
||||
htmlparser2ParentNode.firstChild; // $ExpectType Node
|
||||
htmlparser2ParentNode.lastChild; // $ExpectType Node
|
||||
|
||||
const htmlparser2Doctype = htmlparser2Document.childNodes[0] as DocumentType;
|
||||
|
||||
htmlparser2Doctype; // $ExpectType DocumentType
|
||||
htmlparser2Doctype.data; // $ExpectType string
|
||||
htmlparser2Doctype.name; // $ExpectType "!doctype"
|
||||
htmlparser2Doctype["x-name"]; // $ExpectType string
|
||||
htmlparser2Doctype["x-publicId"]; // $ExpectType string
|
||||
htmlparser2Doctype["x-systemId"]; // $ExpectType string
|
||||
|
||||
const htmlparser2Element = htmlparser2Document.childNodes[0] as Element;
|
||||
|
||||
htmlparser2Element; // $ExpectType Element
|
||||
htmlparser2Element.attribs["someAttr"]; // $ExpectType string
|
||||
htmlparser2Element["x-attribsNamespace"]["someAttr"]; // $ExpectType string
|
||||
htmlparser2Element["x-attribsPrefix"]["someAttr"]; // $ExpectType string
|
||||
htmlparser2Element.namespace; // $ExpectType string
|
||||
htmlparser2Element.tagName; // $ExpectType string
|
||||
htmlparser2Element.sourceCodeLocation!; // $ExpectType ElementLocation
|
||||
|
||||
const htmlparser2TextNode = htmlparser2Document.childNodes[0] as TextNode;
|
||||
|
||||
htmlparser2TextNode.data; // $ExpectType string
|
||||
htmlparser2TextNode.nodeValue; // $ExpectType string
|
||||
htmlparser2TextNode.sourceCodeLocation!; // $ExpectType Location
|
||||
|
||||
const htmlparser2CommentNode = htmlparser2Document.childNodes[0] as CommentNode;
|
||||
|
||||
htmlparser2CommentNode.data; // $ExpectType string
|
||||
htmlparser2CommentNode.nodeValue; // $ExpectType string
|
||||
htmlparser2CommentNode.sourceCodeLocation!; // $ExpectType Location
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-htmlparser2-tree-adapter-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
// Type definitions for parse5-parser-stream 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as stream from "stream";
|
||||
import * as parse5 from "parse5";
|
||||
|
||||
/**
|
||||
* Streaming HTML parser with scripting support.
|
||||
* A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
|
||||
*
|
||||
* ** NOTE:** This API is available only for Node.js.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
* const http = require('http');
|
||||
*
|
||||
* // Fetch the page content and obtain it's <head> node
|
||||
* http.get('http://inikulin.github.io/parse5/', res => {
|
||||
* const parser = new parse5.ParserStream();
|
||||
*
|
||||
* parser.once('finish', () => {
|
||||
* console.log(parser.document.childNodes[1].childNodes[0].tagName); //> 'head'
|
||||
* });
|
||||
*
|
||||
* res.pipe(parser);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export default class ParserStream<TDocument> extends stream.Writable {
|
||||
/**
|
||||
* @param options - Parsing options.
|
||||
*/
|
||||
constructor(options?: parse5.ParserOptions);
|
||||
|
||||
/**
|
||||
* The resulting document node.
|
||||
*/
|
||||
document: TDocument;
|
||||
|
||||
/**
|
||||
* Raised when parser encounters a `<script>` element.
|
||||
* If this event has listeners, parsing will be suspended once it is emitted.
|
||||
* So, if `<script>` has the `src` attribute, you can fetch it, execute and then resume parsing just like browsers do.
|
||||
*
|
||||
* @param listener.scriptElement - The script element that caused the event.
|
||||
* @param listener.documentWrite - Write additional `html` at the current parsing position. Suitable for implementing the DOM `document.write` and `document.writeln` methods.
|
||||
* @param listener.documentWrite.html - HTML to write.
|
||||
* @param listener.resume - Resumes parsing.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse = require('parse5');
|
||||
* const http = require('http');
|
||||
*
|
||||
* const parser = new parse5.ParserStream();
|
||||
*
|
||||
* parser.on('script', (scriptElement, documentWrite, resume) => {
|
||||
* const src = parse5.treeAdapters.default.getAttrList(scriptElement)[0].value;
|
||||
*
|
||||
* http.get(src, res => {
|
||||
* // Fetch the script content, execute it with DOM built around `parser.document` and
|
||||
* // `document.write` implemented using `documentWrite`.
|
||||
* ...
|
||||
* // Then resume parsing.
|
||||
* resume();
|
||||
* });
|
||||
* });
|
||||
*
|
||||
* parser.end('<script src="example.com/script.js"></script>');
|
||||
* ```
|
||||
*/
|
||||
on(
|
||||
event: "script",
|
||||
listener: (
|
||||
scriptElement: parse5.Element,
|
||||
documentWrite: (html: string) => void,
|
||||
resume: () => void
|
||||
) => void
|
||||
): this;
|
||||
/**
|
||||
* WritableStream events
|
||||
*/
|
||||
on(event: string, listener: (...params: any[]) => any): this;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import * as parse5 from "parse5";
|
||||
import ParserStream from "parse5-parser-stream";
|
||||
import { createReadStream } from "fs";
|
||||
|
||||
const defaultAdapter = new Object() as parse5.TreeAdapter;
|
||||
let parser = new ParserStream<parse5.DefaultTreeDocument>();
|
||||
|
||||
parser = new ParserStream<parse5.DefaultTreeDocument>({ sourceCodeLocationInfo: true });
|
||||
parser = new ParserStream<parse5.DefaultTreeDocument>({ treeAdapter: defaultAdapter });
|
||||
parser = new ParserStream<parse5.DefaultTreeDocument>({
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
parser = new ParserStream<parse5.DefaultTreeDocument>({
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
|
||||
parser.document; // $ExpectType DefaultTreeDocument
|
||||
|
||||
parser
|
||||
.on(
|
||||
"script",
|
||||
(
|
||||
element: parse5.Element,
|
||||
documentWrite: (html: string) => void,
|
||||
resume: () => {}
|
||||
) => {}
|
||||
)
|
||||
.on("finish", () => {});
|
||||
|
||||
createReadStream("file").pipe(parser);
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-parser-stream-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,33 @@
|
||||
// Type definitions for parse5-plain-text-conversion-stream 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
import ParserStream from "parse5-parser-stream";
|
||||
|
||||
/**
|
||||
* Converts plain text files into HTML document as required by [HTML specification](https://html.spec.whatwg.org/#read-text).
|
||||
* A [writable stream](https://nodejs.org/api/stream.html#stream_class_stream_writable).
|
||||
*
|
||||
* ** NOTE:** This API is available only for Node.js.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
* const fs = require('fs');
|
||||
*
|
||||
* const file = fs.createReadStream('war_and_peace.txt');
|
||||
* const converter = new parse5.PlainTextConversionStream();
|
||||
*
|
||||
* converter.once('finish', () => {
|
||||
* console.log(converter.document.childNodes[1].childNodes[0].tagName); //> 'head'
|
||||
* });
|
||||
*
|
||||
* file.pipe(converter);
|
||||
* ```
|
||||
*/
|
||||
export default class PlainTextConversionStream<TDocument> extends ParserStream<
|
||||
TDocument
|
||||
> {}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
import * as parse5 from "parse5";
|
||||
import PlainTextConversionStream from "parse5-plain-text-conversion-stream";
|
||||
import { createReadStream } from "fs";
|
||||
|
||||
const defaultAdapter = new Object() as parse5.TreeAdapter;
|
||||
let converter = new PlainTextConversionStream<parse5.DefaultTreeDocument>();
|
||||
|
||||
converter = new PlainTextConversionStream<parse5.DefaultTreeDocument>({
|
||||
sourceCodeLocationInfo: true
|
||||
});
|
||||
converter = new PlainTextConversionStream<parse5.DefaultTreeDocument>({
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
converter = new PlainTextConversionStream<parse5.DefaultTreeDocument>({
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
converter = new PlainTextConversionStream<parse5.DefaultTreeDocument>({
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
|
||||
converter.document; // $ExpectType DefaultTreeDocument
|
||||
|
||||
converter.on("finish", () => {});
|
||||
|
||||
createReadStream("file").pipe(converter);
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-plain-text-conversion-stream-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+192
@@ -0,0 +1,192 @@
|
||||
// Type definitions for parse5-sax-parser 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as stream from "stream";
|
||||
import * as parse5 from "parse5";
|
||||
|
||||
export interface StartTagToken {
|
||||
/**
|
||||
* Tag name.
|
||||
*/
|
||||
tagName: string;
|
||||
/**
|
||||
* List of attributes.
|
||||
*/
|
||||
attrs: parse5.Attribute[];
|
||||
/**
|
||||
* Indicates if the tag is self-closing.
|
||||
*/
|
||||
selfClosing: boolean;
|
||||
/**
|
||||
* Start tag source code location info. Available if location info is enabled via {@link SAXParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.StartTagLocation;
|
||||
}
|
||||
|
||||
export interface EndTagToken {
|
||||
/**
|
||||
* Tag name.
|
||||
*/
|
||||
tagName: string;
|
||||
/**
|
||||
* End tag source code location info. Available if location info is enabled via {@link SAXParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
export interface CommentToken {
|
||||
/**
|
||||
* Comment text.
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Comment source code location info. Available if location info is enabled via {@link SAXParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
export interface TextToken {
|
||||
/**
|
||||
* Text content.
|
||||
*/
|
||||
text: string;
|
||||
/**
|
||||
* Text content source code location info. Available if location info is enabled via {@link SAXParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
export interface DoctypeToken {
|
||||
/**
|
||||
* Document type name.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Document type public identifier.
|
||||
*/
|
||||
publicId: string;
|
||||
/**
|
||||
* Document type system identifier.
|
||||
*/
|
||||
systemId: string;
|
||||
/**
|
||||
* Document type declaration source code location info. Available if location info is enabled via {@link SAXParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: parse5.Location;
|
||||
}
|
||||
|
||||
export interface SAXParserOptions {
|
||||
/**
|
||||
* Enables source code location information for the tokens.
|
||||
* When enabled, each token event handler will receive {@link Location} (or {@link StartTagLocation})
|
||||
* object as its last argument.
|
||||
*/
|
||||
sourceCodeLocationInfo?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Streaming [SAX](https://en.wikipedia.org/wiki/Simple_API_for_XML)-style HTML parser.
|
||||
* A [transform stream](https://nodejs.org/api/stream.html#stream_class_stream_transform)
|
||||
* (which means you can pipe *through* it, see example).
|
||||
*
|
||||
* ** NOTE:** This API is available only for Node.js.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
* const http = require('http');
|
||||
* const fs = require('fs');
|
||||
*
|
||||
* const file = fs.createWriteStream('/home/google.com.html');
|
||||
* const parser = new parse5.SAXParser();
|
||||
*
|
||||
* parser.on('text', text => {
|
||||
* // Handle page text content
|
||||
* ...
|
||||
* });
|
||||
*
|
||||
* http.get('http://google.com', res => {
|
||||
* // SAXParser is the Transform stream, which means you can pipe
|
||||
* // through it. So, you can analyze page content and, e.g., save it
|
||||
* // to the file at the same time:
|
||||
* res.pipe(parser).pipe(file);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export default class SAXParser extends stream.Transform {
|
||||
/**
|
||||
* @param options - Parsing options.
|
||||
*/
|
||||
constructor(options?: SAXParserOptions);
|
||||
|
||||
/**
|
||||
* Raised when the parser encounters a start tag.
|
||||
*
|
||||
* @param listener.startTag - Start tag token.
|
||||
*/
|
||||
on(event: "startTag", listener: (startTag: StartTagToken) => void): this;
|
||||
|
||||
/**
|
||||
* Raised when parser encounters an end tag.
|
||||
*
|
||||
* @param listener.endTag - End tag token.
|
||||
*/
|
||||
on(event: "endTag", listener: (endTag: EndTagToken) => void): this;
|
||||
/**
|
||||
* Raised when parser encounters text content.
|
||||
*
|
||||
* @param listener.text - Text token.
|
||||
*/
|
||||
on(event: "text", listener: (text: TextToken) => void): this;
|
||||
/**
|
||||
* Raised when parser encounters a comment.
|
||||
*
|
||||
* @param listener.comment - Comment content.
|
||||
*/
|
||||
on(event: "comment", listener: (comment: CommentToken) => void): this;
|
||||
/**
|
||||
* Raised when parser encounters a [document type declaration](https://en.wikipedia.org/wiki/Document_type_declaration).
|
||||
*
|
||||
* @param listener.doctype - Document type token.
|
||||
*/
|
||||
on(event: "doctype", listener: (doctype: DoctypeToken) => void): this;
|
||||
/**
|
||||
* TransformStream events
|
||||
*/
|
||||
on(event: string, listener: (...params: any[]) => any): this;
|
||||
|
||||
/**
|
||||
* Stops parsing. Useful if you want the parser to stop consuming CPU time once you've obtained the desired info
|
||||
* from the input stream. Doesn't prevent piping, so that data will flow through the parser as usual.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
* const http = require('http');
|
||||
* const fs = require('fs');
|
||||
*
|
||||
* const file = fs.createWriteStream('google.com.html');
|
||||
* const parser = new parse5.SAXParser();
|
||||
*
|
||||
* parser.on('doctype', (name, publicId, systemId) => {
|
||||
* // Process doctype info ans stop parsing
|
||||
* ...
|
||||
* parser.stop();
|
||||
* });
|
||||
*
|
||||
* http.get('http://google.com', res => {
|
||||
* // Despite the fact that parser.stop() was called whole
|
||||
* // content of the page will be written to the file
|
||||
* res.pipe(parser).pipe(file);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
stop(): void;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
import SAXParser, {
|
||||
StartTagToken,
|
||||
EndTagToken,
|
||||
CommentToken,
|
||||
TextToken,
|
||||
DoctypeToken
|
||||
} from "parse5-sax-parser";
|
||||
import { createReadStream, createWriteStream } from "fs";
|
||||
|
||||
let sax = new SAXParser();
|
||||
|
||||
sax = new SAXParser({ sourceCodeLocationInfo: true });
|
||||
|
||||
sax.stop();
|
||||
|
||||
sax
|
||||
.on("startTag", (startTag: StartTagToken) => {
|
||||
startTag.tagName; // $ExpectType string
|
||||
startTag.attrs; // $ExpectType Attribute[]
|
||||
startTag.selfClosing; // $ExpectType boolean
|
||||
startTag.sourceCodeLocation!; // $ExpectType StartTagLocation
|
||||
})
|
||||
.on("endTag", (endTag: EndTagToken) => {
|
||||
endTag.tagName; // $ExpectType string
|
||||
endTag.sourceCodeLocation!; // $ExpectType Location
|
||||
})
|
||||
.on("comment", (comment: CommentToken) => {
|
||||
comment.text; // $ExpectType string
|
||||
comment.sourceCodeLocation!; // $ExpectType Location
|
||||
})
|
||||
.on("text", (text: TextToken) => {
|
||||
text.text; // $ExpectType string
|
||||
text.sourceCodeLocation!; // $ExpectType Location
|
||||
})
|
||||
.on("doctype", (doctype: DoctypeToken) => {
|
||||
doctype.name; // $ExpectType string
|
||||
doctype.publicId; // $ExpectType string
|
||||
doctype.systemId; // $ExpectType string
|
||||
doctype.sourceCodeLocation!; // $ExpectType Location
|
||||
})
|
||||
.on("finish", () => {});
|
||||
|
||||
createReadStream("file1")
|
||||
.pipe(sax)
|
||||
.pipe(createWriteStream("file2"));
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-sax-parser-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
// Type definitions for parse5-serializer-stream 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as stream from "stream";
|
||||
import * as parse5 from "parse5";
|
||||
|
||||
/**
|
||||
* Streaming AST node to an HTML serializer.
|
||||
* A [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
|
||||
*
|
||||
* ** NOTE:** This API is available only for Node.js.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
* const fs = require('fs');
|
||||
*
|
||||
* const file = fs.createWriteStream('/home/index.html');
|
||||
*
|
||||
* // Serializes the parsed document to HTML and writes it to the file.
|
||||
* const document = parse5.parse('<body>Who is John Galt?</body>');
|
||||
* const serializer = new parse5.SerializerStream(document);
|
||||
*
|
||||
* serializer.pipe(file);
|
||||
* ```
|
||||
*/
|
||||
export default class SerializerStream extends stream.Readable {
|
||||
/**
|
||||
* Streaming AST node to an HTML serializer. A readable stream.
|
||||
*
|
||||
* @param node - Node to serialize.
|
||||
* @param options - Serialization options.
|
||||
*/
|
||||
constructor(node: parse5.Node, options?: parse5.SerializerOptions);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { parse, TreeAdapter } from "parse5";
|
||||
import SerializerStream from "parse5-serializer-stream";
|
||||
import { createReadStream, createWriteStream } from "fs";
|
||||
|
||||
const document = parse("<html>");
|
||||
const defaultAdapter = new Object() as TreeAdapter;
|
||||
let serializer = new SerializerStream(document);
|
||||
|
||||
serializer = new SerializerStream(document, {
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
serializer = new SerializerStream(document, {
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
|
||||
serializer.pipe(createWriteStream("file"));
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-serializer-stream-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+601
@@ -0,0 +1,601 @@
|
||||
// Type definitions for parse5 5.0
|
||||
// Project: https://github.com/inikulin/parse5
|
||||
// Definitions by: Ivan Nikulin <https://github.com/inikulin>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
export interface Location {
|
||||
/**
|
||||
* One-based line index of the first character
|
||||
*/
|
||||
startLine: number;
|
||||
/**
|
||||
* One-based column index of the first character
|
||||
*/
|
||||
startCol: number;
|
||||
/**
|
||||
* One-based line index of the last character
|
||||
*/
|
||||
endLine: number;
|
||||
/**
|
||||
* One-based column index of the last character
|
||||
*/
|
||||
endCol: number;
|
||||
/**
|
||||
* Zero-based first character index
|
||||
*/
|
||||
startOffset: number;
|
||||
/**
|
||||
* Zero-based last character index
|
||||
*/
|
||||
endOffset: number;
|
||||
}
|
||||
|
||||
export interface AttributesLocation {
|
||||
[attributeName: string]: Location;
|
||||
}
|
||||
|
||||
export interface StartTagLocation extends Location {
|
||||
/**
|
||||
* Start tag attributes' location info
|
||||
*/
|
||||
attrs: AttributesLocation;
|
||||
}
|
||||
|
||||
export interface ElementLocation extends StartTagLocation {
|
||||
/**
|
||||
* Element's start tag location info.
|
||||
*/
|
||||
startTag: StartTagLocation;
|
||||
/**
|
||||
* Element's end tag location info.
|
||||
*/
|
||||
endTag: Location;
|
||||
}
|
||||
|
||||
export interface ParserOptions {
|
||||
/**
|
||||
* The [scripting flag](https://html.spec.whatwg.org/multipage/parsing.html#scripting-flag). If set
|
||||
* to `true`, `noscript` element content will be parsed as text.
|
||||
*
|
||||
* **Default:** `true`
|
||||
*/
|
||||
scriptingEnabled?: boolean;
|
||||
/**
|
||||
* Enables source code location information. When enabled, each node (except the root node)
|
||||
* will have a `sourceCodeLocation` property. If the node is not an empty element, `sourceCodeLocation` will
|
||||
* be a {@link ElementLocation} object, otherwise it will be {@link Location}.
|
||||
* If the element was implicitly created by the parser (as part of
|
||||
* [tree correction](https://html.spec.whatwg.org/multipage/syntax.html#an-introduction-to-error-handling-and-strange-cases-in-the-parser)),
|
||||
* its `sourceCodeLocation` property will be `undefined`.
|
||||
*
|
||||
* **Default:** `false`
|
||||
*/
|
||||
sourceCodeLocationInfo?: boolean;
|
||||
/**
|
||||
* Specifies the resulting tree format.
|
||||
*
|
||||
* **Default:** `treeAdapters.default`
|
||||
*/
|
||||
treeAdapter?: TreeAdapter;
|
||||
}
|
||||
|
||||
export interface SerializerOptions {
|
||||
/***
|
||||
* Specifies input tree format.
|
||||
*
|
||||
* **Default:** `treeAdapters.default`
|
||||
*/
|
||||
treeAdapter?: TreeAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks).
|
||||
*/
|
||||
export type DocumentMode = "no-quirks" | "quirks" | "limited-quirks";
|
||||
|
||||
// Default tree adapter
|
||||
|
||||
/**
|
||||
* Element attribute.
|
||||
*/
|
||||
export interface Attribute {
|
||||
/**
|
||||
* The name of the attribute.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The value of the attribute.
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* The namespace of the attribute.
|
||||
*/
|
||||
namespace?: string;
|
||||
/**
|
||||
* The namespace-related prefix of the attribute.
|
||||
*/
|
||||
prefix?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter Node interface.
|
||||
*/
|
||||
export interface DefaultTreeNode {
|
||||
/**
|
||||
* The name of the node. E.g. {@link Document} will have `nodeName` equal to '#document'`.
|
||||
*/
|
||||
nodeName: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter ParentNode interface.
|
||||
*/
|
||||
export interface DefaultTreeParentNode {
|
||||
/**
|
||||
* Child nodes.
|
||||
*/
|
||||
childNodes: DefaultTreeNode[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter DocumentType interface.
|
||||
*/
|
||||
export interface DefaultTreeDocumentType extends DefaultTreeNode {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
nodeName: "#documentType";
|
||||
/**
|
||||
* Document type name.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* Document type public identifier.
|
||||
*/
|
||||
publicId: string;
|
||||
/**
|
||||
* Document type system identifier.
|
||||
*/
|
||||
systemId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter Document interface.
|
||||
*/
|
||||
export interface DefaultTreeDocument extends DefaultTreeParentNode {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
nodeName: "#document";
|
||||
/**
|
||||
* [Document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks).
|
||||
*/
|
||||
mode: DocumentMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter DocumentFragment interface.
|
||||
*/
|
||||
export interface DefaultTreeDocumentFragment extends DefaultTreeParentNode {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
nodeName: "#document-fragment";
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter Element interface.
|
||||
*/
|
||||
export interface DefaultTreeElement extends DefaultTreeParentNode {
|
||||
/**
|
||||
* The name of the node. Equals to element {@link tagName}.
|
||||
*/
|
||||
nodeName: string;
|
||||
/**
|
||||
* Element tag name.
|
||||
*/
|
||||
tagName: string;
|
||||
/**
|
||||
* Element namespace.
|
||||
*/
|
||||
namespaceURI: string;
|
||||
/**
|
||||
* List of element attributes.
|
||||
*/
|
||||
attrs: Attribute[];
|
||||
/**
|
||||
* Parent node.
|
||||
*/
|
||||
parentNode: DefaultTreeParentNode;
|
||||
/**
|
||||
* Element source code location info. Available if location info is enabled via {@link ParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: ElementLocation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter CommentNode interface.
|
||||
*/
|
||||
export interface DefaultTreeCommentNode extends DefaultTreeNode {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
nodeName: "#comment";
|
||||
/**
|
||||
* Comment text.
|
||||
*/
|
||||
data: string;
|
||||
/**
|
||||
* Parent node.
|
||||
*/
|
||||
parentNode: DefaultTreeParentNode;
|
||||
/**
|
||||
* Comment source code location info. Available if location info is enabled via {@link ParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: Location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default tree adapter TextNode interface.
|
||||
*/
|
||||
export interface DefaultTreeTextNode extends DefaultTreeNode {
|
||||
/**
|
||||
* The name of the node.
|
||||
*/
|
||||
nodeName: "#text";
|
||||
/**
|
||||
* Text content.
|
||||
*/
|
||||
value: string;
|
||||
/**
|
||||
* Parent node.
|
||||
*/
|
||||
parentNode: DefaultTreeParentNode;
|
||||
/**
|
||||
* Text node source code location info. Available if location info is enabled via {@link ParserOptions}.
|
||||
*/
|
||||
sourceCodeLocation?: Location;
|
||||
}
|
||||
|
||||
// Generic node intefaces
|
||||
/**
|
||||
* Generic Node interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeNode}) to get access to the properties.
|
||||
*/
|
||||
export type Node = DefaultTreeNode | object;
|
||||
/**
|
||||
* Generic ParentNode interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeParentNode}) to get access to the properties.
|
||||
*/
|
||||
export type ParentNode = DefaultTreeParentNode | object;
|
||||
/**
|
||||
* Generic DocumentType interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocumentType}) to get access to the properties.
|
||||
*/
|
||||
export type DocumentType = DefaultTreeDocumentType | object;
|
||||
/**
|
||||
* Generic Document interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocument}) to get access to the properties.
|
||||
*/
|
||||
export type Document = DefaultTreeDocument | object;
|
||||
/**
|
||||
* Generic DocumentFragment interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeDocumentFragment}) to get access to the properties.
|
||||
*/
|
||||
export type DocumentFragment = DefaultTreeDocumentFragment | object;
|
||||
/**
|
||||
* Generic Element interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeElement}) to get access to the properties.
|
||||
*/
|
||||
export type Element = DefaultTreeElement | object;
|
||||
/**
|
||||
* Generic TextNode interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.DefaultTreeTextNode}) to get access to the properties.
|
||||
*/
|
||||
export type TextNode = DefaultTreeTextNode | object;
|
||||
/**
|
||||
* Generic CommentNode interface.
|
||||
* Cast to the actual AST interface (e.g. {@link parse5.Default.CommentNode}) to get access to the properties.
|
||||
*/
|
||||
export type CommentNode = DefaultTreeCommentNode | object;
|
||||
|
||||
/**
|
||||
* Tree adapter is a set of utility functions that provides minimal required abstraction layer beetween parser and a specific AST format.
|
||||
* Note that `TreeAdapter` is not designed to be a general purpose AST manipulation library. You can build such library
|
||||
* on top of existing `TreeAdapter` or use one of the existing libraries from npm.
|
||||
*
|
||||
* @see [default implementation](https://github.com/inikulin/parse5/blob/master/lib/tree_adapters/default.js)
|
||||
*/
|
||||
export interface TreeAdapter {
|
||||
/**
|
||||
* Creates a document node.
|
||||
*/
|
||||
createDocument(): Document;
|
||||
/**
|
||||
* Creates a document fragment node.
|
||||
*/
|
||||
createDocumentFragment(): DocumentFragment;
|
||||
/**
|
||||
* Creates an element node.
|
||||
*
|
||||
* @param tagName - Tag name of the element.
|
||||
* @param namespaceURI - Namespace of the element.
|
||||
* @param attrs - Attribute name-value pair array. Foreign attributes may contain `namespace` and `prefix` fields as well.
|
||||
*/
|
||||
createElement(
|
||||
tagName: string,
|
||||
namespaceURI: string,
|
||||
attrs: Attribute[]
|
||||
): Element;
|
||||
/**
|
||||
* Creates a comment node.
|
||||
*
|
||||
* @param data - Comment text.
|
||||
*/
|
||||
createCommentNode(data: string): CommentNode;
|
||||
/**
|
||||
* Appends a child node to the given parent node.
|
||||
*
|
||||
* @param parentNode - Parent node.
|
||||
* @param newNode - Child node.
|
||||
*/
|
||||
appendChild(parentNode: ParentNode, newNode: Node): void;
|
||||
/**
|
||||
* Inserts a child node to the given parent node before the given reference node.
|
||||
*
|
||||
* @param parentNode - Parent node.
|
||||
* @param newNode - Child node.
|
||||
* @param referenceNode - Reference node.
|
||||
*/
|
||||
insertBefore(
|
||||
parentNode: ParentNode,
|
||||
newNode: Node,
|
||||
referenceNode: Node
|
||||
): void;
|
||||
/**
|
||||
* Sets the `<template>` element content element.
|
||||
*
|
||||
* @param templateElement - `<template>` element.
|
||||
* @param contentElement - Content element.
|
||||
*/
|
||||
setTemplateContent(
|
||||
templateElement: Element,
|
||||
contentElement: DocumentFragment
|
||||
): void;
|
||||
/**
|
||||
* Returns the `<template>` element content element.
|
||||
*
|
||||
* @param templateElement - `<template>` element.
|
||||
*/
|
||||
getTemplateContent(templateElement: Element): DocumentFragment;
|
||||
/**
|
||||
* Sets the document type. If the `document` already contains a document type node, the `name`, `publicId` and `systemId`
|
||||
* properties of this node will be updated with the provided values. Otherwise, creates a new document type node
|
||||
* with the given properties and inserts it into the `document`.
|
||||
*
|
||||
* @param document - Document node.
|
||||
* @param name - Document type name.
|
||||
* @param publicId - Document type public identifier.
|
||||
* @param systemId - Document type system identifier.
|
||||
*/
|
||||
setDocumentType(
|
||||
document: Document,
|
||||
name: string,
|
||||
publicId: string,
|
||||
systemId: string
|
||||
): void;
|
||||
/**
|
||||
* Sets the [document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks).
|
||||
*
|
||||
* @param document - Document node.
|
||||
* @param mode - Document mode.
|
||||
*/
|
||||
setDocumentMode(document: Document, mode: DocumentMode): void;
|
||||
/**
|
||||
* Returns [document mode](https://dom.spec.whatwg.org/#concept-document-limited-quirks).
|
||||
*
|
||||
* @param document - Document node.
|
||||
*/
|
||||
getDocumentMode(document: Document): DocumentMode;
|
||||
/**
|
||||
* Removes a node from its parent.
|
||||
*
|
||||
* @param node - Node to remove.
|
||||
*/
|
||||
detachNode(node: Node): void;
|
||||
/**
|
||||
* Inserts text into a node. If the last child of the node is a text node, the provided text will be appended to the
|
||||
* text node content. Otherwise, inserts a new text node with the given text.
|
||||
*
|
||||
* @param parentNode - Node to insert text into.
|
||||
* @param text - Text to insert.
|
||||
*/
|
||||
insertText(parentNode: ParentNode, text: string): void;
|
||||
/**
|
||||
* Inserts text into a sibling node that goes before the reference node. If this sibling node is the text node,
|
||||
* the provided text will be appended to the text node content. Otherwise, inserts a new sibling text node with
|
||||
* the given text before the reference node.
|
||||
*
|
||||
* @param parentNode - Node to insert text into.
|
||||
* @param text - Text to insert.
|
||||
* @param referenceNode - Node to insert text before.
|
||||
*/
|
||||
insertTextBefore(
|
||||
parentNode: ParentNode,
|
||||
text: string,
|
||||
referenceNode: Node
|
||||
): void;
|
||||
/**
|
||||
* Copies attributes to the given element. Only attributes that are not yet present in the element are copied.
|
||||
*
|
||||
* @param recipient - Element to copy attributes into.
|
||||
* @param attrs - Attributes to copy.
|
||||
*/
|
||||
adoptAttributes(recipient: Element, attrs: Attribute[]): void;
|
||||
/**
|
||||
* Returns the first child of the given node.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
getFirstChild(node: ParentNode): Node;
|
||||
/**
|
||||
* Returns the given node's children in an array.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
getChildNodes(node: ParentNode): Node[];
|
||||
/**
|
||||
* Returns the given node's parent.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
getParentNode(node: Node): ParentNode;
|
||||
/**
|
||||
* Returns the given element's attributes in an array, in the form of name-value pairs.
|
||||
* Foreign attributes may contain `namespace` and `prefix` fields as well.
|
||||
*
|
||||
* @param element - Element.
|
||||
*/
|
||||
getAttrList(element: Element): Attribute[];
|
||||
/**
|
||||
* Returns the given element's tag name.
|
||||
*
|
||||
* @param element - Element.
|
||||
*/
|
||||
getTagName(element: Element): string;
|
||||
/**
|
||||
* Returns the given element's namespace.
|
||||
*
|
||||
* @param element - Element.
|
||||
*/
|
||||
getNamespaceURI(element: Element): string;
|
||||
/**
|
||||
* Returns the given text node's content.
|
||||
*
|
||||
* @param textNode - Text node.
|
||||
*/
|
||||
getTextNodeContent(textNode: TextNode): string;
|
||||
/**
|
||||
* Returns the given comment node's content.
|
||||
*
|
||||
* @param commentNode - Comment node.
|
||||
*/
|
||||
getCommentNodeContent(commentNode: CommentNode): string;
|
||||
/**
|
||||
* Returns the given document type node's name.
|
||||
*
|
||||
* @param doctypeNode - Document type node.
|
||||
*/
|
||||
getDocumentTypeNodeName(doctypeNode: DocumentType): string;
|
||||
/**
|
||||
* Returns the given document type node's public identifier.
|
||||
*
|
||||
* @param doctypeNode - Document type node.
|
||||
*/
|
||||
getDocumentTypeNodePublicId(doctypeNode: DocumentType): string;
|
||||
/**
|
||||
* Returns the given document type node's system identifier.
|
||||
*
|
||||
* @param doctypeNode - Document type node.
|
||||
*/
|
||||
getDocumentTypeNodeSystemId(doctypeNode: DocumentType): string;
|
||||
/**
|
||||
* Determines if the given node is a text node.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
isTextNode(node: Node): boolean;
|
||||
/**
|
||||
* Determines if the given node is a comment node.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
isCommentNode(node: Node): boolean;
|
||||
/**
|
||||
* Determines if the given node is a document type node.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
isDocumentTypeNode(node: Node): boolean;
|
||||
/**
|
||||
* Determines if the given node is an element.
|
||||
*
|
||||
* @param node - Node.
|
||||
*/
|
||||
isElementNode(node: Node): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an HTML string.
|
||||
*
|
||||
* @param html - Input HTML string.
|
||||
* @param options - Parsing options.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
*
|
||||
* const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
|
||||
*
|
||||
* console.log(document.childNodes[1].tagName); //> 'html'
|
||||
* ```
|
||||
*/
|
||||
export function parse(html: string, options?: ParserOptions): Document;
|
||||
|
||||
/**
|
||||
* Parses an HTML fragment.
|
||||
*
|
||||
* @param fragmentContext - Parsing context element. If specified, given fragment will be parsed as if it was set to the context element's `innerHTML` property.
|
||||
* @param html - Input HTML fragment string.
|
||||
* @param options - Parsing options.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
*
|
||||
* const documentFragment = parse5.parseFragment('<table></table>');
|
||||
*
|
||||
* console.log(documentFragment.childNodes[0].tagName); //> 'table'
|
||||
*
|
||||
* // Parses the html fragment in the context of the parsed <table> element.
|
||||
* const trFragment = parser.parseFragment(documentFragment.childNodes[0], '<tr><td>Shake it, baby</td></tr>');
|
||||
*
|
||||
* console.log(trFragment.childNodes[0].childNodes[0].tagName); //> 'td'
|
||||
* ```
|
||||
*/
|
||||
export function parseFragment(
|
||||
fragmentContext: Element,
|
||||
html: string,
|
||||
options?: ParserOptions
|
||||
): DocumentFragment;
|
||||
export function parseFragment(
|
||||
html: string,
|
||||
options?: ParserOptions
|
||||
): DocumentFragment;
|
||||
|
||||
/**
|
||||
* Serializes an AST node to an HTML string.
|
||||
*
|
||||
* @param node - Node to serialize.
|
||||
* @param options - Serialization options.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
*
|
||||
* const parse5 = require('parse5');
|
||||
*
|
||||
* const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');
|
||||
*
|
||||
* // Serializes a document.
|
||||
* const html = parse5.serialize(document);
|
||||
*
|
||||
* // Serializes the <html> element content.
|
||||
* const str = parse5.serialize(document.childNodes[1]);
|
||||
*
|
||||
* console.log(str); //> '<head></head><body>Hi there!</body>'
|
||||
* ```
|
||||
*/
|
||||
export function serialize(node: Node, options?: SerializerOptions): string;
|
||||
@@ -0,0 +1,191 @@
|
||||
import * as parse5 from "parse5";
|
||||
|
||||
// Shorthands
|
||||
// parse
|
||||
const document = parse5.parse("<html>");
|
||||
|
||||
document; // $ExpectType Document
|
||||
|
||||
const defaultAdapter = new Object() as parse5.TreeAdapter;
|
||||
|
||||
parse5.parse("<html>", {}); // $ExpectType Document
|
||||
parse5.parse("<html>", { sourceCodeLocationInfo: true }); // $ExpectType Document
|
||||
parse5.parse("<html>", { treeAdapter: defaultAdapter }); // $ExpectType Document
|
||||
|
||||
let opt = {
|
||||
sourceCodeLocationInfo: true,
|
||||
scriptingEnabled: false,
|
||||
treeAdapter: defaultAdapter
|
||||
};
|
||||
|
||||
parse5.parse("<html>", opt); // $ExpectType Document
|
||||
|
||||
opt = {
|
||||
sourceCodeLocationInfo: true,
|
||||
scriptingEnabled: false,
|
||||
treeAdapter: defaultAdapter
|
||||
};
|
||||
|
||||
parse5.parse("<html>", opt); // $ExpectType Document
|
||||
|
||||
// parseFragment
|
||||
const fragment = parse5.parseFragment("<div>");
|
||||
|
||||
fragment; // $ExpectType DocumentFragment
|
||||
|
||||
parse5.parseFragment("<div>", {});
|
||||
parse5.parseFragment("<div>", { sourceCodeLocationInfo: true });
|
||||
parse5.parseFragment("<div>", { treeAdapter: defaultAdapter });
|
||||
parse5.parseFragment("<div>", {
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
parse5.parseFragment("<div>", {
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
|
||||
const element = (parse5.parseFragment(
|
||||
"<div>"
|
||||
) as parse5.DefaultTreeDocumentFragment).childNodes[0] as parse5.Element;
|
||||
|
||||
parse5.parseFragment(element, "<div>");
|
||||
parse5.parseFragment(element, "<div>", {});
|
||||
parse5.parseFragment(element, "<div>", { sourceCodeLocationInfo: true });
|
||||
parse5.parseFragment(element, "<div>", {
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
parse5.parseFragment(element, "<div>", {
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
parse5.parseFragment(element, "<div>", {
|
||||
sourceCodeLocationInfo: true,
|
||||
treeAdapter: defaultAdapter
|
||||
});
|
||||
|
||||
// serialize
|
||||
const html = parse5.serialize(element);
|
||||
|
||||
html; // $ExpectType string
|
||||
|
||||
parse5.serialize(element, { treeAdapter: defaultAdapter });
|
||||
parse5.serialize(element, { treeAdapter: defaultAdapter });
|
||||
|
||||
// Location info
|
||||
const loc = (element as parse5.DefaultTreeElement).sourceCodeLocation!;
|
||||
|
||||
loc.startLine; // $ExpectType number
|
||||
loc.startCol; // $ExpectType number
|
||||
loc.endLine; // $ExpectType number
|
||||
loc.endCol; // $ExpectType number
|
||||
loc.startOffset; // $ExpectType number
|
||||
loc.endOffset; // $ExpectType number
|
||||
|
||||
loc.startTag.startLine; // $ExpectType number
|
||||
loc.startTag.startCol; // $ExpectType number
|
||||
loc.startTag.endLine; // $ExpectType number
|
||||
loc.startTag.endCol; // $ExpectType number
|
||||
loc.startTag.startOffset; // $ExpectType number
|
||||
loc.startTag.endOffset; // $ExpectType number
|
||||
|
||||
loc.startTag.attrs["someAttr"].startLine; // $ExpectType number
|
||||
loc.startTag.attrs["someAttr"].startCol; // $ExpectType number
|
||||
loc.startTag.attrs["someAttr"].endLine; // $ExpectType number
|
||||
loc.startTag.attrs["someAttr"].endCol; // $ExpectType number
|
||||
loc.startTag.attrs["someAttr"].startOffset; // $ExpectType number
|
||||
loc.startTag.attrs["someAttr"].endOffset; // $ExpectType number
|
||||
|
||||
loc.endTag.startLine; // $ExpectType number
|
||||
loc.endTag.startCol; // $ExpectType number
|
||||
loc.endTag.endLine; // $ExpectType number
|
||||
loc.endTag.endCol; // $ExpectType number
|
||||
loc.endTag.startOffset; // $ExpectType number
|
||||
loc.endTag.endOffset; // $ExpectType number
|
||||
|
||||
// Default AST
|
||||
const defaultDocument = document as parse5.DefaultTreeDocument;
|
||||
|
||||
defaultDocument.nodeName; // $ExpectType "#document"
|
||||
defaultDocument.mode; // $ExpectType DocumentMode
|
||||
|
||||
const defaultDoctype = document as parse5.DefaultTreeDocumentType;
|
||||
|
||||
defaultDoctype.name; // $ExpectType string
|
||||
defaultDoctype.publicId; // $ExpectType string
|
||||
defaultDoctype.systemId; // $ExpectType string
|
||||
|
||||
const defaultDocumentFragment = fragment as parse5.DefaultTreeDocumentFragment;
|
||||
|
||||
defaultDocumentFragment.nodeName; // $ExpectType "#document-fragment"
|
||||
|
||||
const defaultElement = defaultDocument
|
||||
.childNodes[0] as parse5.DefaultTreeElement;
|
||||
|
||||
defaultElement.sourceCodeLocation!; // $ExpectType ElementLocation
|
||||
defaultElement.namespaceURI; // $ExpectType string
|
||||
defaultElement.nodeName; // $ExpectType string
|
||||
defaultElement.tagName; // $ExpectType string
|
||||
defaultElement.parentNode; // $ExpectType DefaultTreeParentNode
|
||||
|
||||
const defaultAttr = defaultElement.attrs[0];
|
||||
|
||||
defaultAttr.name; // $ExpectType string
|
||||
defaultAttr.namespace!; // $ExpectType string
|
||||
defaultAttr.prefix!; // $ExpectType string
|
||||
defaultAttr.value; // $ExpectType string
|
||||
|
||||
const defaultTextNode = defaultDocumentFragment
|
||||
.childNodes[0] as parse5.DefaultTreeTextNode;
|
||||
|
||||
defaultTextNode.sourceCodeLocation!; // $ExpectType Location
|
||||
defaultTextNode.nodeName; // $ExpectType "#text"
|
||||
defaultTextNode.value; // $ExpectType string
|
||||
defaultTextNode.parentNode; // $ExpectType DefaultTreeParentNode
|
||||
|
||||
const defaultCommentNode = defaultDocumentFragment
|
||||
.childNodes[0] as parse5.DefaultTreeCommentNode;
|
||||
|
||||
defaultCommentNode.sourceCodeLocation!; // $ExpectType Location
|
||||
defaultCommentNode.nodeName; // $ExpectType "#comment"
|
||||
defaultCommentNode.data; // $ExpectType string
|
||||
defaultCommentNode.parentNode; // $ExpectType DefaultTreeParentNode
|
||||
|
||||
const adapter = defaultAdapter;
|
||||
|
||||
adapter.createDocument(); // $ExpectType Document
|
||||
adapter.createDocumentFragment(); // $ExpectType DocumentFragment
|
||||
adapter.createElement("div", "namespace", [{ name: "someAttr", value: "42" }]); // $ExpectType Element
|
||||
adapter.createCommentNode("foo"); // $ExpectType CommentNode
|
||||
|
||||
adapter.appendChild(document, element);
|
||||
adapter.insertBefore(document, element, element);
|
||||
adapter.setTemplateContent(element, fragment);
|
||||
|
||||
adapter.getTemplateContent(element); // $ExpectType DocumentFragment
|
||||
|
||||
adapter.setDocumentType(document, "name", "publicId", "systemId");
|
||||
adapter.setDocumentMode(document, "quirks");
|
||||
|
||||
adapter.getDocumentMode(document); // $ExpectType DocumentMode
|
||||
|
||||
adapter.detachNode(element);
|
||||
adapter.insertText(element, "text");
|
||||
adapter.insertTextBefore(document, "text", element);
|
||||
adapter.adoptAttributes(element, [{ name: "someAttr", value: "42" }]);
|
||||
|
||||
adapter.getFirstChild(element); // $ExpectType Node
|
||||
adapter.getChildNodes(element)[0]; // $ExpectType Node
|
||||
adapter.getParentNode(element); // $ExpectType ParentNode
|
||||
adapter.getAttrList(element)[0]; // $ExpectType Attribute
|
||||
adapter.getTagName(element); // $ExpectType string
|
||||
adapter.getNamespaceURI(element); // $ExpectType string
|
||||
adapter.getTextNodeContent(defaultTextNode); // $ExpectType string
|
||||
adapter.getCommentNodeContent(defaultCommentNode); // $ExpectType string
|
||||
adapter.getDocumentTypeNodeName(defaultDoctype); // $ExpectType string
|
||||
adapter.getDocumentTypeNodePublicId(defaultDoctype); // $ExpectType string
|
||||
adapter.getDocumentTypeNodeSystemId(defaultDoctype); // $ExpectType string
|
||||
adapter.isTextNode(element); // $ExpectType boolean
|
||||
adapter.isCommentNode(element); // $ExpectType boolean
|
||||
adapter.isDocumentTypeNode(element); // $ExpectType boolean
|
||||
adapter.isElementNode(element); // $ExpectType boolean
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"parse5-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Vendored
+146
@@ -0,0 +1,146 @@
|
||||
// Type definitions for @reach/router 1.0
|
||||
// Project: https://github.com/reach/router
|
||||
// Definitions by: Kingdaro <https://github.com/kingdaro>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import * as React from "react";
|
||||
|
||||
export type WindowLocation = Window["location"];
|
||||
|
||||
export interface History {
|
||||
readonly location: string;
|
||||
readonly transitioning: boolean;
|
||||
listen: (listener: HistoryListener) => HistoryUnsubscribe;
|
||||
navigate: NavigateFn;
|
||||
}
|
||||
|
||||
export type HistoryListener = () => void;
|
||||
export type HistoryUnsubscribe = () => void;
|
||||
|
||||
export class Router extends React.Component<RouterProps> {}
|
||||
|
||||
export interface RouterProps {
|
||||
basepath?: string;
|
||||
primary?: boolean;
|
||||
location?: WindowLocation;
|
||||
}
|
||||
|
||||
export type RouteComponentProps<TParams = {}> = Partial<TParams> & {
|
||||
path?: string;
|
||||
default?: boolean;
|
||||
location?: WindowLocation;
|
||||
navigate?: NavigateFn;
|
||||
uri?: string;
|
||||
};
|
||||
|
||||
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
export type AnchorProps = Omit<
|
||||
React.DetailedHTMLProps<
|
||||
React.AnchorHTMLAttributes<HTMLAnchorElement>,
|
||||
HTMLAnchorElement
|
||||
>,
|
||||
"href" // remove href, as it's ignored by the router
|
||||
>;
|
||||
|
||||
export interface LinkProps<TState> extends AnchorProps {
|
||||
to?: string;
|
||||
replace?: boolean;
|
||||
getProps?: (props: LinkGetProps) => {};
|
||||
state?: TState;
|
||||
}
|
||||
|
||||
export interface LinkGetProps {
|
||||
isCurrent: boolean;
|
||||
isPartiallyCurrent: boolean;
|
||||
href: string;
|
||||
location: WindowLocation;
|
||||
}
|
||||
|
||||
export class Link<TState> extends React.Component<LinkProps<TState>> {}
|
||||
|
||||
export interface RedirectProps {
|
||||
from?: string;
|
||||
to: string;
|
||||
noThrow?: boolean;
|
||||
}
|
||||
|
||||
export class Redirect extends React.Component<RedirectProps> {}
|
||||
|
||||
export interface MatchProps<TParams> {
|
||||
path: string;
|
||||
children: MatchRenderFn<TParams>;
|
||||
}
|
||||
|
||||
export type MatchRenderFn<TParams> = (
|
||||
props: MatchRenderProps<TParams>,
|
||||
) => React.ReactNode;
|
||||
|
||||
export interface MatchRenderProps<TParams> {
|
||||
match: null | { uri: string; path: string } & TParams;
|
||||
location: WindowLocation;
|
||||
navigate: NavigateFn;
|
||||
}
|
||||
|
||||
export class Match<TParams> extends React.Component<MatchProps<TParams>> {}
|
||||
|
||||
export type NavigateFn = (to: string, options?: NavigateOptions<{}>) => void;
|
||||
|
||||
export interface NavigateOptions<TState> {
|
||||
state?: TState;
|
||||
replace?: boolean;
|
||||
}
|
||||
|
||||
export interface LocationProps {
|
||||
children: LocationProviderRenderFn;
|
||||
}
|
||||
|
||||
export class Location extends React.Component<LocationProps> {}
|
||||
|
||||
export interface LocationProviderProps {
|
||||
history: History;
|
||||
children?: React.ReactNode | LocationProviderRenderFn;
|
||||
}
|
||||
|
||||
export type LocationProviderRenderFn = (
|
||||
context: LocationContext,
|
||||
) => React.ReactNode;
|
||||
|
||||
export interface LocationContext {
|
||||
location: WindowLocation;
|
||||
navigate: NavigateFn;
|
||||
}
|
||||
|
||||
export class LocationProvider extends React.Component<LocationProviderProps> {}
|
||||
|
||||
export interface ServerLocationProps {
|
||||
url: string;
|
||||
}
|
||||
|
||||
export class ServerLocation extends React.Component<ServerLocationProps> {}
|
||||
|
||||
export const navigate: NavigateFn;
|
||||
|
||||
export interface HistorySource {
|
||||
readonly location: WindowLocation;
|
||||
addEventListener(name: string, listener: (event: Event) => void): void;
|
||||
removeEventListener(name: string, listener: (event: Event) => void): void;
|
||||
history: {
|
||||
readonly state: any;
|
||||
pushState(state: any, title: string, uri: string): void;
|
||||
replaceState(state: any, title: string, uri: string): void;
|
||||
};
|
||||
}
|
||||
|
||||
export function createHistory(source: HistorySource): History;
|
||||
|
||||
export function createMemorySource(initialPath: string): HistorySource;
|
||||
|
||||
export interface RedirectRequest {
|
||||
uri: string;
|
||||
}
|
||||
|
||||
export function isRedirect(error: any): error is RedirectRequest;
|
||||
|
||||
export function redirectTo(uri: string): void;
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Link, Location, RouteComponentProps, Router } from "@reach/router";
|
||||
import * as React from "react";
|
||||
import { render } from "react-dom";
|
||||
|
||||
interface DashParams {
|
||||
id: string;
|
||||
}
|
||||
|
||||
const Home = (props: RouteComponentProps) => <div>Home</div>;
|
||||
|
||||
const Dash = (props: RouteComponentProps<DashParams>) => (
|
||||
<div>Dash for item ${props.id}</div>
|
||||
);
|
||||
|
||||
const NotFound = (props: RouteComponentProps) => <div>Route not found</div>;
|
||||
|
||||
render(
|
||||
<Router>
|
||||
<Home path="/" />
|
||||
<Dash path="/default/:id" />
|
||||
<NotFound default />
|
||||
|
||||
<Link to="/somepath" rel="noopener noreferrer" target="_blank" />
|
||||
|
||||
<Location>
|
||||
{(context) => (
|
||||
<>
|
||||
<div>hostname is {context.location.hostname}</div>
|
||||
<button onClick={() => context.navigate("/")}>
|
||||
Go Home
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</Location>
|
||||
</Router>,
|
||||
document.getElementById("app-root"),
|
||||
);
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["dom", "es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "react",
|
||||
"paths": {
|
||||
"@reach/router": ["reach__router"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "reach__router-tests.tsx"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
// Type definitions for react-infinite-scroll-component 4.1
|
||||
// Project: https://github.com/ankeetmaini/react-infinite-scroll-component#readme
|
||||
// Definitions by: Stephanie Roy <https://github.com/sroy3>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import * as React from 'react';
|
||||
|
||||
declare namespace InfiniteScroll {
|
||||
interface InfiniteScrollProps {
|
||||
/**
|
||||
* Set the length of the data.This will unlock the subsequent calls to next.
|
||||
*/
|
||||
dataLength: number;
|
||||
|
||||
/**
|
||||
* A function which must be called after reaching the bottom. It must trigger some sort of action which fetches the next data.
|
||||
* The data is passed as children to the InfiniteScroll component and the data should contain previous items too.
|
||||
* e.g. Initial data = [1, 2, 3] and then next load of data should be [1, 2, 3, 4, 5, 6].
|
||||
*/
|
||||
next: () => void;
|
||||
|
||||
/**
|
||||
* It tells the InfiniteScroll component on whether to call next function on reaching the bottom and shows an endMessage to the user
|
||||
*/
|
||||
hasMore: boolean;
|
||||
|
||||
/**
|
||||
* This message is shown to the user when he has seen all the records which means he's at the bottom and hasMore is false
|
||||
*/
|
||||
endMessage: React.ReactNode;
|
||||
|
||||
/**
|
||||
* You can send a loader component to show while the component waits for the next load of data. e.g. <h3>Loading...</h3> or any fancy loader element
|
||||
*/
|
||||
loader?: React.ReactNode;
|
||||
|
||||
/**
|
||||
* This function will be called, it should return the fresh data that you want to show the user
|
||||
*/
|
||||
refreshFunction?: () => void;
|
||||
|
||||
/**
|
||||
* To enable Pull Down to Refresh feature
|
||||
*/
|
||||
pullDownToRefresh?: boolean;
|
||||
|
||||
/**
|
||||
* Any JSX that you want to show the user, default={<h3>Pull down to refresh</h3>}
|
||||
*/
|
||||
pullDownToRefreshContent?: React.ReactNode;
|
||||
|
||||
/**
|
||||
* Minimum distance the user needs to pull down to trigger the refresh, default=100px
|
||||
*/
|
||||
pullDownToRefreshThreshold?: number;
|
||||
|
||||
/**
|
||||
* Any JSX that you want to show the user, default={<h3>Release to refresh</h3>}
|
||||
*/
|
||||
releaseToRefreshContent?: boolean;
|
||||
|
||||
/**
|
||||
* A threshold value after that the InfiniteScroll will call next. By default it's 0.8. It means the next will be called when the user comes below 80% of the total height.
|
||||
*/
|
||||
scrollThreshold?: number;
|
||||
|
||||
/**
|
||||
* A function that will listen to the scroll event on the scrolling container. Note that the scroll event is throttled, so you may not receive as many events as you would expect.
|
||||
*/
|
||||
onScroll?: () => void;
|
||||
|
||||
/**
|
||||
* Reference to a (parent) DOM element that is already providing overflow scrollbars to the InfiniteScroll component.
|
||||
* You should provide the id of the DOM node preferably.
|
||||
*/
|
||||
scrollableTarget?: React.ReactNode | string;
|
||||
|
||||
/**
|
||||
* Children is by default assumed to be of type array and it's length is used to determine if loader needs to be shown or not,
|
||||
* if your children is not an array, specify this prop to tell if your items are 0 or more.
|
||||
*/
|
||||
hasChildren?: boolean;
|
||||
|
||||
/**
|
||||
* Set a scroll y position for the component to render with.
|
||||
*/
|
||||
initialScrollY?: number;
|
||||
|
||||
/**
|
||||
* Set a scroll y position for the component to render with.
|
||||
*/
|
||||
style?: any;
|
||||
|
||||
/**
|
||||
* Give only if you want to have a fixed height scrolling content
|
||||
*/
|
||||
height?: number;
|
||||
}
|
||||
}
|
||||
|
||||
declare class InfiniteScroll extends React.Component<InfiniteScroll.InfiniteScrollProps, any> {}
|
||||
export = InfiniteScroll;
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as React from 'react';
|
||||
import * as InfiniteScroll from 'react-infinite-scroll-component';
|
||||
|
||||
const options: JSX.Element[] = [
|
||||
<div key='1'>1</div>,
|
||||
<div key='2'>2</div>,
|
||||
];
|
||||
|
||||
const props: InfiniteScroll.InfiniteScrollProps = {
|
||||
dataLength: 4,
|
||||
hasMore: true,
|
||||
endMessage: 'The end.',
|
||||
next: () => null,
|
||||
};
|
||||
|
||||
<InfiniteScroll {...props}>{options}</InfiniteScroll>;
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"jsx": "react",
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-infinite-scroll-component-tests.tsx"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
+36
-8
@@ -5,7 +5,14 @@
|
||||
// TypeScript Version: 2.6
|
||||
|
||||
import { Component, ComponentType, ReactNode } from 'react';
|
||||
import { StyleProp, TextProperties, TextStyle, ViewStyle, ImageStyle } from 'react-native';
|
||||
import {
|
||||
StyleProp,
|
||||
TextProperties,
|
||||
ViewProperties,
|
||||
TextStyle,
|
||||
ViewStyle,
|
||||
ImageStyle,
|
||||
} from 'react-native';
|
||||
|
||||
export interface HTMLViewNode {
|
||||
data?: string;
|
||||
@@ -43,11 +50,11 @@ export interface HTMLViewProps {
|
||||
* @param defaultRenderer the default rendering implementation, so you can use the normal rendering logic for some subtree:
|
||||
*/
|
||||
renderNode?(
|
||||
node: HTMLViewNode,
|
||||
index: number,
|
||||
siblings: HTMLViewNode,
|
||||
parent: HTMLViewNode,
|
||||
defaultRenderer: (node: HTMLViewNode, parent: HTMLViewNode) => ReactNode,
|
||||
node: HTMLViewNode,
|
||||
index: number,
|
||||
siblings: HTMLViewNode,
|
||||
parent: HTMLViewNode,
|
||||
defaultRenderer: (node: HTMLViewNode, parent: HTMLViewNode) => ReactNode
|
||||
): ReactNode;
|
||||
|
||||
/**
|
||||
@@ -71,12 +78,33 @@ export interface HTMLViewProps {
|
||||
addLineBreaks?: boolean;
|
||||
|
||||
/*
|
||||
* TODO Add futher customisization props
|
||||
* https://github.com/jsdf/react-native-htmlview#customizing-things-even-further
|
||||
* The root wrapper component
|
||||
*/
|
||||
RootComponent?: ComponentType;
|
||||
|
||||
/*
|
||||
* Properties for the RootComponent, can be used independently from RootComponent
|
||||
*/
|
||||
rootComponentProps?: ViewProperties;
|
||||
|
||||
/*
|
||||
* The component used for rendering HTML element nodes
|
||||
*/
|
||||
NodeComponent?: ComponentType;
|
||||
|
||||
/*
|
||||
* Properties for the NodeComponent, can be used independently from NodeComponent
|
||||
*/
|
||||
nodeComponentProps?: TextProperties;
|
||||
|
||||
/*
|
||||
* The component used for rendering text element nodes
|
||||
*/
|
||||
TextComponent?: ComponentType;
|
||||
|
||||
/*
|
||||
* Properties for the TextComponent, can be used independently from TextComponent
|
||||
*/
|
||||
textComponentProps?: TextProperties;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import { Text, StyleSheet } from 'react-native';
|
||||
import { View, Text, StyleSheet } from 'react-native';
|
||||
import HTMLView from 'react-native-htmlview';
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
@@ -18,23 +18,40 @@ const defaultTextProps = {
|
||||
style: {
|
||||
fontSize: 14,
|
||||
},
|
||||
allowFontScaling: false,
|
||||
};
|
||||
|
||||
const defaultNodeProps = {
|
||||
style: {
|
||||
fontFamily: 'Arial',
|
||||
},
|
||||
};
|
||||
|
||||
const defaultRootProps = {
|
||||
style: {
|
||||
padding: 10,
|
||||
},
|
||||
};
|
||||
|
||||
class Simple extends React.Component {
|
||||
onPressLink = () => {
|
||||
// Do someting
|
||||
}
|
||||
onPressLink = () => {
|
||||
// Do someting
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<HTMLView
|
||||
TextComponent={Text}
|
||||
textComponentProps={defaultTextProps}
|
||||
value="<br><b>This is html</b><div><p>Yo P</p></p>"
|
||||
addLineBreaks={false}
|
||||
stylesheet={styles}
|
||||
onLinkPress={this.onPressLink}
|
||||
/>
|
||||
);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<HTMLView
|
||||
value="<br><b>This is html</b><div><p>Yo P</p></p>"
|
||||
addLineBreaks={false}
|
||||
stylesheet={styles}
|
||||
onLinkPress={this.onPressLink}
|
||||
NodeComponent={Text}
|
||||
nodeComponentProps={defaultNodeProps}
|
||||
RootComponent={View}
|
||||
rootComponentProps={defaultRootProps}
|
||||
TextComponent={Text}
|
||||
textComponentProps={defaultTextProps}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,4 @@
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "preserve"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+70
@@ -0,0 +1,70 @@
|
||||
// Type definitions for scoped-http-client 0.11
|
||||
// Project: https://github.com/technoweenie/node-scoped-http-client
|
||||
// Definitions by: Matt Perry <https://github.com/mattvperry>
|
||||
// Ryan Adolf <https://github.com/rianadon>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node"/>
|
||||
|
||||
import { Agent, RequestOptions, IncomingMessage, ClientRequest } from "http";
|
||||
|
||||
export type ScopeCallback = (scoped: ScopedClient) => void;
|
||||
export type RequestCallback = (err: any, request: ClientRequest) => void;
|
||||
export type ResponseCallback = (cb?: (err: any, response: IncomingMessage, body: string) => void) => ScopedClient;
|
||||
|
||||
export interface Options extends RequestOptions {
|
||||
encoding?: string;
|
||||
httpAgent?: Agent|boolean;
|
||||
httpsAgent?: Agent|boolean;
|
||||
query?: any;
|
||||
pathname?: string;
|
||||
slashes?: any;
|
||||
hash?: string;
|
||||
}
|
||||
|
||||
export class ScopedClient {
|
||||
constructor(url: string, options: Options);
|
||||
fullPath(p: string): string;
|
||||
scope(options: Options, callback?: ScopeCallback): ScopedClient;
|
||||
// tslint:disable-next-line unified-signatures
|
||||
scope(url: string, callback?: ScopeCallback): ScopedClient;
|
||||
scope(url: string, options: Options, callback?: ScopeCallback): ScopedClient;
|
||||
join(suffix: string): string;
|
||||
path(p: string): ScopedClient;
|
||||
query(key: any, value?: any): ScopedClient;
|
||||
host(h: string): ScopedClient;
|
||||
port(p: string|number): ScopedClient;
|
||||
protocol(p: string): ScopedClient;
|
||||
encoding(e?: string): ScopedClient;
|
||||
timeout(time: any): ScopedClient;
|
||||
auth(user?: string, pass?: string): ScopedClient;
|
||||
header(name: string, value: string): ScopedClient;
|
||||
headers(h: any): ScopedClient;
|
||||
|
||||
request(method: string, callback?: RequestCallback): ResponseCallback;
|
||||
request(method: string, reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
get(callback?: RequestCallback): ResponseCallback;
|
||||
get(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
post(callback?: RequestCallback): ResponseCallback;
|
||||
post(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
patch(callback?: RequestCallback): ResponseCallback;
|
||||
patch(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
put(callback?: RequestCallback): ResponseCallback;
|
||||
put(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
delete(callback?: RequestCallback): ResponseCallback;
|
||||
delete(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
del(callback?: RequestCallback): ResponseCallback;
|
||||
del(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
|
||||
head(callback?: RequestCallback): ResponseCallback;
|
||||
head(reqBody: string, callback?: RequestCallback): ResponseCallback;
|
||||
}
|
||||
|
||||
export function create(options: Options): ScopedClient;
|
||||
export function create(url?: string, options?: Options): ScopedClient;
|
||||
@@ -0,0 +1,61 @@
|
||||
import * as ScopedClient from "scoped-http-client";
|
||||
import { IncomingMessage } from "http";
|
||||
|
||||
// Basic client
|
||||
let client = ScopedClient.create('https://api.github.com')
|
||||
.header('accept', 'application/json')
|
||||
.path('user/show/technoweenie')
|
||||
.get()((err, resp, body) => {
|
||||
body; // $ExpectType string
|
||||
});
|
||||
|
||||
// Setting the url through multiple steps
|
||||
client = ScopedClient.create()
|
||||
.protocol('https')
|
||||
.host('api.github.com')
|
||||
.port(443)
|
||||
.path('user/show/technoweenie')
|
||||
.query('key', 'value')
|
||||
.encoding('utf-8')
|
||||
.header('X-Test-Header', 'value')
|
||||
.get()(handler);
|
||||
|
||||
// Scoping
|
||||
client.path('https://api.github.com');
|
||||
client.scope('users/technoweenie', (cli) => {
|
||||
cli.get()((err, resp, body) => {
|
||||
body; // $ExpectType string
|
||||
});
|
||||
});
|
||||
|
||||
function handler(err: Error, resp: IncomingMessage, body: string) {}
|
||||
|
||||
// Other HTTP methods
|
||||
client.query({ login: 'technoweenie', token: '...' })
|
||||
.scope('users/technoweenie', (cli) => {
|
||||
cli.post('data')(handler);
|
||||
cli.put('data')(handler);
|
||||
cli.head()(handler);
|
||||
cli.delete()(handler);
|
||||
cli.del()(handler);
|
||||
cli.patch()(handler);
|
||||
});
|
||||
|
||||
// Streaming post body
|
||||
client.post((err, req) => {
|
||||
req.write("...");
|
||||
req.write("...");
|
||||
})(handler);
|
||||
|
||||
// HTTP Basic Authentication
|
||||
client
|
||||
.auth('technoweenie', '...')
|
||||
.get((err, req) => {});
|
||||
|
||||
// Setting a timeout
|
||||
client = ScopedClient.create('http://10.255.255.1:9999');
|
||||
client.timeout(100);
|
||||
|
||||
// Fetching client information
|
||||
client.join('suffix'); // $ExpectType string
|
||||
client.fullPath('path'); // $ExpectType string
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"scoped-http-client-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
// Type definitions for vue-color 2.4
|
||||
// Project: https://github.com/xiaokaike/vue-color#readme
|
||||
// Definitions by: My Self <https://github.com/me>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import Vue from 'vue';
|
||||
|
||||
export const version: string;
|
||||
export class Compact extends Vue {}
|
||||
export class Material extends Vue {}
|
||||
export class Slider extends Vue {}
|
||||
export class Swatches extends Vue {}
|
||||
export class Photoshop extends Vue {}
|
||||
export class Sketch extends Vue {}
|
||||
export class Chrome extends Vue {}
|
||||
|
||||
// those exports aren't specified in the documentation but still exported.
|
||||
// export class Grayscale extends Vue {}
|
||||
// export class Alpha extends Vue {}
|
||||
// export class Checkboard extends Vue {}
|
||||
// export class EditableInput extends Vue {}
|
||||
// export class Hue extends Vue {}
|
||||
// export class Saturation extends Vue {}
|
||||
// export class ColorMixin extends Vue {}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"vue": ">=2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"vue-color-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
@@ -0,0 +1,37 @@
|
||||
import Vue from 'vue';
|
||||
import {
|
||||
Material,
|
||||
Compact,
|
||||
Swatches,
|
||||
Slider,
|
||||
Sketch,
|
||||
Chrome,
|
||||
Photoshop
|
||||
} from 'vue-color';
|
||||
|
||||
const colors = '#194d33';
|
||||
|
||||
new Vue({
|
||||
el: '#app',
|
||||
components: {
|
||||
'material-picker': Material,
|
||||
'compact-picker': Compact,
|
||||
'swatches-picker': Swatches,
|
||||
'slider-picker': Slider,
|
||||
'sketch-picker': Sketch,
|
||||
'chrome-picker': Chrome,
|
||||
'photoshop-picker': Photoshop
|
||||
},
|
||||
template: `
|
||||
<material-picker v-model="colors"></material-picker>
|
||||
<compact-picker v-model="colors"></compact-picker>
|
||||
<swatches-picker v-model="colors"></swatches-picker>
|
||||
<slider-picker v-model="colors"></slider-picker>
|
||||
<sketch-picker v-model="colors"></sketch-picker>
|
||||
<chrome-picker v-model="colors"></chrome-picker>
|
||||
<photoshop-picker v-model="colors"></photoshop-picker>
|
||||
`,
|
||||
data() {
|
||||
return { colors };
|
||||
}
|
||||
});
|
||||
Vendored
+2
-2
@@ -16,12 +16,12 @@ export = WebpackServe;
|
||||
|
||||
declare module 'webpack' {
|
||||
interface Configuration {
|
||||
serve: WebpackServe.Options;
|
||||
serve?: WebpackServe.Options;
|
||||
}
|
||||
}
|
||||
|
||||
declare function WebpackServe(
|
||||
{ config }: { config: WebpackServe.Options }
|
||||
{ config }: { config: webpack.Configuration }
|
||||
): Promise<WebpackServe.Instance>;
|
||||
|
||||
declare namespace WebpackServe {
|
||||
|
||||
@@ -5,13 +5,15 @@ const compiler = webpack();
|
||||
|
||||
const server = serve({
|
||||
config: {
|
||||
http2: true,
|
||||
dev: {
|
||||
publicPath: '/',
|
||||
logLevel: 'info'
|
||||
serve: {
|
||||
http2: true,
|
||||
dev: {
|
||||
publicPath: '/',
|
||||
logLevel: 'info'
|
||||
},
|
||||
host: 'localhost'
|
||||
},
|
||||
host: 'localhost'
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
server
|
||||
|
||||
Reference in New Issue
Block a user