Blame view
src/util/index.js
2 KB
93a68cfa1
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
// export function camel (str) { // const camel = (str || '').replace(/-([^-])/g, g => g[1].toUpperCase()); // return capitalize(camel); // } // export function camelActual (str) { // return (str || '').replace(/-(\w)/g, (_, c) => (c ? c.toUpperCase() : '')); // } // export function kebab (str) { // return (str || '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); // } // export function capitalize (str) { // str = str || ''; // return `${str.substr(0, 1).toUpperCase()}${str.slice(1)}`; // } // export function findProduct (store, id) { // return store.state.store.products.find(p => p.id === id); // } // export function isOnSale (variants) { // return variants.some(variant => { // return parseFloat(variant.price) < parseFloat(variant.compareAtPrice); // }); // } // export function randomNumber (min, max) { // return Math.floor(Math.random() * max) + min; // } // export function randomString (length = 5) { // let text = ''; // const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; // for (let i = 0; i < length; i++) { // text += possible.charAt(Math.floor(Math.random() * possible.length)); // } // return text; // } const randomElement = (arr = []) => { return arr[Math.floor(Math.random() * arr.length)]; }; const kebab = (str) => { return (str || '').replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); }; const toggleFullScreen = () => { let doc = window.document; let docEl = doc.documentElement; let requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen; let cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen; if (!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) { requestFullScreen.call(docEl); } else { cancelFullScreen.call(doc); } }; export default { randomElement, toggleFullScreen, kebab }; |