Skip to content

Commit 19a63ea

Browse files
committed
added a clearAll function to allow you to nuke localStorage
1 parent 5599530 commit 19a63ea

4 files changed

Lines changed: 26 additions & 1 deletion

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ The simpliest localStorage module you will ever use. Allowing you to set, get, a
3333
$store.set('key','value');
3434
// getting that value
3535
$store.get('key');
36+
37+
// clear all localStorage values
38+
$store.clearAll();
3639
```
3740

3841
## Bower

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-localStorage",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"main": "src/localStorage.js",
55
"ignore": [
66
"**/.*",

src/localStorage.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ angular.module('localStorage', ['ngCookies']).factory('$store', ['$parse', '$coo
121121
$parse(key).assign($scope, null);
122122
$scope.$watch(key, function () { });
123123
publicMethods.remove(key);
124+
},
125+
/**
126+
* Clear All - let's you clear out ALL localStorage variables, use this carefully!
127+
*/
128+
clearAll: function() {
129+
storage.clear();
124130
}
125131
};
126132
return publicMethods;

test/localFactory.spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,20 @@ describe('angular-localStorage module', function () {
9393
expect(testValue).toBeNull();
9494
});
9595
});
96+
97+
describe('when use clearAll() method all should be gone', function () {
98+
99+
beforeEach(function () {
100+
$store.set('spec', 'some test string');
101+
});
102+
103+
beforeEach(function () {
104+
$store.clearAll();
105+
testValue = $store.get('spec');
106+
});
107+
108+
it('should return null for value in localStorage', function () {
109+
expect(testValue).toBeNull();
110+
});
111+
});
96112
});

0 commit comments

Comments
 (0)