mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-13 08:57:26 +08:00
Merge pull request #4694 from mdekrey/angular-storage
Add angular-storage definition file
This commit is contained in:
43
angular-storage/angular-storage-tests.ts
Normal file
43
angular-storage/angular-storage-tests.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/// <reference path='../angularjs/angular.d.ts' />
|
||||
/// <reference path='angular-storage.d.ts' />
|
||||
|
||||
// Samples taken from the a0-angular-storage Readme.md
|
||||
|
||||
var app = angular.module('angular-storage-tests', ['angular-storage']);
|
||||
|
||||
angular.module('angular-storage-tests')
|
||||
.controller('StoreController', function(store: angular.a0.storage.IStoreService) {
|
||||
var myObj = {
|
||||
name: 'mgonto'
|
||||
};
|
||||
|
||||
store.set('obj', myObj);
|
||||
|
||||
var myNewObject = store.get('obj');
|
||||
|
||||
console.log('Should be true: ', angular.equals(myNewObject, myObj));
|
||||
|
||||
store.remove('obj');
|
||||
|
||||
store.set('number', 2);
|
||||
|
||||
console.log('Should be true: ', typeof(store.get('number')) === 'number');
|
||||
})
|
||||
.factory('Auth0Store', function(store: angular.a0.storage.IStoreService) {
|
||||
return store.getNamespacedStore('auth0');
|
||||
})
|
||||
.controller('NamespacedStoreController', function(Auth0Store: angular.a0.storage.INamespacedStoreService) {
|
||||
|
||||
var myObj = {
|
||||
name: 'mgonto'
|
||||
};
|
||||
|
||||
// This will be saved in localStorage as auth0.obj
|
||||
Auth0Store.set('obj', myObj);
|
||||
|
||||
// This will look for auth0.obj
|
||||
var myNewObject = Auth0Store.get('obj');
|
||||
|
||||
console.log('Should be true: ', angular.equals(myNewObject, myObj));
|
||||
});;
|
||||
|
||||
53
angular-storage/angular-storage.d.ts
vendored
Normal file
53
angular-storage/angular-storage.d.ts
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// Type definitions for angular-storage v0.0.11
|
||||
// Project: https://github.com/auth0/angular-storage
|
||||
// Definitions by: Matthew DeKrey <https://github.com/mdekrey>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module angular.a0.storage {
|
||||
interface IStoreService extends INamespacedStoreService {
|
||||
/**
|
||||
* Returns a namespaced store
|
||||
*
|
||||
* @param {String} namespace - The namespace
|
||||
* @param {String} storage - The name of the storage service. Defaults to local storage.
|
||||
* @param {String} delimiter - The delimiter to use to separate the namespace and the keys.
|
||||
* @returns {INamespacedStoreService}
|
||||
*/
|
||||
getNamespacedStore(namespace: string, storage?: string, delimiter?: string): INamespacedStoreService;
|
||||
}
|
||||
|
||||
interface INamespacedStoreService {
|
||||
/**
|
||||
* Sets a new value to the storage with the key name. It can be any object.
|
||||
*
|
||||
* @param {String} name - The key name for the location of the value
|
||||
* @param value - The value to store
|
||||
*/
|
||||
set(name: string, value: any): void;
|
||||
|
||||
/**
|
||||
* Returns the saved value with they key name.
|
||||
*
|
||||
* @param {String} name - The key name for the location of the value
|
||||
* @returns The saved value; if you saved an object, you get an object
|
||||
*/
|
||||
get(name: string): any;
|
||||
|
||||
/**
|
||||
* Deletes the saved value with the key name
|
||||
*
|
||||
* @param {String} name - The key name for the location of the value to remove
|
||||
*/
|
||||
remove(name: string): void;
|
||||
}
|
||||
|
||||
interface IStoreProvider {
|
||||
|
||||
/**
|
||||
* Sets the storage.
|
||||
*
|
||||
* @param {String} storage - The storage name
|
||||
*/
|
||||
setStore(storage: string): void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user