localstorage: Allow regex based delete.

This commit is contained in:
Umair Khan 2017-04-26 15:35:56 +05:00 committed by Tim Abbott
parent ce5980aa45
commit 58a82e7c55
1 changed files with 17 additions and 0 deletions

View File

@ -61,6 +61,18 @@ var ls = {
localStorage.removeItem(key);
},
// Remove keys which match a regex.
removeDataRegex: function (version, regex) {
var key_regex = new RegExp(this.formGetter(version, regex));
var keys = Object.keys(localStorage).filter(function (key) {
return key_regex.test(key);
});
keys.forEach(function (key) {
localStorage.removeItem(key);
});
},
// migrate from an older version of a data src to a newer one with a
// specified callback function.
migrate: function (name, v1, v2, callback) {
@ -125,6 +137,11 @@ var exports = function () {
ls.removeData(_data.VERSION, name);
},
// Remove keys which match the pattern given by name.
removeRegex: function (name) {
ls.removeDataRegex(_data.VERSION, name);
},
migrate: function (name, v1, v2, callback) {
return ls.migrate(name, v1, v2, callback);
},