diff --git a/satnav/satnav-tests.ts b/satnav/satnav-tests.ts new file mode 100644 index 000000000..6382c0481 --- /dev/null +++ b/satnav/satnav-tests.ts @@ -0,0 +1,18 @@ +/// +Satnav({}) +.navigate({ + path: 'product/{required}/?{optional}', + directions: (params) => { + // Logic for product route + console.log(params.required); + console.log(params.hasOwnProperty('optional')); + } +}) +.otherwise('/product/1') +.change(function (hash, params, old) { + // Logic for any change + console.log(hash); + console.log(params); + console.log(old); +}) +.go(); //Resolve current route \ No newline at end of file diff --git a/satnav/satnav.d.ts b/satnav/satnav.d.ts new file mode 100644 index 000000000..5b16a3ffb --- /dev/null +++ b/satnav/satnav.d.ts @@ -0,0 +1,28 @@ +// Type definitions for satnav +// Project: https://github.com/f5io/satnav-js +// Definitions by: Christian Holm Diget +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare type Callback = () => void; + +interface ISatnavOptions { + html5?: boolean, + force?: boolean, + poll?: number, + matchAll?: boolean +} + +interface INavigationOptions { + path?: string, + directions?: (params : any) => any, + title?: string | Callback +} + +interface ISatnav { + navigate(navigationOptions: INavigationOptions): ISatnav; + otherwise(route: string): ISatnav; + change(onChange: (hash: string, params: any, old: any) => any): ISatnav; + go(): ISatnav; +} + +declare function Satnav(options?: ISatnavOptions): ISatnav; \ No newline at end of file