mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-26 11:12:19 +08:00
Merge pull request #5109 from martinmcwhorter/master
definitions for ngKookies
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
/// <reference path="ngkookies.ts" />
|
||||
|
||||
var app: any;
|
||||
|
||||
app.controller('MainCtrl', function ($kookies: angular.kookies.IKookiesService) {
|
||||
// 1. create session cookie
|
||||
$kookies.set('name', 'value');
|
||||
|
||||
// 2. create expiring cookie
|
||||
$kookies.set('name', 'value', {expires: 7});
|
||||
|
||||
// 3. Create expiring cookie, valid across entire site
|
||||
$kookies.set('name', 'value', {expires: 7, path: '/'});
|
||||
|
||||
$kookies.set('name', 'value');
|
||||
|
||||
// read cookie
|
||||
$kookies.get('name'); // "value"
|
||||
$kookies.get('nothing'); // undefined
|
||||
|
||||
// read all available cookies
|
||||
$kookies.get();
|
||||
|
||||
$kookies.set('name', 'value');
|
||||
|
||||
// delete cookie
|
||||
$kookies.remove('name'); // true
|
||||
$kookies.remove('nothing'); // false
|
||||
|
||||
$kookies.set('name', 'value', {path: '/'});
|
||||
|
||||
$kookies.remove('name'); // false
|
||||
// use the same options (path, domain) as what the cookie was written with
|
||||
$kookies.remove('name', {path: '/'}); // true
|
||||
|
||||
var foo: number = $kookies.get('foo', Number);
|
||||
});
|
||||
|
||||
app.config(['$kookiesProvider',
|
||||
function ($kookiesProvider: angular.kookies.IKookiesProvider) {
|
||||
$kookiesProvider.config.raw = true;
|
||||
$kookiesProvider.config.json = true;
|
||||
}
|
||||
]);
|
||||
@@ -0,0 +1,34 @@
|
||||
// Type definitions for ngKookes 0.2.0
|
||||
// Project: https://github.com/voronianski/ngKookies
|
||||
// Definitions by: Martin McWhorter https://github.com/martinmcwhorter
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module angular.kookies {
|
||||
|
||||
type Options = {
|
||||
expires?: number|Date,
|
||||
path?: string,
|
||||
domain?: string,
|
||||
secure?: boolean
|
||||
};
|
||||
|
||||
interface IKookiesService {
|
||||
|
||||
set(name: string, value: string, optopns?: Options): void;
|
||||
get(): any;
|
||||
get(name: string): any;
|
||||
get(name:string, converter: any): any;
|
||||
get<T>(name:string, converter: any): T;
|
||||
remove(name: string, options?: Options): boolean;
|
||||
}
|
||||
|
||||
type Config = { raw?: boolean, json?: boolean }
|
||||
|
||||
interface IKookiesProvider {
|
||||
|
||||
config: Config;
|
||||
setConfig(config: Config): void;
|
||||
defaults: Options;
|
||||
setDefaults(options: Options): void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user