miusuncle.github.io's People
miusuncle.github.io's Issues
JSTORE.js
function query(param) {
var match = RegExp('[?&]' + param + '=([^&]*)').exec(location.href.split('#')[0]);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
var storage = global.localStorage;
var storagePrefix = 'qcact/js/';
var rkey = /^(.+)\.(\w{12,})\.js$/;
var defaultExpiration = 30 * 24; // 30 days(unit: h)
var JSTORE = {
get: function (key) {
var item = storage.getItem(storagePrefix + key);
try {
return JSON.parse(item || 'false');
} catch (e) {
return false;
}
},
has: function (rawKey) {
var matches = String(rawKey).match(rkey);
return matches && (this.get(matches[1]).hash === matches[2]);
},
set: function (rawKey, data, opts) {
var matches = String(rawKey).match(rkey);
if (matches) {
var now = +new Date;
var storeKey = storagePrefix + matches[1];
opts || (opts = {});
var storeVal = {
'hash': matches[2],
'stamp': now,
'expire': (now + (opts.expire || defaultExpiration) * 60 * 60 * 1000),
'data': data,
};
storage.setItem(storeKey, JSON.stringify(storeVal));
}
return this;
},
remove: function (key) {
storage.removeItem(storagePrefix + key);
return this;
},
clear: function (expired) {
var now = +new Date;
for (var item in storage) {
var key = item.split(storagePrefix)[1];
if (key && (!expired || this.get(key).expire <= now)) {
this.remove(key);
}
}
return this;
},
};
if (('localStorage' in global) && ('JSON' in global) && +query('debug') !== 1) {
global.JSTORE = JSTORE.clear(true);
}
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.