Created
February 29, 2016 11:29
-
-
Save wearethefoos/66fd9045278f61881c07 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Utils { | |
| uuid() { | |
| var i, random; | |
| var uuid = ''; | |
| for (i = 0; i < 32; i++) { | |
| random = Math.random() * 16 | 0; | |
| if (i === 8 || i === 12 || i === 16 || i === 20) { | |
| uuid += '-'; | |
| } | |
| uuid += (i === 12 ? 4 : (i === 16 ? (random & 3 | 8) : random)) | |
| .toString(16); | |
| } | |
| return uuid; | |
| } | |
| pluralize(word, count = 2) { | |
| return count === 1 ? word : word + 's'; | |
| } | |
| store(namespace, data) { | |
| if (data) { | |
| return localStorage.setItem(namespace, JSON.stringify(data)); | |
| } | |
| var store = localStorage.getItem(namespace); | |
| return (store && JSON.parse(store)) || []; | |
| } | |
| extend() { | |
| var newObj = {}; | |
| for (var i = 0; i < arguments.length; i++) { | |
| var obj = arguments[i]; | |
| for (var key in obj) { | |
| if (obj.hasOwnProperty(key)) { | |
| newObj[key] = obj[key]; | |
| } | |
| } | |
| } | |
| return newObj; | |
| } | |
| } | |
| export default Utils; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment