Skip to content

Commit

Permalink
[update] client
Browse files Browse the repository at this point in the history
  • Loading branch information
romelperez committed Jul 28, 2017
1 parent 908cdfa commit 38b6bc7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![prhone](https://img.shields.io/badge/prhone-project-1b38a9.svg)](http://romelperez.com)
[![license](https://img.shields.io/github/license/romelperez/web-boilerplate.svg?maxAge=2592000)](./LICENSE)

This is a personal reference based:
This is a personal reference based on:

## Tech

Expand Down
41 changes: 41 additions & 0 deletions client/tools/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function isSupported () {
try {
window.localStorage.setItem('__tk', 'value');
window.localStorage.getItem('__tk');
window.localStorage.removeItem('__tk');
return 'localStorage' in window && window.localStorage !== null;
} catch (e) {
return false;
}
}

const store = {
local: null
};

function resetLocal () {
if (!isSupported()) {
var db = {
setItem: function (id, val) {
return (db[id] = String(val));
},
getItem: function (id) {
return db.hasOwnProperty(id) ? String(db[id]) : void 0;
},
removeItem: function (id) {
return delete db[id];
},
clear: function () {
resetLocal();
}
};

store.local = db;
} else {
store.local = window.localStorage;
}
}

resetLocal();

module.exports = store;
10 changes: 10 additions & 0 deletions client/tools/validators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
window.vulcanval.extendLocale({
id: 'es',
msgs: {
isTime: 'Una hora válida es requerida.',
}
});

window.vulcanval.addValidator('isTime', function (value = '') {
return (/^\d\d\:\d\d$/).test(String(value));
});
9 changes: 9 additions & 0 deletions client/tools/xhr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import axios from 'axios';
import storage from 'client/tools/storage';

axios.interceptors.request.use(function (req) {
if ((/^\/.+/).test(req.url)) {
req.headers['x-token-auth'] = storage.local.getItem('token');
}
return req;
});

0 comments on commit 38b6bc7

Please sign in to comment.