diff options
author | Indrajith K L | 2017-01-17 15:37:25 +0530 |
---|---|---|
committer | Indrajith K L | 2017-01-17 15:37:25 +0530 |
commit | 550e2f03ad0b60b3c9db3d68dbf014dcb740a2ff (patch) | |
tree | faf6bff0bdde8f01514a3f59ecca943569647c40 /src/utils.js | |
download | JSTemplate-550e2f03ad0b60b3c9db3d68dbf014dcb740a2ff.tar.gz JSTemplate-550e2f03ad0b60b3c9db3d68dbf014dcb740a2ff.tar.bz2 JSTemplate-550e2f03ad0b60b3c9db3d68dbf014dcb740a2ff.zip |
Initial Commit
Diffstat (limited to 'src/utils.js')
-rw-r--r-- | src/utils.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/utils.js b/src/utils.js new file mode 100644 index 0000000..e0a4c76 --- /dev/null +++ b/src/utils.js @@ -0,0 +1,38 @@ +var UTILS = { + getLocalStorage: function(key) { + var localData = localStorage.getItem(key); + var parsedData = JSON.parse(localData); + + return parsedData; + }, + + setLocalStorage: function(storageKey, data) { + var stringifiedData = JSON.stringify(data); + localStorage.setItem(storageKey, stringifiedData); + }, + + toJSON: function(data) { + if (_.isObject(data)) { + return data; + } + try { + var o = JSON.parse(data); + if (o && typeof o === "object") { + return o; + } + } catch (e) { + console.log(e); + } + + return false; + }, + isEmail: function(email) { + var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/; + return regex.test(email); + }, + isTag: function(content) { + if (content.match(/<(\w+)((?:\s+\w+(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/)) { + return true; + } + } +} |